Skip to content

Commit

Permalink
Use fixed directory to compile python binary.
Browse files Browse the repository at this point in the history
Fixes #8
  • Loading branch information
kku1993 committed Jun 27, 2021
1 parent eeae71c commit e44664e
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,39 @@ workspace(name="py_test")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

PY_VERSION = '3.8.3'
BUILD_DIR = '/tmp/bazel-python-{0}'.format(PY_VERSION)

# Special logic for building python interpreter with OpenSSL from homebrew.
# See https://devguide.python.org/setup/#macos-and-os-x
_py_configure = """
if [[ "$OSTYPE" == "darwin"* ]]; then
./configure --prefix=$(pwd)/bazel_install --with-openssl=$(brew --prefix openssl)
cd {0} && ./configure --prefix={0}/bazel_install --with-openssl=$(brew --prefix openssl)
else
./configure --prefix=$(pwd)/bazel_install
cd {0} && ./configure --prefix={0}/bazel_install
fi
"""
""".format(BUILD_DIR)

http_archive(
name = "python_interpreter",
urls = ["https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tar.xz"],
urls = [
"https://www.python.org/ftp/python/{0}/Python-{0}.tar.xz".format(PY_VERSION),
],
sha256 = "dfab5ec723c218082fe3d5d7ae17ecbdebffa9a1aea4d64aa3a2ecdd2e795864",
strip_prefix = "Python-3.8.3",
strip_prefix = "Python-{0}".format(PY_VERSION),
patch_cmds = [
"mkdir $(pwd)/bazel_install",
# Create a build directory outside of bazel so we get consistent path in
# the generated files. See #8
"mkdir -p {0}".format(BUILD_DIR),
"cp -r * {0}".format(BUILD_DIR),
# Build python.
_py_configure,
# Produce deterministic binary by using a fixed build timestamp and
# running `ar` in deterministic mode. See #7
"SOURCE_DATE_EPOCH=0 make -j $(nproc) ARFLAGS='rvD'",
"make install",
"cd {0} && SOURCE_DATE_EPOCH=0 make -j $(nproc) ARFLAGS='rvD'".format(BUILD_DIR),
"cd {0} && make install".format(BUILD_DIR),
# Copy the contents of the build directory back into bazel.
"rm -rf * && mv {0}/* .".format(BUILD_DIR),
"ln -s bazel_install/bin/python3 python_bin",
],
build_file_content = """
Expand Down

0 comments on commit e44664e

Please sign in to comment.