Skip to content

Instantly share code, notes, and snippets.

@purkhusid
Created February 9, 2022 08:37
Show Gist options
  • Save purkhusid/644e19abba53bbdb105b0e79e44dd7e7 to your computer and use it in GitHub Desktop.
Save purkhusid/644e19abba53bbdb105b0e79e44dd7e7 to your computer and use it in GitHub Desktop.
# Python
# 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)
else
./configure --prefix=$(pwd)/bazel_install
fi
"""
http_archive(
name = "python_interpreter",
build_file_content = """
exports_files(["python_bin"])
filegroup(
name = "files",
srcs = glob(["bazel_install/**"], exclude = ["**/* *"]),
visibility = ["//visibility:public"],
)
""",
patch_cmds = [
"mkdir $(pwd)/bazel_install",
_py_configure,
"make",
"make install",
"ln -s bazel_install/bin/python3 python_bin",
],
sha256 = "dfab5ec723c218082fe3d5d7ae17ecbdebffa9a1aea4d64aa3a2ecdd2e795864",
strip_prefix = "Python-3.8.3",
urls = ["https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tar.xz"],
)
http_archive(
name = "rules_python",
sha256 = "b6d46438523a3ec0f3cead544190ee13223a52f6a6765a29eae7b7cc24cc83a0",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.1.0/rules_python-0.1.0.tar.gz",
)
load("@rules_python//python:pip.bzl", "pip_install")
pip_install(
name = "pip",
python_interpreter_target = "@python_interpreter//:python_bin",
requirements = "//src/python:requirements.txt",
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment