Skip to content

Commit

Permalink
[bazel] Add bzlmod support for rules_python
Browse files Browse the repository at this point in the history
Signed-off-by: James Wainwright <[email protected]>
  • Loading branch information
jwnrt committed Dec 16, 2024
1 parent dc298ea commit 927278a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
4 changes: 1 addition & 3 deletions rules/bitstreams.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ particular bitstream or use cached version for the next cache entry, for each
design (i.e. mix-and-match).
"""

load("@python3//:defs.bzl", "interpreter")

def _bitstreams_repo_impl(rctx):
# First, check if an existing pre-built bitstream cache repo exists, and if
# so, use it instead of building one.
Expand Down Expand Up @@ -112,7 +110,7 @@ bitstreams_repo = repository_rule(
default = 18 * 3600, # Refresh every 18h
),
"python_interpreter": attr.label(
default = interpreter,
default = "@python3_host//:python",
allow_single_file = True,
doc = "Python interpreter to use.",
),
Expand Down
3 changes: 1 addition & 2 deletions rules/repo/bare_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

load("@python3//:defs.bzl", "interpreter")
load("@bazel_skylib//lib:paths.bzl", "paths")

def _bare_repository_impl(rctx):
Expand Down Expand Up @@ -47,7 +46,7 @@ bare_repository = repository_rule(
doc = "Additional files to place in the repository (mapping repo filename to strings).",
),
"python_interpreter": attr.label(
default = interpreter,
default = "@python3_host//:python",
allow_single_file = True,
doc = "Python interpreter to use.",
),
Expand Down
3 changes: 1 addition & 2 deletions third_party/python/pip.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
# SPDX-License-Identifier: Apache-2.0

load("@rules_python//python:pip.bzl", "pip_parse")
load("@python3//:defs.bzl", "interpreter")

def pip_deps():
pip_parse(
name = "ot_python_deps",
python_interpreter_target = interpreter,
python_interpreter_target = "@python3_host//:python",
requirements_lock = "@lowrisc_opentitan//:python-requirements.txt",
)
31 changes: 31 additions & 0 deletions third_party/python/python.MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright lowRISC contributors (OpenTitan project).
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

# Dependencies:
bazel_dep(name = "rules_python", version = "0.39.0")

# Python toolchain:
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
# Required because CI containers currently run as the `root` user.
# We lose caching of `.pyc` files as a result.
# See <https://github.com/bazelbuild/rules_python/pull/713>.
ignore_root_user_error = True,
is_default = True,
python_version = "3.9",
)
use_repo(python, "pythons_hub")
register_toolchains("@pythons_hub//:all")

# We occasionally access the toolchain repositories directly to use interpreters.
use_repo(python, python3 = "python_3_9", python3_host = "python_3_9_host")

# Pip dependencies:
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
hub_name = "ot_python_deps",
python_version = "3.9",
requirements_lock = "//:python-requirements.txt",
)
use_repo(pip, "ot_python_deps")

0 comments on commit 927278a

Please sign in to comment.