Skip to content

Commit c7c0ba7

Browse files
committed
Add macOS build configuration (#5)
* Stabilize for macOS build * Extend some bazel configs to macOS from linux-only * Added CI/CD support for macOS --------- Co-authored-by: evgeny.grigorenko@jetbrains.com <egrig@evgenys-virtual-machine.local> Co-authored-by: Mihajlo Linić <linicmihajlo@gmail.com>
1 parent 7c575c1 commit c7c0ba7

File tree

4 files changed

+56
-13
lines changed

4 files changed

+56
-13
lines changed

.bazelrc

+12-5
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,20 @@ build:linux_x86_64 --host_copt=-march=haswell
4444
build:linux_aarch64 --copt=-march=armv8-a
4545
build:linux_aarch64 --host_copt=-march=armv8-a
4646

47+
# Configure for Linux on ARM64 (Apple Silicon)
48+
# Macosx version in plat name should be aligned with --macos_minimum_os
49+
# flag in .bazelrc. And requires a change in both places to be made.
50+
build:macos --macos_minimum_os=12.0
51+
build:macos_arm64 --copt=-mcpu=apple-m1
52+
build:macos_arm64 --host_copt=-mcpu=apple-m1
53+
4754
# Only use level three optimizations for target, not necessarily for host
4855
# since host artifacts don't need to be fast.
4956
build --copt=-O3
5057

5158
# Suppress C++ compiler warnings.
52-
build:linux --copt=-w
53-
build:linux --host_copt=-w
59+
build --copt=-w
60+
build --host_copt=-w
5461

5562
#
5663
# Remote execution capabilities
@@ -118,12 +125,12 @@ build:linux --define=INCLUDEDIR=$(PREFIX)/include
118125
build:linux --define=PROTOBUF_INCLUDE_PATH=$(PREFIX)/include
119126

120127
# By default, build TF in C++ 17 mode.
121-
build:linux --cxxopt=-std=c++17
122-
build:linux --host_cxxopt=-std=c++17
128+
build --cxxopt=-std=c++17
129+
build --host_cxxopt=-std=c++17
123130

124131
# Do not risk cache corruption. See:
125132
# https://github.com/bazelbuild/bazel/issues/3360
126-
build:linux --experimental_guard_against_concurrent_changes
133+
build --experimental_guard_against_concurrent_changes
127134

128135
# Configure short or long logs
129136
build:short_logs --output_filter=DONT_MATCH_ANYTHING

.github/workflows/publish.yaml

+15-5
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,13 @@ jobs:
102102
include:
103103
- os: ubuntu-22.04
104104
arch: x86_64
105+
sys: linux
105106
- os: ubuntu-22.04-arm
106107
arch: aarch64
108+
sys: linux
109+
- os: macos-14
110+
arch: arm64
111+
sys: macos
107112
runs-on: ${{ matrix.os }}
108113
timeout-minutes: 360
109114
environment: release
@@ -150,14 +155,14 @@ jobs:
150155
--build_tag_filters="-nokokoro,-nopresubmit,-requires-gpu-nvidia" \
151156
--google_credentials="${{ steps.auth.outputs.credentials_file_path }}" \
152157
--remote_cache="https://storage.googleapis.com/${{ vars.BAZEL_CACHE_BUCKET }}/${{ github.job }}" \
153-
--config="linux_${{ matrix.arch }}" \
158+
--config="${{ matrix.sys }}_${{ matrix.arch }}" \
154159
-- \
155160
--output_dir="${{ github.workspace }}/dist/"
156161
157162
- name: Upload Python package
158163
uses: actions/upload-artifact@v4.3.3
159164
with:
160-
name: python-package-distributions-${{ matrix.arch }}
165+
name: python-package-distributions-${{ matrix.sys }}-${{ matrix.arch }}
161166
path: dist/*.whl
162167

163168
test-package:
@@ -168,8 +173,13 @@ jobs:
168173
include:
169174
- os: ubuntu-22.04
170175
arch: x86_64
176+
sys: linux
171177
- os: ubuntu-22.04-arm
172178
arch: aarch64
179+
sys: linux
180+
- os: macos-14
181+
arch: arm64
182+
sys: macos
173183
runs-on: ${{ matrix.os }}
174184
timeout-minutes: 5
175185
steps:
@@ -182,7 +192,7 @@ jobs:
182192
- name: Download Python package
183193
uses: actions/download-artifact@v4.1.7
184194
with:
185-
name: python-package-distributions-${{ matrix.arch }}
195+
name: python-package-distributions-${{ matrix.sys }}-${{ matrix.arch }}
186196
path: dist/
187197

188198
- name: Set up Python
@@ -210,7 +220,7 @@ jobs:
210220
211221
publish-package:
212222
name: Publish Package
213-
needs: [build-package, test-package]
223+
needs: [build-package,test-package]
214224
runs-on: ubuntu-22.04
215225
timeout-minutes: 5
216226
permissions:
@@ -231,4 +241,4 @@ jobs:
231241
password: ${{ secrets.PYTHON_REPOSITORY_TOKEN }}
232242
repository-url: ${{ vars.PYTHON_REPOSITORY_URL }}
233243
verbose: 'true'
234-
user: ${{ secrets.PYTHON_REPOSITORY_USER }}
244+
user: ${{ secrets.PYTHON_REPOSITORY_USER }}

tensorflow_federated/cc/simulation/BUILD

+5-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ cc_library(
5353

5454
cc_binary(
5555
name = "worker_binary",
56-
linkopts = ["-lrt"],
56+
linkopts = select({
57+
"@platforms//os:osx": [],
58+
"@platforms//os:linux": ["-lrt"],
59+
"//conditions:default": [],
60+
}),
5761
deps = [":worker_main"],
5862
)

tools/python_package/build_python_package.sh

+24-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# limitations under the License.
1515
#
1616
# Tool to build the TensorFlow Federated Python package.
17+
18+
1719
set -e
1820

1921
usage() {
@@ -24,8 +26,10 @@ usage() {
2426
}
2527

2628
main() {
29+
2730
# Parse the arguments.
2831
local output_dir="${BUILD_WORKING_DIRECTORY}/dist"
32+
2933

3034
while [[ "$#" -gt 0 ]]; do
3135
option="$1"
@@ -48,7 +52,8 @@ main() {
4852
exit 1
4953
fi
5054

51-
# Check the GLIBC version.
55+
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
56+
# Check the GLIBC version.
5257
glibc_version=$(ldd --version 2>&1 | grep "GLIBC" | awk '{print $NF}')
5358

5459
# Error handling if GLIBC version couldn't be determined.
@@ -67,12 +72,25 @@ main() {
6772
arch=$(uname -m)
6873
case "$arch" in
6974
aarch64|x86_64) ;; # Supported architectures
70-
*) echo "error: Unsupported architecture: $arch" >&2; exit 1 ;;
75+
*) echo "error: Unsupported architecture: linux/$arch" >&2; exit 1 ;;
7176
esac
7277

7378
plat_name="manylinux_${manylinux_version}_${arch}"
79+
elif [[ "$OSTYPE" == "darwin"* ]]; then
7480

81+
arch=$(uname -m)
82+
case "$arch" in
83+
arm64) ;; # Supported architectures
84+
*) echo "error: Unsupported architecture: darwin/$arch" >&2; exit 1 ;;
85+
esac
7586

87+
# TODO: update code above to process macos plat_name as well
88+
# In .bazelrc it is build with --macos_minimum_os=12.0
89+
# Macosx version in plat name should be aligned with --macos_minimum_os
90+
# flag in .bazelrc. And requires a change in both places to be made.
91+
# wonder if there is a better way
92+
plat_name="macosx_12_0_arm64"
93+
fi
7694
# Create a temp directory.
7795
local temp_dir="$(mktemp --directory)"
7896
trap "rm -rf ${temp_dir}" EXIT
@@ -87,6 +105,10 @@ main() {
87105
# Build the Python package.
88106
pip install --upgrade "build" "toml-cli"
89107

108+
# Trap to avoid editing a linked file
109+
previous_plat_name=$(toml get --toml-path "pyproject.toml" "tool.distutils.bdist_wheel.plat-name")
110+
trap "toml set --toml-path "pyproject.toml" "tool.distutils.bdist_wheel.plat-name" "$previous_plat_name"" EXIT
111+
90112
# Update wheel platform
91113
toml set --toml-path "pyproject.toml" "tool.distutils.bdist_wheel.plat-name" "$plat_name"
92114
pip freeze

0 commit comments

Comments
 (0)