Skip to content

Commit 0b3ae20

Browse files
authored
Move options to bazelrc and use job container for linux (#1436)
* move build options to `.bazelrc` * use job container to run linux actions * address review
1 parent 9f7679e commit 0b3ae20

File tree

6 files changed

+62
-66
lines changed

6 files changed

+62
-66
lines changed

.github/workflows/api.yml

-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ on:
77
schedule:
88
- cron: "0 12 * * *"
99

10-
env:
11-
BAZEL_OPTIMIZATION: --copt=-msse4.2 --copt=-mavx --compilation_mode=opt
12-
1310
jobs:
1411

1512
macos:

.github/workflows/build.bazel.sh

+6-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ set -e -x
1818
export TENSORFLOW_INSTALL="$(python3 setup.py --install-require)"
1919

2020
export BAZEL_OS=$(uname | tr '[:upper:]' '[:lower:]')
21+
export BAZEL_VERSION=$(cat .bazelversion)
2122
curl -sSOL https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-installer-${BAZEL_OS}-x86_64.sh
2223
bash -e bazel-${BAZEL_VERSION}-installer-${BAZEL_OS}-x86_64.sh
2324
bazel version
@@ -35,17 +36,17 @@ python3 tools/build/configure.py
3536
cat .bazelrc
3637

3738
bazel build \
38-
--crosstool_top=//third_party/toolchains/gcc7_manylinux2010:toolchain \
3939
${BAZEL_OPTIMIZATION} \
40-
--noshow_progress \
41-
--noshow_loading_progress \
42-
--verbose_failures \
43-
--test_output=errors \
4440
-- //tensorflow_io/... //tensorflow_io_gcs_filesystem/...
4541

4642
rm -rf build && mkdir -p build
4743

4844
cp -r bazel-bin/tensorflow_io build/tensorflow_io
4945
cp -r bazel-bin/tensorflow_io_gcs_filesystem build/tensorflow_io_gcs_filesystem
5046

47+
chown -R $(id -nu):$(id -ng) build/tensorflow_io/
48+
chown -R $(id -nu):$(id -ng) build/tensorflow_io_gcs_filesystem/
49+
find build/tensorflow_io -name '*runfiles*' | xargs rm -rf
50+
find build/tensorflow_io_gcs_filesystem -name '*runfiles*' | xargs rm -rf
51+
5152
exit 0

.github/workflows/build.gpu.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ cat .bazelrc
7676

7777
bazel build -s --verbose_failures -c opt -k \
7878
--jobs=${N_JOBS} \
79-
--crosstool_top=//third_party/toolchains/gcc7_manylinux2010-nvcc-cuda10.1:toolchain \
79+
--config=linux_ci_gpu \
8080
//tensorflow_io/core:python/ops/libtensorflow_io.so
8181

8282
exit $?

.github/workflows/build.yml

+28-54
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ on:
1111
env:
1212
REPO_NAME: ${{ github.repository }}
1313
EVENT_NAME: ${{ github.event_name }}
14-
BAZEL_OPTIMIZATION: --copt=-msse4.2 --copt=-mavx --compilation_mode=opt
1514

1615
jobs:
1716
lint:
@@ -59,10 +58,9 @@ jobs:
5958
- name: macOS
6059
run: |
6160
set -x -e
61+
export BAZEL_OPTIMIZATION="--config=cache"
6262
if [[ "${EVENT_NAME}" == "push" && "${REPO_NAME}" == "tensorflow/io" ]]; then
63-
export BAZEL_OPTIMIZATION="--remote_cache=https://storage.googleapis.com/tensorflow-sigs-io --remote_upload_local_results=true --google_credentials=service_account_creds.json"
64-
else
65-
export BAZEL_OPTIMIZATION="--remote_cache=https://storage.googleapis.com/tensorflow-sigs-io --remote_upload_local_results=false"
63+
export BAZEL_OPTIMIZATION="$BAZEL_OPTIMIZATION --remote_upload_local_results=true --google_credentials=service_account_creds.json"
6664
fi
6765
echo "Bring /usr/bin to front as GitHub does not use system python3 by default"
6866
export PATH=/usr/bin:$PATH
@@ -76,6 +74,11 @@ jobs:
7674
linux:
7775
name: Linux
7876
runs-on: ubuntu-latest
77+
container:
78+
image: ubuntu:20.04
79+
env:
80+
REPO_NAME: ${{ env.REPO_NAME }}
81+
EVENT_NAME: ${{ env.EVENT_NAME }}
7982
steps:
8083
- uses: actions/checkout@v2
8184
- name: GCP
@@ -84,19 +87,18 @@ jobs:
8487
${{ secrets.GCP_CREDS }}
8588
EOF
8689
- name: Ubuntu 20.04
90+
shell: bash
8791
run: |
8892
set -x -e
93+
export BAZEL_OPTIMIZATION="--config=cache"
8994
if [[ "${EVENT_NAME}" == "push" && "${REPO_NAME}" == "tensorflow/io" ]]; then
90-
export BAZEL_OPTIMIZATION="--remote_cache=https://storage.googleapis.com/tensorflow-sigs-io --remote_upload_local_results=true --google_credentials=service_account_creds.json"
91-
else
92-
export BAZEL_OPTIMIZATION="--remote_cache=https://storage.googleapis.com/tensorflow-sigs-io --remote_upload_local_results=false"
95+
export BAZEL_OPTIMIZATION="$BAZEL_OPTIMIZATION --remote_upload_local_results=true --google_credentials=service_account_creds.json"
9396
fi
94-
bash -x -e .github/workflows/build.space.sh
97+
apt update
98+
apt-get install -y python3
9599
python3 .github/workflows/build.instruction.py docs/development.md "##### Ubuntu 20.04" > source.sh
96100
cat source.sh
97-
docker run -i --rm -v $PWD:/v -w /v --net=host \
98-
-e BAZEL_OPTIMIZATION="${BAZEL_OPTIMIZATION}" \
99-
ubuntu:20.04 bash -x -e source.sh
101+
bash -x -e source.sh
100102
101103
macos-bazel:
102104
name: Bazel macOS
@@ -111,32 +113,13 @@ jobs:
111113
- name: Bazel on macOS
112114
run: |
113115
set -x -e
116+
export BAZEL_OPTIMIZATION="--config=optimization --config=cache"
114117
if [[ "${EVENT_NAME}" == "push" && "${REPO_NAME}" == "tensorflow/io" ]]; then
115-
export BAZEL_OPTIMIZATION="${BAZEL_OPTIMIZATION} --remote_cache=https://storage.googleapis.com/tensorflow-sigs-io --remote_upload_local_results=true --google_credentials=service_account_creds.json"
116-
else
117-
export BAZEL_OPTIMIZATION="${BAZEL_OPTIMIZATION} --remote_cache=https://storage.googleapis.com/tensorflow-sigs-io --remote_upload_local_results=false"
118+
export BAZEL_OPTIMIZATION="$BAZEL_OPTIMIZATION --remote_upload_local_results=true --google_credentials=service_account_creds.json"
118119
fi
119120
echo "Bring /usr/bin to front as GitHub does not use system python3 by default"
120121
export PATH=/usr/bin:$PATH
121-
python3 --version
122-
python3 -c 'import site; print(site.getsitepackages())'
123-
BAZEL_OS=$(uname | tr '[:upper:]' '[:lower:]')
124-
BAZEL_VERSION=$(cat .bazelversion)
125-
curl -sSOL https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-installer-${BAZEL_OS}-x86_64.sh
126-
sudo bash -e bazel-${BAZEL_VERSION}-installer-${BAZEL_OS}-x86_64.sh
127-
sudo python3 -m pip install $(python3 setup.py --install-require)
128-
python3 tools/build/configure.py
129-
bazel build \
130-
${BAZEL_OPTIMIZATION} \
131-
--copt -Wunguarded-availability \
132-
--noshow_progress \
133-
--noshow_loading_progress \
134-
--verbose_failures \
135-
--test_output=errors \
136-
//tensorflow_io/... //tensorflow_io_gcs_filesystem/...
137-
mkdir build
138-
cp -r bazel-bin/tensorflow_io build
139-
cp -r bazel-bin/tensorflow_io_gcs_filesystem build
122+
sudo -E bash -e .github/workflows/build.bazel.sh
140123
- uses: actions/upload-artifact@v2
141124
with:
142125
name: ${{ runner.os }}-bazel-bin
@@ -225,6 +208,11 @@ jobs:
225208
linux-bazel:
226209
name: Bazel Linux
227210
runs-on: ubuntu-latest
211+
container:
212+
image: gcr.io/tensorflow-testing/nosla-ubuntu16.04-manylinux2010@sha256:3a9b4820021801b1fa7d0592c1738483ac7abc209fc6ee8c9ef06cf2eab2d170
213+
env:
214+
REPO_NAME: ${{ env.REPO_NAME }}
215+
EVENT_NAME: ${{ env.EVENT_NAME }}
228216
steps:
229217
- uses: actions/checkout@v2
230218
- name: GCP
@@ -233,23 +221,14 @@ jobs:
233221
${{ secrets.GCP_CREDS }}
234222
EOF
235223
- name: Bazel on Linux
224+
shell: bash
236225
run: |
237226
set -x -e
227+
export BAZEL_OPTIMIZATION="--config=optimization --config=linux_ci --config=cache"
238228
if [[ "${EVENT_NAME}" == "push" && "${REPO_NAME}" == "tensorflow/io" ]]; then
239-
export BAZEL_OPTIMIZATION="${BAZEL_OPTIMIZATION} --remote_cache=https://storage.googleapis.com/tensorflow-sigs-io --remote_upload_local_results=true --google_credentials=service_account_creds.json"
240-
else
241-
export BAZEL_OPTIMIZATION="${BAZEL_OPTIMIZATION} --remote_cache=https://storage.googleapis.com/tensorflow-sigs-io --remote_upload_local_results=false"
229+
export BAZEL_OPTIMIZATION="$BAZEL_OPTIMIZATION --remote_upload_local_results=true --google_credentials=service_account_creds.json"
242230
fi
243-
bash -x -e .github/workflows/build.space.sh
244-
BAZEL_OS=$(uname | tr '[:upper:]' '[:lower:]')
245-
BAZEL_VERSION=$(cat .bazelversion)
246-
docker run -i --rm -v $PWD:/v -w /v --net=host \
247-
-e BAZEL_VERSION=${BAZEL_VERSION} \
248-
-e BAZEL_OPTIMIZATION="${BAZEL_OPTIMIZATION}" \
249-
gcr.io/tensorflow-testing/nosla-ubuntu16.04-manylinux2010@sha256:3a9b4820021801b1fa7d0592c1738483ac7abc209fc6ee8c9ef06cf2eab2d170 /v/.github/workflows/build.bazel.sh
250-
sudo chown -R $(id -nu):$(id -ng) .
251-
sudo find build/tensorflow_io -name '*runfiles*' | sudo xargs rm -rf
252-
sudo find build/tensorflow_io_gcs_filesystem -name '*runfiles*' | sudo xargs rm -rf
231+
bash -x -e .github/workflows/build.bazel.sh
253232
sudo cp .bazelrc build/tensorflow_io/
254233
- uses: actions/upload-artifact@v2
255234
with:
@@ -347,16 +326,11 @@ jobs:
347326
shell: cmd
348327
run: |
349328
@echo on
329+
set "BAZEL_OPTIMIZATION=--config=cache"
350330
if "%EVENT_NAME%" == "push" (
351331
if "%REPO_NAME%" == "tensorflow/io" (
352-
set "BAZEL_OPTIMIZATION=--remote_cache=https://storage.googleapis.com/tensorflow-sigs-io --remote_upload_local_results=true --google_credentials=service_account_creds.json"
353-
) else (
354-
echo %REPO_NAME%
355-
set "BAZEL_OPTIMIZATION=--remote_cache=https://storage.googleapis.com/tensorflow-sigs-io --remote_upload_local_results=false"
332+
set "BAZEL_OPTIMIZATION=%BAZEL_OPTIMIZATION% --remote_upload_local_results=true --google_credentials=service_account_creds.json"
356333
)
357-
) else (
358-
echo %EVENT_NAME%
359-
set "BAZEL_OPTIMIZATION=--remote_cache=https://storage.googleapis.com/tensorflow-sigs-io --remote_upload_local_results=false"
360334
)
361335
set /P BAZEL_VERSION=< .bazelversion
362336
curl -sSL -o bazel.exe https://github.com/bazelbuild/bazel/releases/download/%BAZEL_VERSION%/bazel-%BAZEL_VERSION%-windows-x86_64.exe
@@ -367,7 +341,7 @@ jobs:
367341
python3 setup.py --install-require | xargs python3 -m pip install
368342
python3 tools/build/configure.py
369343
cat .bazelrc
370-
bazel build -s --verbose_failures --noshow_progress --noshow_loading_progress --experimental_ui_max_stdouterr_bytes=-1 %BAZEL_OPTIMIZATION% //tensorflow_io/core:python/ops/libtensorflow_io.so //tensorflow_io/core:python/ops/libtensorflow_io_plugins.so //tensorflow_io_gcs_filesystem/...
344+
bazel build -s %BAZEL_OPTIMIZATION% //tensorflow_io/core:python/ops/libtensorflow_io.so //tensorflow_io/core:python/ops/libtensorflow_io_plugins.so //tensorflow_io_gcs_filesystem/...
371345
if %errorlevel% neq 0 exit /b %errorlevel%
372346
mkdir build
373347
cp -r bazel-bin/tensorflow_io build

.kokorun/io_cpu.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ docker --version
4848
export PYTHON_VERSION=3.8
4949

5050
export BAZEL_VERSION=$(cat .bazelversion)
51-
export BAZEL_OPTIMIZATION="--copt=-msse4.2 --copt=-mavx --compilation_mode=opt --remote_cache=https://storage.googleapis.com/tensorflow-sigs-io --remote_upload_local_results=false"
51+
export BAZEL_OPTIMIZATION="--config=optimization --config=cache"
5252
export BAZEL_OS=$(uname | tr '[:upper:]' '[:lower:]')
5353

5454
docker run -i --rm -v $PWD:/v -w /v --net=host \

tools/build/configure.py

+26-2
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,40 @@ def write_config():
114114
bazel_rc.write('build --action_env TF_CUDA_VERSION="10.1"\n')
115115
bazel_rc.write('build --action_env TF_CUDNN_VERSION="7"\n')
116116
# Needed for tf rules
117-
bazel_rc.write('build --experimental_repo_remote_exec\n')
117+
bazel_rc.write("build --experimental_repo_remote_exec\n")
118118
# Enable platform specific config
119-
bazel_rc.write('build --enable_platform_specific_config\n')
119+
bazel_rc.write("build --enable_platform_specific_config\n")
120120
# Needed for GRPC build
121121
bazel_rc.write('build:macos --copt="-DGRPC_BAZEL_BUILD"\n')
122122
# Stay with 10.14 for macOS
123123
bazel_rc.write('build:macos --copt="-mmacosx-version-min=10.14"\n')
124124
bazel_rc.write('build:macos --linkopt="-mmacosx-version-min=10.14"\n')
125+
# Warns for unguarded uses of Objective-C APIs
126+
bazel_rc.write("build:macos --copt=-Wunguarded-availability\n")
125127
# MSVC (Windows): Standards-conformant preprocessor mode
126128
bazel_rc.write('build:windows --copt="/Zc:preprocessor"\n')
129+
# Config for CI and release build
130+
bazel_rc.write("build:optimization --copt=-msse4.2\n")
131+
bazel_rc.write("build:optimization --copt=-mavx\n")
132+
bazel_rc.write("build:optimization --compilation_mode=opt\n")
133+
bazel_rc.write(
134+
"build:linux_ci --crosstool_top=//third_party/toolchains/gcc7_manylinux2010:toolchain\n"
135+
)
136+
bazel_rc.write(
137+
"build:linux_ci_gpu --crosstool_top=//third_party/toolchains/gcc7_manylinux2010-nvcc-cuda10.1:toolchain\n"
138+
)
139+
# For a cleaner output
140+
bazel_rc.write("build --noshow_progress\n")
141+
bazel_rc.write("build --noshow_loading_progress\n")
142+
bazel_rc.write("build --verbose_failures\n")
143+
bazel_rc.write("build --test_output=errors\n")
144+
bazel_rc.write("build --experimental_ui_max_stdouterr_bytes=-1\n")
145+
# GCS cache (read-only by default)
146+
bazel_rc.write(
147+
"build:cache --remote_cache=https://storage.googleapis.com/tensorflow-sigs-io\n"
148+
)
149+
bazel_rc.write("build:cache --remote_upload_local_results=false\n")
150+
127151
bazel_rc.close()
128152
except OSError:
129153
print("ERROR: Writing .bazelrc")

0 commit comments

Comments
 (0)