diff --git a/WORKSPACE b/WORKSPACE index a4852ce..cd2d7d3 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -27,8 +27,18 @@ git_repository( load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") bazel_skylib_workspace() +#################################################################################################### +# rules_python +#################################################################################################### + git_repository( name = "rules_python", remote = "https://github.com/bazelbuild/rules_python.git", 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", +) diff --git a/example/BUILD b/example/BUILD index ea782f1..6d1d2dc 100644 --- a/example/BUILD +++ b/example/BUILD @@ -36,6 +36,12 @@ toolchain( # Zapp examples & tests +py_test( + name = "hello_native", + main = "hello.py", + srcs = ["hello.py"], +) + zapp_test( name = "hello_script", main = "hello.py", diff --git a/example/WORKSPACE b/example/WORKSPACE index b94de19..5f650ae 100644 --- a/example/WORKSPACE +++ b/example/WORKSPACE @@ -29,12 +29,21 @@ git_repository( 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( # name = "rules_zapp", # remote = "https://github.com/arrdem/rules_zapp.git", -# tag = "0.1.1", +# tag = "0.1.3", # # branch = "trunk", # ) @@ -43,9 +52,7 @@ local_repository( path = "../", ) -load("@rules_python//python:pip.bzl", "pip_install") - -pip_install( - name = "my_deps", - requirements = "//:requirements.txt", +# Use the py3 default toolchain from zapp for a quickstart +register_toolchains( + "@rules_zapp//zapp:python3_toolchain", ) diff --git a/zapp/BUILD b/zapp/BUILD index cc321aa..a839829 100644 --- a/zapp/BUILD +++ b/zapp/BUILD @@ -1,6 +1,36 @@ 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 py_library( @@ -11,7 +41,7 @@ py_library( ] ) -# Bootstrapping Zapp using py_binary + py_binary( name = "zappc", main = "compiler/__main__.py", @@ -23,7 +53,7 @@ py_binary( ], ) -# For testing of zappc +# Bootstrapping because we can zapp_binary( name = "zappzappc", main = "compiler/__main__.py", diff --git a/zapp/zapp.bzl b/zapp/zapp.bzl index cfce977..47ce6d0 100644 --- a/zapp/zapp.bzl +++ b/zapp/zapp.bzl @@ -177,13 +177,14 @@ _zapp_attrs = { "wheels": attr.label_list(), "entry_point": attr.string(), "prelude_points": attr.string_list(), + "zip_safe": attr.bool(default = True), + # FIXME: These are really toolchain parameters, probably. "compiler": attr.label( default = Label(DEFAULT_COMPILER), executable = True, cfg = "host", ), "shebang": attr.string(default = "/usr/bin/env %py3%"), - "zip_safe": attr.bool(default = True), } _zapp = rule(