@@ -4,22 +4,74 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4
4
5
5
http_archive (
6
6
name = "rules_python" ,
7
- url = "https://github.com/bazelbuild/rules_python/releases/download/0.0.1/rules_python-0.0.1.tar.gz" ,
8
7
sha256 = "aa96a691d3a8177f3215b14b0edc9641787abaaa30363a080165d06ab65e1161" ,
8
+ url = "https://github.com/bazelbuild/rules_python/releases/download/0.0.1/rules_python-0.0.1.tar.gz" ,
9
9
)
10
+
10
11
load ("@rules_python//python:repositories.bzl" , "py_repositories" )
12
+
11
13
py_repositories ()
12
14
15
+ # You could optionally use an in-build, compiled python interpreter as a toolchain,
16
+ # and also use it to execute pip.
17
+
18
+ # Special logic for building python interpreter with OpenSSL from homebrew.
19
+ # See https://devguide.python.org/setup/#macos-and-os-x
20
+ _py_configure = """
21
+ if [[ "$OSTYPE" == "darwin"* ]]; then
22
+ ./configure --prefix=$(pwd)/bazel_install --with-openssl=$(brew --prefix openssl)
23
+ else
24
+ ./configure --prefix=$(pwd)/bazel_install
25
+ fi
26
+ """
27
+
28
+ # NOTE: you need to have the SSL headers installed to build with openssl support (and use HTTPS).
29
+ # E.g. on Ubuntu: `sudo apt install libssl-dev`
30
+ http_archive (
31
+ name = "python_interpreter" ,
32
+ build_file_content = """
33
+ exports_files(["python_bin"])
34
+ filegroup(
35
+ name = "files",
36
+ srcs = glob(["bazel_install/**"], exclude = ["**/* *"]),
37
+ visibility = ["//visibility:public"],
38
+ )
39
+ """ ,
40
+ patch_cmds = [
41
+ "mkdir $(pwd)/bazel_install" ,
42
+ _py_configure ,
43
+ "make" ,
44
+ "make install" ,
45
+ "ln -s bazel_install/bin/python3 python_bin" ,
46
+ ],
47
+ sha256 = "dfab5ec723c218082fe3d5d7ae17ecbdebffa9a1aea4d64aa3a2ecdd2e795864" ,
48
+ strip_prefix = "Python-3.8.3" ,
49
+ urls = ["https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tar.xz" ],
50
+ )
51
+ # End of in-build Python interpreter setup.
52
+
13
53
local_repository (
14
54
name = "rules_python_external" ,
15
55
path = "../" ,
16
56
)
17
57
18
58
load ("@rules_python_external//:repositories.bzl" , "rules_python_external_dependencies" )
59
+
19
60
rules_python_external_dependencies ()
20
61
21
62
load ("@rules_python_external//:defs.bzl" , "pip_install" )
63
+
22
64
pip_install (
65
+ # You can optionally provide a python_interpreter (path) or a python_interpreter_target (a Bazel target, that
66
+ # acts as an executable). The latter can be anything that could be used as Python interpreter. E.g.:
67
+ # 1. Python interpreter that you compile in the build file (as above in @python_interpreter).
68
+ # 2. Pre-compiled python interpreter included with http_archive
69
+ # 3. Wrapper script, like in the autodetecting python toolchain.
70
+ python_interpreter_target = "@python_interpreter//:python_bin" ,
23
71
# Uses the default repository name "pip"
24
72
requirements = "//:requirements.txt" ,
25
73
)
74
+
75
+ # Optional:
76
+ # Register the toolchain with the same python interpreter we used for pip in pip_install().
77
+ register_toolchains ("//:my_py_toolchain" )
0 commit comments