Put the py3 toolchain in the tin

This commit is contained in:
Reid 'arrdem' McKenzie 2021-08-29 21:41:20 -06:00
parent 4ee4f3d011
commit e5686db6cb
5 changed files with 65 additions and 11 deletions

View file

@ -27,8 +27,18 @@ git_repository(
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
bazel_skylib_workspace() bazel_skylib_workspace()
####################################################################################################
# rules_python
####################################################################################################
git_repository( git_repository(
name = "rules_python", name = "rules_python",
remote = "https://github.com/bazelbuild/rules_python.git", remote = "https://github.com/bazelbuild/rules_python.git",
tag = "0.3.0", tag = "0.3.0",
) )
# And so that zapp can zapp itself...
# Note that consumers DO NOT get this dependency "for free".
register_toolchains(
"//zapp:python3_toolchain",
)

View file

@ -36,6 +36,12 @@ toolchain(
# Zapp examples & tests # Zapp examples & tests
py_test(
name = "hello_native",
main = "hello.py",
srcs = ["hello.py"],
)
zapp_test( zapp_test(
name = "hello_script", name = "hello_script",
main = "hello.py", main = "hello.py",

View file

@ -29,12 +29,21 @@ git_repository(
tag = "0.3.0", tag = "0.3.0",
) )
register_toolchains("//:python3_toolchain") load("@rules_python//python:pip.bzl", "pip_install")
pip_install(
name = "my_deps",
requirements = "//:requirements.txt",
)
####################################################################################################
# rules_zapp
####################################################################################################
# git_repository( # git_repository(
# name = "rules_zapp", # name = "rules_zapp",
# remote = "https://github.com/arrdem/rules_zapp.git", # remote = "https://github.com/arrdem/rules_zapp.git",
# tag = "0.1.1", # tag = "0.1.3",
# # branch = "trunk", # # branch = "trunk",
# ) # )
@ -43,9 +52,7 @@ local_repository(
path = "../", path = "../",
) )
load("@rules_python//python:pip.bzl", "pip_install") # Use the py3 default toolchain from zapp for a quickstart
register_toolchains(
pip_install( "@rules_zapp//zapp:python3_toolchain",
name = "my_deps",
requirements = "//:requirements.txt",
) )

View file

@ -1,6 +1,36 @@
package(default_visibility = ["//visibility:public"]) package(default_visibility = ["//visibility:public"])
load("zapp.bzl", "zapp_binary") load("@rules_python//python:defs.bzl",
"py_library",
"py_runtime",
"py_runtime_pair"
)
load("zapp.bzl",
"zapp_binary"
)
# The Python runtime we need
py_runtime(
name = "python3_runtime",
files = [],
interpreter_path = "/usr/bin/python3",
python_version = "PY3",
visibility = ["//visibility:public"],
)
py_runtime_pair(
name = "python_runtime",
py2_runtime = None,
py3_runtime = ":python3_runtime",
)
toolchain(
name = "python3_toolchain",
toolchain = ":python_runtime",
toolchain_type = "@bazel_tools//tools/python:toolchain_type",
)
# Zapp plugins used as a runtime library by rules_zapp # Zapp plugins used as a runtime library by rules_zapp
py_library( py_library(
@ -11,7 +41,7 @@ py_library(
] ]
) )
# Bootstrapping Zapp using py_binary
py_binary( py_binary(
name = "zappc", name = "zappc",
main = "compiler/__main__.py", main = "compiler/__main__.py",
@ -23,7 +53,7 @@ py_binary(
], ],
) )
# For testing of zappc # Bootstrapping because we can
zapp_binary( zapp_binary(
name = "zappzappc", name = "zappzappc",
main = "compiler/__main__.py", main = "compiler/__main__.py",

View file

@ -177,13 +177,14 @@ _zapp_attrs = {
"wheels": attr.label_list(), "wheels": attr.label_list(),
"entry_point": attr.string(), "entry_point": attr.string(),
"prelude_points": attr.string_list(), "prelude_points": attr.string_list(),
"zip_safe": attr.bool(default = True),
# FIXME: These are really toolchain parameters, probably.
"compiler": attr.label( "compiler": attr.label(
default = Label(DEFAULT_COMPILER), default = Label(DEFAULT_COMPILER),
executable = True, executable = True,
cfg = "host", cfg = "host",
), ),
"shebang": attr.string(default = "/usr/bin/env %py3%"), "shebang": attr.string(default = "/usr/bin/env %py3%"),
"zip_safe": attr.bool(default = True),
} }
_zapp = rule( _zapp = rule(