Skip to content

Commit 5f3a351

Browse files
allow building ml_metadata_store_server image on ARM64
1 parent 790e26d commit 5f3a351

File tree

6 files changed

+94
-50
lines changed

6 files changed

+94
-50
lines changed

.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5.3.0

ml_metadata/.bazelversion

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

ml_metadata/postgresql.BUILD

Lines changed: 66 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ exports_files(["COPYRIGHT"])
66

77
# This is OSS version of PostgreSQL bazel build target.
88
# The build target is consistent with Tensorflow's dependency on PostgreSQL.
9-
# Reference: https://github.com/tensorflow/io/commit/6a2b9b3e94fd80f9a7f0b982089e8a69751bd059
9+
# Reference: https://github.com/tensorflow/io/commit/a1171cdd20e658ef3f1a8b3bf66dd4e228ceae30
1010
cc_library(
1111
name = "postgresql",
1212
srcs = glob([
@@ -43,8 +43,8 @@ cc_library(
4343
"src/common/unicode_norm.c",
4444
"src/common/username.c",
4545
"src/common/wait_error.c",
46-
"src/interfaces/libpq/fe-auth.c",
4746
"src/interfaces/libpq/fe-auth-scram.c",
47+
"src/interfaces/libpq/fe-auth.c",
4848
"src/interfaces/libpq/fe-connect.c",
4949
"src/interfaces/libpq/fe-exec.c",
5050
"src/interfaces/libpq/fe-lobj.c",
@@ -62,8 +62,6 @@ cc_library(
6262
"src/port/path.c",
6363
"src/port/pg_bitutils.c",
6464
"src/port/pg_crc32c_sb8.c",
65-
# Comment this line out to force usage of sb8 algorithm of crc32c
66-
# "src/port/pg_crc32c_sse42_choose.c",
6765
"src/port/pg_strong_random.c",
6866
"src/port/pgcheckdir.c",
6967
"src/port/pgmkdirp.c",
@@ -80,12 +78,28 @@ cc_library(
8078
"src/port/tar.c",
8179
"src/port/thread.c",
8280
] + select({
83-
"@//ml_metadata:macos": [],
81+
"@bazel_tools//src/conditions:darwin": [],
82+
"@bazel_tools//src/conditions:windows": [
83+
"src/interfaces/libpq/pthread-win32.c",
84+
"src/interfaces/libpq/win32.c",
85+
"src/port/dirmod.c",
86+
"src/port/getaddrinfo.c",
87+
"src/port/inet_aton.c",
88+
"src/port/open.c",
89+
"src/port/strlcpy.c",
90+
"src/port/win32error.c",
91+
"src/port/win32setlocale.c",
92+
"src/port/pthread-win32.h",
93+
],
8494
"//conditions:default": [
8595
"src/port/getpeereid.c",
86-
"src/port/strlcat.c",
8796
"src/port/strlcpy.c",
8897
],
98+
}) + select({
99+
"@platforms//cpu:x86_64": [
100+
"src/port/pg_crc32c_sse42_choose.c",
101+
],
102+
"//conditions:default": [],
89103
}),
90104
hdrs = [
91105
"config/pg_config.h",
@@ -98,7 +112,14 @@ cc_library(
98112
defines = [
99113
"FRONTEND",
100114
] + select({
101-
"@//ml_metadata:macos": [
115+
"@bazel_tools//src/conditions:windows": [
116+
"BLCKSZ=8192",
117+
"XLOG_BLCKSZ=8192",
118+
'PG_MAJORVERSION=\\"12\\"',
119+
"HAVE_LIBZ=1",
120+
"WIN32",
121+
],
122+
"@bazel_tools//src/conditions:darwin": [
102123
"HAVE_DECL_STRLCPY=1",
103124
"HAVE_STRLCPY=1",
104125
"HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN=1",
@@ -114,9 +135,18 @@ cc_library(
114135
"src/include",
115136
"src/interfaces/libpq",
116137
] + select({
138+
"@bazel_tools//src/conditions:windows": [
139+
"src/include/port/win32",
140+
"src/include/port/win32_msvc",
141+
"src/port",
142+
],
117143
"//conditions:default": [],
118144
}),
119145
linkopts = select({
146+
"@bazel_tools//src/conditions:windows": [
147+
"-DEFAULTLIB:ws2_32.lib",
148+
"-DEFAULTLIB:shell32.lib",
149+
],
120150
"//conditions:default": [],
121151
}),
122152
deps = [],
@@ -125,7 +155,10 @@ cc_library(
125155
genrule(
126156
name = "pg_config_os_h",
127157
srcs = select({
128-
"@//ml_metadata:macos": [
158+
"@bazel_tools//src/conditions:windows": [
159+
"src/include/port/win32.h",
160+
],
161+
"@bazel_tools//src/conditions:darwin": [
129162
"src/include/port/darwin.h",
130163
],
131164
"//conditions:default": [
@@ -135,18 +168,22 @@ genrule(
135168
outs = [
136169
"config/pg_config_os.h",
137170
],
138-
cmd = "cp $< $@",
171+
cmd = ("cp $< $@"),
139172
)
140173

141174
genrule(
142175
name = "pg_config_ext_h",
143176
srcs = select({
177+
"@bazel_tools//src/conditions:windows": [
178+
"src/include/pg_config_ext.h.win32",
179+
],
144180
"//conditions:default": [
145181
"src/include/pg_config_ext.h.in",
146182
],
147183
}),
148184
outs = ["config/pg_config_ext.h"],
149185
cmd = select({
186+
"@bazel_tools//src/conditions:windows": ("cp $< $@"),
150187
"//conditions:default": (
151188
"sed " +
152189
"-e 's/undef PG_INT64_TYPE/define PG_INT64_TYPE long int/g' " +
@@ -357,6 +394,9 @@ genrule(
357394
genrule(
358395
name = "pg_config_h",
359396
srcs = select({
397+
"@bazel_tools//src/conditions:windows": [
398+
"src/include/pg_config.h.win32",
399+
],
360400
"//conditions:default": [
361401
"src/include/pg_config.h.in",
362402
],
@@ -365,7 +405,8 @@ genrule(
365405
"config/pg_config.h",
366406
],
367407
cmd = select({
368-
"//conditions:default": "\n".join([
408+
"@bazel_tools//src/conditions:windows": ("cp $< $@"),
409+
"//conditions:default": ("\n".join([
369410
"cat <<'EOF' >$@",
370411
"/* src/include/pg_config.h. Generated from pg_config.h.in by configure. */",
371412
"/* src/include/pg_config.h.in. Generated from configure.in by autoheader. */",
@@ -1145,9 +1186,11 @@ genrule(
11451186
"/* Define to 1 if you have __cpuid. */",
11461187
"/* #undef HAVE__CPUID */",
11471188
"",
1189+
"#if defined __x86_64__",
11481190
"/* Define to 1 if you have __get_cpuid. */",
11491191
"#define HAVE__GET_CPUID 1",
11501192
"",
1193+
"#endif",
11511194
"/* Define to 1 if your compiler understands _Static_assert. */",
11521195
"#define HAVE__STATIC_ASSERT 1",
11531196
"",
@@ -1312,15 +1355,13 @@ genrule(
13121355
"/* #undef USE_PAM */",
13131356
"",
13141357
"/* Define to 1 to use software CRC-32C implementation (slicing-by-8). */",
1315-
# Force usage of sb8 algorithm of crc32c
1316-
"#define USE_SLICING_BY_8_CRC32C 1",
1358+
"/* #undef USE_SLICING_BY_8_CRC32C */",
13171359
"",
13181360
"/* Define to 1 use Intel SSE 4.2 CRC instructions. */",
13191361
"/* #undef USE_SSE42_CRC32C */",
13201362
"",
13211363
"/* Define to 1 to use Intel SSE 4.2 CRC instructions with a runtime check. */",
1322-
# Do not check at runtime but force usage of sb8 algorithm of crc32c
1323-
"/* #undef USE_SSE42_CRC32C_WITH_RUNTIME_CHECK */",
1364+
"#define USE_SSE42_CRC32C_WITH_RUNTIME_CHECK 1",
13241365
"",
13251366
"/* Define to build with systemd support. (--with-systemd) */",
13261367
"/* #undef USE_SYSTEMD */",
@@ -1334,6 +1375,15 @@ genrule(
13341375
"/* Define to select unnamed POSIX semaphores. */",
13351376
"/* #undef USE_UNNAMED_POSIX_SEMAPHORES */",
13361377
"",
1378+
"/* Define to use native Windows API for random number generation */",
1379+
"/* #undef USE_WIN32_RANDOM */",
1380+
"",
1381+
"/* Define to select Win32-style semaphores. */",
1382+
"/* #undef USE_WIN32_SEMAPHORES */",
1383+
"",
1384+
"/* Define to select Win32-style shared memory. */",
1385+
"/* #undef USE_WIN32_SHARED_MEMORY */",
1386+
"",
13371387
"/* Define to 1 if `wcstombs_l' requires <xlocale.h>. */",
13381388
"#define WCSTOMBS_L_IN_XLOCALE 1",
13391389
"",
@@ -1405,6 +1455,6 @@ genrule(
14051455
" pointer, if such a type exists, and if the system does not define it. */",
14061456
"/* #undef uintptr_t */",
14071457
"EOF",
1408-
]),
1458+
])),
14091459
}),
1410-
)
1460+
)

ml_metadata/tools/docker_server/Dockerfile

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# TODO(b/195701120) Introduces l.gcr.io/google/bazel:5.3.0 when it is available
16-
# and makes sure that it uses ubuntu 20.04 as base image. Currently the lastest
17-
# version only supports bazel 3.5.0.
1815
FROM ubuntu:20.04 as builder
1916

17+
ARG TARGETARCH
18+
2019
RUN export DEBIAN_FRONTEND=noninteractive && \
2120
apt-get update -y --option Acquire::Retries=3 && \
2221
apt-get install --no-install-recommends -y -q --option Acquire::Retries=3 \
@@ -35,17 +34,16 @@ RUN export DEBIAN_FRONTEND=noninteractive && \
3534
python-is-python3 \
3635
python3-dev
3736

38-
# Set up Bazel 5.3.0
39-
ENV BAZEL_VERSION 5.3.0
37+
# Install Bazelisk
38+
ENV BAZELISK_VERSION 1.19.0
4039
WORKDIR /
41-
RUN mkdir /bazel && \
42-
cd /bazel && \
43-
curl -H "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36" -fSsL -O https://github.com/bazelbuild/bazel/releases/download/$BAZEL_VERSION/bazel-$BAZEL_VERSION-installer-linux-x86_64.sh && \
44-
curl -H "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36" -fSsL -o /bazel/LICENSE.txt https://raw.githubusercontent.com/bazelbuild/bazel/master/LICENSE && \
45-
chmod +x bazel-*.sh && \
46-
./bazel-$BAZEL_VERSION-installer-linux-x86_64.sh && \
47-
cd / && \
48-
rm -f /bazel/bazel-$BAZEL_VERSION-installer-linux-x86_64.sh
40+
RUN case "${TARGETARCH}" in \
41+
amd64) BAZELISK_ARCH="amd64" ;; \
42+
arm64) BAZELISK_ARCH="arm64" ;; \
43+
*) echo "Unsupported architecture: ${TARGETARCH}"; exit 1 ;; \
44+
esac && \
45+
curl -fSsL https://github.com/bazelbuild/bazelisk/releases/download/v${BAZELISK_VERSION}/bazelisk-linux-${BAZELISK_ARCH} -o /usr/local/bin/bazel && \
46+
chmod +x /usr/local/bin/bazel
4947

5048
ADD . /mlmd-src
5149
WORKDIR /mlmd-src
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
Files for building the [Docker](http://www.docker.com) image for running the
2-
MLMD gRPC server.
1+
Files for building the container image that runs the MLMD gRPC server (`gcr.io/tfx-oss-public/ml_metadata_store_server`).
32

4-
To build a docker image, run
5-
`./ml_metadata/tools/docker_server/build_docker_image.sh` under root directory
6-
of github checkout.
3+
To build the image, run the following command:
4+
5+
```shell
6+
./ml_metadata/tools/docker_server/build_docker_image.sh
7+
```

ml_metadata/tools/docker_server/build_docker_image.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env bash
12
# Copyright 2019 Google LLC. All Rights Reserved.
23
#
34
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,11 +15,18 @@
1415

1516
# Convenience script to build docker image for MLMD gRPC server.
1617

17-
set -u -x
18+
set -euo pipefail
1819

1920
DOCKER_IMAGE_REPO=${DOCKER_IMAGE_REPO:-"gcr.io/tfx-oss-public/ml_metadata_store_server"}
2021
DOCKER_IMAGE_TAG=${DOCKER_IMAGE_TAG:-"latest"}
2122
DOCKER_FILE=${DOCKER_FILE:-"Dockerfile"}
2223

24+
# Change to repository root.
25+
REPOSITORY_ROOT_PATH=$(git rev-parse --show-toplevel)
26+
cd "${REPOSITORY_ROOT_PATH}"
27+
2328
# Run docker build command.
24-
docker build -t ${DOCKER_IMAGE_REPO}:${DOCKER_IMAGE_TAG} -f ml_metadata/tools/docker_server/${DOCKER_FILE} .
29+
docker build \
30+
-t ${DOCKER_IMAGE_REPO}:${DOCKER_IMAGE_TAG} \
31+
-f ml_metadata/tools/docker_server/${DOCKER_FILE} \
32+
.

0 commit comments

Comments
 (0)