Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update rules_python, and vendor requirements.bzl #197

Merged
merged 3 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ llvm_toolchain(
maybe(
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",
sha256 = "5868e73107a8e85d8f323806e60cad7283f34b32163ea6ff1020cf27abef6036",
strip_prefix = "rules_python-0.25.0",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.25.0/rules_python-0.25.0.tar.gz",
)

maybe(
Expand Down
47 changes: 46 additions & 1 deletion dependency_support/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 Google LLC
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -11,3 +11,48 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@rules_python//python:pip.bzl", "compile_pip_requirements")

compile_pip_requirements(name = "pip_requirements")

genrule(
name = "clean_requirements",
srcs = ["@rules_hdl_pip_deps//:requirements.bzl"],
outs = ["requirements.clean.bzl"],
cmd = " | ".join([
"cat $<",
# Replace the bazel 6.0.0 specific comment with something that bazel 5.4.0 would produce.
# This enables this example to be run as a test under bazel 5.4.0.
"""sed -e 's#@rules_hdl//#@//#'""",
]) + " >$@",
)

write_file(
name = "gen_update",
out = "update.sh",
content = [
# This depends on bash, would need tweaks for Windows
"#!/usr/bin/env bash",
# Bazel gives us a way to access the source folder!
"cd $BUILD_WORKSPACE_DIRECTORY",
"cp -fv bazel-bin/dependency_support/requirements.clean.bzl dependency_support/requirements.bzl",
],
)

sh_binary(
name = "vendor_requirements",
srcs = ["update.sh"],
data = [":clean_requirements"],
)

# Similarly ensures that the requirements.bzl file is updated
# based on the requirements.txt lockfile.
diff_test(
name = "test_vendored",
failure_message = "Please run: bazel run //dependency_support:vendor_requirements",
file1 = "requirements.bzl",
file2 = ":clean_requirements",
)
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ def org_theopenroadproject():
patch_args = [
"-p1",
],
shallow_since = "1649354925 -0300",
shallow_since = "1659478013 -0700"
)
6 changes: 6 additions & 0 deletions dependency_support/pip_requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dataclasses-json==0.5.7
jwt==1.3.1
requests==2.28.2
absl-py==1.4.0
cocotb==1.8.0
klayout==0.28.8
311 changes: 305 additions & 6 deletions dependency_support/pip_requirements.txt

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions dependency_support/requirements.bzl

Large diffs are not rendered by default.

24 changes: 18 additions & 6 deletions init.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
""" initializes the bazel_rules_hdl workspace """

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
load("@rules_python//python:pip.bzl", "pip_install")
load("@rules_python//python:pip.bzl", "pip_parse")
load("//dependency_support:requirements.bzl", install_pip_deps = "install_deps")
load("//dependency_support/boost:init_boost.bzl", "init_boost")
load("//dependency_support/pybind11:init_pybind11.bzl", "init_pybind11")

Expand All @@ -26,26 +27,37 @@ def init(python_interpreter = None, python_interpreter_target = None):
must call `init` to allow @bazel_rules_hdl to set itself up.

`python_interpreter` and `python_interpreter_target` are passed to
@bazel_rules_hdl's instance of `pip_install`. They can normally be set to
@bazel_rules_hdl's instance of `pip_parse`. They can normally be set to
the default None value, but if the outside workspace has a custom Python
toolchain configured, these must be set, otherwise @bazel_rules_hdl will
not use the right Python toolchain when installing pip dependencies.

If either is set, the outside workspace must also include:

load(
"@rules_hdl_pip_deps//:requirements.bzl",
rules_hdl_install_pip_deps = "install_deps",
)
rules_hdl_install_pip_deps()

Args:
python_interpreter: Path to external Python interpreter to use with
`pip_install`. This can be an absolute path or relative to the host's
`pip_parse`. This can be an absolute path or relative to the host's
`PATH` environment variable.
python_interpreter_target: Bazel target of a Python interpreter to build
to use with `pip_install`. Using `python_interpreter_target` makes it
to use with `pip_parse`. Using `python_interpreter_target` makes it
possible to have a hermetic Python toolchain. `python_interpreter_target`
takes precedence over `python_interpreter` if both are set.
"""
pip_install(
# Used only by the rules that vendor requirements.bzl
pip_parse(
name = "rules_hdl_pip_deps",
requirements = "@rules_hdl//dependency_support:pip_requirements.txt",
requirements_lock = "@rules_hdl//dependency_support:pip_requirements.txt",
python_interpreter = python_interpreter,
python_interpreter_target = python_interpreter_target,
)
if (not python_interpreter) or (python_interpreter_target != "@rules_hdl_cpython//:install/bin/python3"):
install_pip_deps()

init_boost()
init_pybind11()
Expand Down
Loading