Skip to content

Commit 35806b4

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 790e26d commit 35806b4

File tree

10 files changed

+49
-60
lines changed

10 files changed

+49
-60
lines changed

.bazelrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,7 @@ build --protocopt=--experimental_allow_proto3_optional
2323
# parameter 'user_link_flags' is deprecated and will be removed soon.
2424
# It may be temporarily re-enabled by setting --incompatible_require_linker_input_cc_api=false
2525
build --incompatible_require_linker_input_cc_api=false
26+
27+
# Support for Apple M1.
2628
build:macos --apple_platform_type=macos
2729
build:macos_arm64 --cpu=darwin_arm64

WORKSPACE

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -88,22 +88,22 @@ http_archive(
8888

8989
http_archive(
9090
name = "bazel_skylib",
91-
sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44",
91+
sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506",
9292
urls = [
93-
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz",
94-
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz",
93+
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
94+
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
9595
],
9696
)
9797

9898
# Needed by abseil-py by zetasql.
9999
http_archive(
100100
name = "six_archive",
101101
urls = [
102-
"http://mirror.bazel.build/pypi.python.org/packages/source/s/six/six-1.10.0.tar.gz",
103-
"https://pypi.python.org/packages/source/s/six/six-1.10.0.tar.gz",
102+
"http://mirror.bazel.build/pypi.python.org/packages/source/s/six/six-1.16.0.tar.gz",
103+
"https://pypi.python.org/packages/source/s/six/six-1.16.0.tar.gz",
104104
],
105-
sha256 = "105f8d68616f8248e24bf0e9372ef04d3cc10104f1980f54d57b2ce73a5ad56a",
106-
strip_prefix = "six-1.10.0",
105+
sha256 = "1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926",
106+
strip_prefix = "six-1.16.0",
107107
build_file = "//ml_metadata/third_party:six.BUILD"
108108
)
109109

@@ -166,11 +166,12 @@ http_archive(
166166
],
167167
)
168168

169+
# gRPC. Official release 1.50.0. Name is required by Google APIs.
169170
http_archive(
170171
name = "com_github_grpc_grpc",
171-
urls = ["https://github.com/grpc/grpc/archive/v1.46.3.tar.gz"],
172-
sha256 = "d6cbf22cb5007af71b61c6be316a79397469c58c82a942552a62e708bce60964",
173-
strip_prefix = "grpc-1.46.3",
172+
sha256 = "76900ab068da86378395a8e125b5cc43dfae671e09ff6462ddfef18676e2165a",
173+
strip_prefix = "grpc-1.50.0",
174+
urls = ["https://github.com/grpc/grpc/archive/v1.50.0.tar.gz"],
174175
)
175176

176177
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
@@ -191,34 +192,8 @@ bind(
191192
actual = "@com_github_grpc_grpc//:grpc++",
192193
)
193194

194-
# Needed by gRPC.
195-
http_archive(
196-
name = "build_bazel_rules_swift",
197-
sha256 = "d0833bc6dad817a367936a5f902a0c11318160b5e80a20ece35fb85a5675c886",
198-
strip_prefix = "rules_swift-3eeeb53cebda55b349d64c9fc144e18c5f7c0eb8",
199-
urls = ["https://github.com/bazelbuild/rules_swift/archive/3eeeb53cebda55b349d64c9fc144e18c5f7c0eb8.tar.gz"],
200-
)
201-
202-
http_archive(
203-
name = "io_bazel_rules_go",
204-
urls = [
205-
"https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/rules_go/releases/download/v0.20.3/rules_go-v0.20.3.tar.gz",
206-
"https://github.com/bazelbuild/rules_go/releases/download/v0.20.3/rules_go-v0.20.3.tar.gz",
207-
],
208-
sha256 = "e88471aea3a3a4f19ec1310a55ba94772d087e9ce46e41ae38ecebe17935de7b",
209-
)
210-
195+
# pulled in transitively by gRPC.
211196
load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies", "go_register_toolchains")
212-
213-
http_archive(
214-
name = "bazel_gazelle",
215-
urls = [
216-
"https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/bazel-gazelle/releases/download/v0.19.1/bazel-gazelle-v0.19.1.tar.gz",
217-
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.19.1/bazel-gazelle-v0.19.1.tar.gz",
218-
],
219-
sha256 = "86c6d481b3f7aedc1d60c1c211c6f76da282ae197c3b3160f54bd3a8f847896f",
220-
)
221-
222197
load("@bazel_gazelle//:deps.bzl", "go_repository", "gazelle_dependencies")
223198

224199
go_repository(
@@ -235,7 +210,7 @@ go_repository(
235210

236211
go_rules_dependencies()
237212

238-
go_register_toolchains()
213+
go_register_toolchains("host")
239214

240215
gazelle_dependencies()
241216

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ cc_library(
7171
":metadata_access_object_base",
7272
":query_executor",
7373
"@com_google_protobuf//:protobuf",
74-
74+
7575
"@com_google_absl//absl/algorithm:container",
7676
"@com_google_absl//absl/container:flat_hash_map",
7777
"@com_google_absl//absl/container:flat_hash_set",

ml_metadata/metadata_store/pywrap/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ ml_metadata_pybind_extension(
3737
"//ml_metadata/proto:metadata_store_proto",
3838
"//ml_metadata/simple_types/proto:simple_types_proto",
3939
"@pybind11",
40+
"@local_config_python//:python_headers",
4041
],
4142
)
4243

ml_metadata/ml_metadata.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ def ml_metadata_pybind_extension(
262262
"-Wl,-exported_symbols_list,$(location %s)" % exported_symbols_file,
263263
],
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/mysql_configure.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +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-
patches = ["//ml_metadata/third_party:libmysqlclient.patch"],
30+
tag = "v3.3.2",
3131
)

ml_metadata/third_party/grpc.patch

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--- libmariadb/secure/openssl.c
2+
+++ libmariadb/secure/openssl.c
3+
@@ -329,11 +329,7 @@ static int ma_tls_set_certs(MYSQL *mysql, SSL_CTX *ctx)
4+
if ((mysql->options.ssl_cipher &&
5+
mysql->options.ssl_cipher[0] != 0))
6+
{
7+
- if(
8+
-#ifdef TLS1_3_VERSION
9+
- SSL_CTX_set_ciphersuites(ctx, mysql->options.ssl_cipher) == 0 &&
10+
-#endif
11+
- SSL_CTX_set_cipher_list(ctx, mysql->options.ssl_cipher) == 0)
12+
+ if(SSL_CTX_set_cipher_list(ctx, mysql->options.ssl_cipher) == 0)
13+
goto error;
14+
}
15+

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ def run(self):
115115
# file, which is the root directory.
116116
cwd=os.path.dirname(os.path.realpath(__file__)),)
117117

118+
# explicitly call shutdown to free up resources.
119+
subprocess.check_call([self._bazel_cmd, "shutdown"])
118120

119121
# Get version from version module.
120122
with open('ml_metadata/version.py') as fp:

0 commit comments

Comments
 (0)