Skip to content

Commit 725a0db

Browse files
committed
Enable macOS M1 wheel builds
This commit contains fixes for `ml-metadata`'s build setup to enable wheel builds on macOS M1. The core build files have not been touched except for version increments of Bazel dependencies, and for `mariadbconnector-c`, whose build file needed to be updated to support the latest version. Several dependencies were upgraded to newer versions, with the update policy being "as recent as possible without breaking changes". A few gRPC dependencies were eliminated from `ml-metadata`'s workspace to avoid friction on subsequent gRPC updates (this includes e.g. `protobuf`, `zlib`). This change allows for M1 wheel builds without more external system dependencies outside of Bazel - the used build definitions contain M1 capabilities for sufficiently new versions of Bazel.
1 parent 2a3f948 commit 725a0db

12 files changed

+104
-116
lines changed

.bazelrc

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@
1616
# be compiled upon c++17 or higher.
1717
build --cxxopt="-std=c++17"
1818

19-
# Due to the invalid escape sequence in rules_foreign_cc and the bazel 4.0.0 updates
20-
# (https://github.com/bazelbuild/bazel/commit/73402fa4aa5b9de46c9a4042b75e6fb332ad4a7f).
21-
build --incompatible_restrict_string_escapes=false
22-
23-
# icu@: In create_linking_context: in call to create_linking_context(),
24-
# parameter 'user_link_flags' is deprecated and will be removed soon.
25-
# It may be temporarily re-enabled by setting --incompatible_require_linker_input_cc_api=false
26-
build --incompatible_require_linker_input_cc_api=false
19+
# Support for Apple M1.
2720
build:macos --apple_platform_type=macos
2821
build:macos_arm64 --cpu=darwin_arm64

WORKSPACE

Lines changed: 64 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,61 @@ load("//ml_metadata:repo.bzl", "mlmd_http_archive", "clean_dep")
44
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
55
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
66

7-
# lts_20210324.2
7+
# lts_20220623.1
8+
ABSL_COMMIT = "8c0b94e793a66495e0b1f34a5eb26bd7dc672db0"
89
http_archive(
910
name = "com_google_absl",
10-
sha256 = "1764491a199eb9325b177126547f03d244f86b4ff28f16f206c7b3e7e4f777ec",
11-
strip_prefix = "abseil-cpp-278e0a071885a22dcd2fd1b5576cc44757299343",
11+
sha256 = "a6be76f59c474a215f2df5116b312257462e97f2e38b2bfa6df8b6a55710b058",
12+
strip_prefix = "abseil-cpp-%s" % ABSL_COMMIT,
1213
urls = [
13-
"https://mirror.bazel.build/github.com/abseil/abseil-cpp/archive/278e0a071885a22dcd2fd1b5576cc44757299343.tar.gz",
14-
"https://github.com/abseil/abseil-cpp/archive/278e0a071885a22dcd2fd1b5576cc44757299343.tar.gz"
14+
"https://mirror.bazel.build/github.com/abseil/abseil-cpp/archive/%s.tar.gz" % ABSL_COMMIT,
15+
"https://github.com/abseil/abseil-cpp/archive/%s.tar.gz" % ABSL_COMMIT,
1516
],
1617
)
1718

1819
# rules_cc defines rules for generating C++ code from Protocol Buffers.
20+
RULES_CC_COMMIT = "dc039dc2d82696ab3f0087b6dfe79776d1ab2326" # 19/10/2022
1921
http_archive(
2022
name = "rules_cc",
21-
sha256 = "35f2fb4ea0b3e61ad64a369de284e4fbbdcdba71836a5555abb5e194cf119509",
22-
strip_prefix = "rules_cc-624b5d59dfb45672d4239422fa1e3de1822ee110",
23+
sha256 = "391811a18486dbc745627fdaeea9a6d96b683ab88bbecb9fe880a29d4da8cb36",
24+
strip_prefix = "rules_cc-%s" % RULES_CC_COMMIT,
2325
urls = [
24-
"https://mirror.bazel.build/github.com/bazelbuild/rules_cc/archive/624b5d59dfb45672d4239422fa1e3de1822ee110.tar.gz",
25-
"https://github.com/bazelbuild/rules_cc/archive/624b5d59dfb45672d4239422fa1e3de1822ee110.tar.gz",
26+
"https://mirror.bazel.build/github.com/bazelbuild/rules_cc/archive/%s.tar.gz" % RULES_CC_COMMIT,
27+
"https://github.com/bazelbuild/rules_cc/archive/%s.tar.gz" % RULES_CC_COMMIT,
2628
],
2729
)
2830

31+
RULES_FOREIGN_CC_COMMIT = "a7f9e8b38cc2c8a7c66862dd6a4c8848e9829a02" # 23/09/2022
32+
http_archive(
33+
name="rules_foreign_cc",
34+
sha256 = "ce3121834693d76308f50fa62c548c2710f900d807beb11d97c25739b6995f58",
35+
strip_prefix = "rules_foreign_cc-%s" % RULES_FOREIGN_CC_COMMIT,
36+
urls = [
37+
"https://mirror.bazel.build/github.com/bazelbuild/rules_foreign_cc/archive/%s.tar.gz" % RULES_FOREIGN_CC_COMMIT,
38+
"https://github.com/bazelbuild/rules_foreign_cc/archive/%s.tar.gz" % RULES_FOREIGN_CC_COMMIT,
39+
],
40+
)
41+
42+
PLATFORMS_COMMIT = "d9296d956de6e7b3ae83ecc37a5970e5eebeee32"
43+
http_archive(
44+
name="platforms",
45+
sha256 = "01db13196adfb8468db77d7e42b1828dd7242112cca55b4df65df7cf7c91ec39",
46+
strip_prefix = "platforms-%s" % PLATFORMS_COMMIT,
47+
urls = [
48+
"https://mirror.bazel.build/github.com/bazelbuild/platforms/archive/%s.tar.gz" % PLATFORMS_COMMIT,
49+
"https://github.com/bazelbuild/PLATFORMS/archive/%s.tar.gz" % PLATFORMS_COMMIT,
50+
],
51+
)
52+
53+
BORINGSSL_COMMIT = "adde128bd706c6caf26dd595e631871b09f40bf6"
2954
mlmd_http_archive(
3055
name = "boringssl",
31-
sha256 = "1188e29000013ed6517168600fc35a010d58c5d321846d6a6dfee74e4c788b45",
32-
strip_prefix = "boringssl-7f634429a04abc48e2eb041c81c5235816c96514",
56+
sha256 = "7fc7632ce455575025be2cac610a23377753b01a4932d94a452cf831a5b32e9e",
57+
strip_prefix = "boringssl-%s" % BORINGSSL_COMMIT,
3358
system_build_file = clean_dep("//ml_metadata/third_party/systemlibs:boringssl.BUILD"),
3459
urls = [
35-
"https://storage.googleapis.com/mirror.tensorflow.org/github.com/google/boringssl/archive/7f634429a04abc48e2eb041c81c5235816c96514.tar.gz",
36-
"https://github.com/google/boringssl/archive/7f634429a04abc48e2eb041c81c5235816c96514.tar.gz",
60+
"https://storage.googleapis.com/mirror.tensorflow.org/github.com/google/boringssl/archive/%s.tar.gz" % BORINGSSL_COMMIT,
61+
"https://github.com/google/boringssl/archive/%s.tar.gz" % BORINGSSL_COMMIT,
3762
],
3863
)
3964

@@ -71,63 +96,41 @@ http_archive(
7196

7297
http_archive(
7398
name = "bazel_skylib",
74-
sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44",
99+
sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506",
75100
urls = [
76-
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz",
77-
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz",
101+
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
102+
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
78103
],
79104
)
80105

81106
# Needed by abseil-py by zetasql.
82107
http_archive(
83108
name = "six_archive",
84109
urls = [
85-
"http://mirror.bazel.build/pypi.python.org/packages/source/s/six/six-1.10.0.tar.gz",
86-
"https://pypi.python.org/packages/source/s/six/six-1.10.0.tar.gz",
110+
"http://mirror.bazel.build/pypi.python.org/packages/source/s/six/six-1.16.0.tar.gz",
111+
"https://pypi.python.org/packages/source/s/six/six-1.16.0.tar.gz",
87112
],
88-
sha256 = "105f8d68616f8248e24bf0e9372ef04d3cc10104f1980f54d57b2ce73a5ad56a",
89-
strip_prefix = "six-1.10.0",
113+
sha256 = "1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926",
114+
strip_prefix = "six-1.16.0",
90115
build_file = "//ml_metadata/third_party:six.BUILD"
91116
)
92117

93-
PROTOBUF_COMMIT = "fde7cf7358ec7cd69e8db9be4f1fa6a5c431386a" # 3.13.0
94-
http_archive(
95-
name = "com_google_protobuf",
96-
sha256 = "e589e39ef46fb2b3b476b3ca355bd324e5984cbdfac19f0e1625f0042e99c276",
97-
strip_prefix = "protobuf-%s" % PROTOBUF_COMMIT,
98-
urls = [
99-
"https://storage.googleapis.com/grpc-bazel-mirror/github.com/google/protobuf/archive/%s.tar.gz" % PROTOBUF_COMMIT,
100-
"https://github.com/google/protobuf/archive/%s.tar.gz" % PROTOBUF_COMMIT,
101-
],
102-
)
103-
104-
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
105-
106-
protobuf_deps()
107-
108-
# Needed by Protobuf.
109-
http_archive(
110-
name = "zlib",
111-
build_file = "@com_google_protobuf//:third_party/zlib.BUILD",
112-
sha256 = "d8688496ea40fb61787500e863cc63c9afcbc524468cedeb478068924eb54932",
113-
strip_prefix = "zlib-1.2.12",
114-
urls = ["https://github.com/madler/zlib/archive/v1.2.12.tar.gz"],
115-
)
116-
117118
# pybind11
118119
http_archive(
119120
name = "pybind11",
121+
sha256 = "eacf582fa8f696227988d08cfc46121770823839fe9e301a20fbce67e7cd70ec",
120122
build_file = "@pybind11_bazel//:pybind11.BUILD",
121-
strip_prefix = "pybind11-2.4.3",
122-
urls = ["https://github.com/pybind/pybind11/archive/v2.4.3.tar.gz"],
123+
strip_prefix = "pybind11-2.10.0",
124+
urls = ["https://github.com/pybind/pybind11/archive/v2.10.0.tar.gz"],
123125
)
124126

125127
# Bazel rules for pybind11
128+
PYBIND11_BAZEL_COMMIT = "9a24c33cbdc510fa60ab7f5ffb7d80ab89272799" # up to date for pybind11 2.10.0
126129
http_archive(
127130
name = "pybind11_bazel",
128-
strip_prefix = "pybind11_bazel-d5587e65fb8cbfc0015391a7616dc9c66f64a494",
129-
url = "https://github.com/pybind/pybind11_bazel/archive/d5587e65fb8cbfc0015391a7616dc9c66f64a494.zip",
130-
sha256 = "bf8e1f3ebde5ee37ad30c451377b03fbbe42b9d8f24c244aa8af2ccbaeca7e6c",
131+
sha256 = "e1fe52ad3468629772c50c67a93449f235aed650a0fe8e89a22fbff285f677a1",
132+
strip_prefix = "pybind11_bazel-%s" % PYBIND11_BAZEL_COMMIT,
133+
url = "https://github.com/pybind/pybind11_bazel/archive/%s.zip" % PYBIND11_BAZEL_COMMIT,
131134
)
132135
load("@pybind11_bazel//:python_configure.bzl", "python_configure")
133136
python_configure(name = "local_config_python")
@@ -141,13 +144,12 @@ http_archive(
141144
strip_prefix = "re2-d1394506654e0a19a92f3d8921e26f7c3f4de969",
142145
)
143146

144-
# gRPC. Official release 1.33.2. Name is required by Google APIs.
147+
# gRPC. Official release 1.50.0. Name is required by Google APIs.
145148
http_archive(
146149
name = "com_github_grpc_grpc",
147-
sha256 = "2060769f2d4b0d3535ba594b2ab614d7f68a492f786ab94b4318788d45e3278a",
148-
strip_prefix = "grpc-1.33.2",
149-
patches = ["//ml_metadata/third_party:grpc.patch"],
150-
urls = ["https://github.com/grpc/grpc/archive/v1.33.2.tar.gz"],
150+
sha256 = "76900ab068da86378395a8e125b5cc43dfae671e09ff6462ddfef18676e2165a",
151+
strip_prefix = "grpc-1.50.0",
152+
urls = ["https://github.com/grpc/grpc/archive/v1.50.0.tar.gz"],
151153
)
152154
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
153155
grpc_deps()
@@ -164,34 +166,8 @@ bind(
164166
actual = "@com_github_grpc_grpc//:grpc++",
165167
)
166168

167-
# Needed by gRPC.
168-
http_archive(
169-
name = "build_bazel_rules_swift",
170-
sha256 = "d0833bc6dad817a367936a5f902a0c11318160b5e80a20ece35fb85a5675c886",
171-
strip_prefix = "rules_swift-3eeeb53cebda55b349d64c9fc144e18c5f7c0eb8",
172-
urls = ["https://github.com/bazelbuild/rules_swift/archive/3eeeb53cebda55b349d64c9fc144e18c5f7c0eb8.tar.gz"],
173-
)
174-
175-
http_archive(
176-
name = "io_bazel_rules_go",
177-
urls = [
178-
"https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/rules_go/releases/download/v0.20.3/rules_go-v0.20.3.tar.gz",
179-
"https://github.com/bazelbuild/rules_go/releases/download/v0.20.3/rules_go-v0.20.3.tar.gz",
180-
],
181-
sha256 = "e88471aea3a3a4f19ec1310a55ba94772d087e9ce46e41ae38ecebe17935de7b",
182-
)
183-
169+
# pulled in transitively by gRPC.
184170
load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies", "go_register_toolchains")
185-
186-
http_archive(
187-
name = "bazel_gazelle",
188-
urls = [
189-
"https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/bazel-gazelle/releases/download/v0.19.1/bazel-gazelle-v0.19.1.tar.gz",
190-
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.19.1/bazel-gazelle-v0.19.1.tar.gz",
191-
],
192-
sha256 = "86c6d481b3f7aedc1d60c1c211c6f76da282ae197c3b3160f54bd3a8f847896f",
193-
)
194-
195171
load("@bazel_gazelle//:deps.bzl", "go_repository", "gazelle_dependencies")
196172

197173
go_repository(
@@ -208,7 +184,7 @@ go_repository(
208184

209185
go_rules_dependencies()
210186

211-
go_register_toolchains()
187+
go_register_toolchains("host")
212188

213189
gazelle_dependencies()
214190

@@ -221,13 +197,12 @@ git_repository(
221197
)
222198

223199
# BEGIN IFNDEF_WIN
224-
ZETASQL_COMMIT = "5ccb05880e72ab9ff75dd6b05d7b0acce53f1ea2" # 04/22/2021 # windows
200+
ZETASQL_COMMIT = "ac37cf5c0d80b5605176fc0f29e87b12f00be693" # 08/11/2022 # windows
225201
http_archive( # windows
226202
name = "com_google_zetasql", # windows
227203
urls = ["https://github.com/google/zetasql/archive/%s.zip" % ZETASQL_COMMIT], # windows
228204
strip_prefix = "zetasql-%s" % ZETASQL_COMMIT, # windows
229-
# patches = ["//ml_metadata/third_party:zetasql.patch"], # windows
230-
sha256 = '4ca4e45f457926484822701ec15ca4d0172b01d7ce43c0b34c6f3ab98c95b241' # windows
205+
sha256 = "651a768cd51627f58aa6de7039aba9ddab22f4b0450521169800555269447840",
231206
) # windows
232207

233208
load("@com_google_zetasql//bazel:zetasql_deps_step_1.bzl", "zetasql_deps_step_1") # windows
@@ -239,6 +214,10 @@ zetasql_deps_step_2( # windows
239214
tools_deps = False, # windows
240215
java_deps = False, # windows
241216
testing_deps = False) # windows
217+
load("@com_google_zetasql//bazel:zetasql_deps_step_3.bzl", "zetasql_deps_step_3")
218+
zetasql_deps_step_3()
219+
load("@com_google_zetasql//bazel:zetasql_deps_step_4.bzl", "zetasql_deps_step_4")
220+
zetasql_deps_step_4()
242221
# END IFNDEF_WIN
243222

244223

ml_metadata/.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
3.7.2
14+
5.3.2

ml_metadata/libmysqlclient.BUILD

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ genrule(
3434
)
3535

3636
config_setting(
37-
name = "darwin",
38-
values = {"cpu": "darwin"},
37+
name = "macos",
38+
constraint_values = [
39+
"@bazel_tools//platforms:osx",
40+
],
3941
visibility = ["//visibility:public"],
4042
)
4143

@@ -45,13 +47,14 @@ cc_library(
4547
# plugins.
4648
"plugins/auth/my_auth.c",
4749
"plugins/auth/old_password.c",
50+
"plugins/compress/c_zlib.c",
4851
"plugins/pvio/pvio_socket.c",
4952
# ssl.
5053
"libmariadb/secure/openssl.c",
5154
# core libmariadb
5255
"libmariadb/ma_array.c",
5356
"libmariadb/ma_charset.c",
54-
"libmariadb/ma_hash.c",
57+
"libmariadb/ma_hashtbl.c",
5558
"libmariadb/ma_net.c",
5659
"libmariadb/mariadb_charset.c",
5760
"libmariadb/ma_time.c",
@@ -91,7 +94,10 @@ cc_library(
9194
"-DLIBICONV_PLUG",
9295
"-DHAVE_OPENSSL",
9396
"-DHAVE_TLS",
94-
],
97+
] + select({
98+
":macos": ["-D_XOPEN_SOURCE"],
99+
"//conditions:default": [],
100+
}),
95101
includes = [
96102
"build/include/",
97103
"include/",
@@ -102,7 +108,7 @@ cc_library(
102108
"-ldl",
103109
"-lm",
104110
] + select({
105-
":darwin": ["-liconv"],
111+
":macos": ["-liconv"],
106112
"//conditions:default": [],
107113
}),
108114
visibility = ["//visibility:public"],

ml_metadata/metadata_store/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ cc_library(
7171
":metadata_source",
7272
":query_executor",
7373
"@com_google_protobuf//:protobuf",
74-
7574
"@com_google_absl//absl/container:flat_hash_map",
7675
"@com_google_absl//absl/container:flat_hash_set",
7776
"@com_google_absl//absl/status",

ml_metadata/metadata_store/pywrap/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ ml_metadata_pybind_extension(
3636
"//ml_metadata/simple_types/proto:simple_types_proto",
3737
"//ml_metadata/metadata_store:simple_types_util",
3838
"@pybind11",
39+
"@local_config_python//:python_headers",
3940
],
4041
)
4142

ml_metadata/ml_metadata.bzl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def ml_metadata_proto_library_py(
9191
name = name,
9292
srcs = srcs,
9393
srcs_version = "PY2AND3",
94-
deps = ["@com_google_protobuf//:protobuf_python"] + deps + oss_deps,
94+
deps = ["@com_google_protobuf//:well_known_types_py_pb2"] + deps + oss_deps,
9595
default_runtime = "@com_google_protobuf//:protobuf_python",
9696
protoc = "@com_google_protobuf//:protoc",
9797
visibility = visibility,
@@ -262,6 +262,7 @@ def ml_metadata_pybind_extension(
262262
],
263263
"//ml_metadata:windows": [],
264264
"//conditions:default": [
265+
"-Wl,-Bsymbolic",
265266
"-Wl,--version-script",
266267
"$(location %s)" % version_script_file,
267268
],
@@ -270,7 +271,7 @@ def ml_metadata_pybind_extension(
270271
exported_symbols_file,
271272
version_script_file,
272273
],
273-
features = ["-use_header_modules"],
274+
features = ["-use_header_modules", "-parse_headers"],
274275
linkshared = 1,
275276
visibility = visibility,
276277
)

ml_metadata/move_generated_files.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ function mlmd::move_generated_files() {
5454
${BUILD_WORKSPACE_DIRECTORY}/${MLMD_EXTENSION}
5555
else
5656
MLMD_EXTENSION="ml_metadata/metadata_store/pywrap/metadata_store_extension.so"
57-
cp -f ${BUILD_WORKSPACE_DIRECTORY}/bazel-bin/${MLMD_EXTENSION} \
58-
${BUILD_WORKSPACE_DIRECTORY}/${MLMD_EXTENSION}
57+
DEST_FILE="${BUILD_WORKSPACE_DIRECTORY}/${MLMD_EXTENSION}"
58+
# remove old .so file first to avoid catastrophic failure on macOS due to codesign.
59+
rm -f "$DEST_FILE"
60+
cp -f ${BUILD_WORKSPACE_DIRECTORY}/bazel-bin/${MLMD_EXTENSION} "${DEST_FILE}"
5961
fi
6062

6163
chmod +w "${BUILD_WORKSPACE_DIRECTORY}/${MLMD_EXTENSION}"

ml_metadata/mysql_configure.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def mysql_configure():
2525
name = "libmysqlclient",
2626
build_file = "//ml_metadata:libmysqlclient.BUILD",
2727
workspace_file = "//ml_metadata:libmysqlclient.WORKSPACE",
28+
patches = ["//ml_metadata/third_party:mariadbconnector.patch"],
2829
remote = "https://github.com/MariaDB/mariadb-connector-c.git",
29-
tag = "v3.0.8-release",
30+
tag = "v3.3.2",
3031
)

ml_metadata/third_party/grpc.patch

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)