Skip to content
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
43 changes: 43 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,49 @@ tasks:
- "//..."
test_targets:
- "//..."
extensions_pyo3_linux:
platform: ubuntu2204
name: Extensions PyO3
working_directory: extensions/pyo3
build_flags: *aspects_flags
test_flags: *aspects_flags
build_targets:
- "//..."
test_targets:
- "//..."
extensions_pyo3_linux_rbe:
platform: rbe_ubuntu2204
name: Extensions PyO3
working_directory: extensions/pyo3
shell_commands:
- sed -i 's/^# load("@bazel_ci_rules/load("@bazel_ci_rules/' WORKSPACE.bazel
- sed -i 's/^# rbe_preconfig/rbe_preconfig/' WORKSPACE.bazel
build_flags: *aspects_flags
test_flags: *aspects_flags
build_targets:
- "//..."
test_targets:
- "//..."
extensions_pyo3_macos:
platform: macos_arm64
name: Extensions PyO3
working_directory: extensions/pyo3
build_flags: *aspects_flags
test_flags: *aspects_flags
build_targets:
- "//..."
test_targets:
- "//..."
extensions_pyo3_windows:
platform: windows
name: Extensions PyO3
working_directory: extensions/pyo3
build_flags: *aspects_flags
test_flags: *aspects_flags
build_targets:
- "//..."
test_targets:
- "//..."
extensions_wasm_bindgen_linux:
platform: ubuntu2204
name: Extensions wasm-bindgen
Expand Down
1 change: 1 addition & 0 deletions .bcr/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ moduleRoots:
- "extensions/mdbook"
- "extensions/prost"
- "extensions/protobuf"
- "extensions/pyo3"
- "extensions/wasm_bindgen"
23 changes: 23 additions & 0 deletions .bcr/extensions/pyo3/metadata.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"homepage": "https://github.com/bazelbuild/rules_rust",
"maintainers": [
{
"email": "26427366+UebelAndre@users.noreply.github.com",
"github": "UebelAndre",
"name": "UebelAndre"
},
{
"email": "1131704+illicitonion@users.noreply.github.com",
"github": "illicitonion",
"name": "Daniel Wagner-Hall"
},
{
"email": "11149636+scentini@users.noreply.github.com",
"github": "scentini",
"name": "Rosica Dejanovska"
}
],
"repository": ["github:bazelbuild/rules_rust"],
"versions": [],
"yanked_versions": {}
}
12 changes: 12 additions & 0 deletions .bcr/extensions/pyo3/presubmit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
bcr_test_module:
module_path: ""
matrix:
platform: ["macos_arm64", "ubuntu2004", "windows"]
bazel: ["7.x", "8.x"]
tasks:
run_tests:
name: "Run test module"
platform: ${{ platform }}
bazel: ${{ bazel }}
test_targets:
- "//..."
5 changes: 5 additions & 0 deletions .bcr/extensions/pyo3/source.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"integrity": "**leave this alone**",
"strip_prefix": "extensions/pyo3",
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/{REPO}-{VERSION}.tar.gz"
}
15 changes: 15 additions & 0 deletions .github/release_notes.template
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ http_archive(

```python
bazel_dep(name = "rules_rust_protobuf", version = "{version}")

register_toolchains(
"@rules_rust_pyo3//toolchains:toolchain",
"@rules_rust_pyo3//toolchains:rust_toolchain",
)
```

#### WORKSPACE
Expand All @@ -119,6 +124,16 @@ http_archive(

</details>

### PyO3

<details>

```python
bazel_dep(name = "rules_rust_pyo3", version = "{version}")
```

</details>

### Wasm-Bindgen

<details>
Expand Down
8 changes: 8 additions & 0 deletions docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,13 @@ stardoc(
deps = ["@rules_rust_prost//:bzl_lib"],
)

stardoc(
name = "rust_pyo3",
out = "src/rust_pyo3.md",
input = "@rules_rust_pyo3//:defs.bzl",
deps = ["@rules_rust_pyo3//:bzl_lib"],
)

stardoc(
name = "rust_wasm_bindgen",
out = "src/rust_wasm_bindgen.md",
Expand Down Expand Up @@ -283,6 +290,7 @@ mdbook(
":rust_mdbook",
":rust_prost",
":rust_protobuf",
":rust_pyo3",
":rust_repositories",
":rust_settings",
":rust_toolchains",
Expand Down
6 changes: 6 additions & 0 deletions docs/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ local_path_override(
path = "../extensions/prost",
)

bazel_dep(name = "rules_rust_pyo3", version = "0.0.0")
local_path_override(
module_name = "rules_rust_pyo3",
path = "../extensions/pyo3",
)

bazel_dep(name = "rules_rust_protobuf", version = "0.0.0")
local_path_override(
module_name = "rules_rust_protobuf",
Expand Down
1 change: 1 addition & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
- [mdbook](./rust_mdbook.md)
- [prost](./rust_prost.md)
- [protobuf](./rust_protobuf.md)
- [pyo3](./rust_pyo3.md)
- [wasm_bindgen](./rust_wasm_bindgen.md)
1 change: 1 addition & 0 deletions docs/src/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
- [rust_bindgen](rust_bindgen.md): rules for generating C++ bindings.
- [rust_prost](rust_prost.md): rules for generating [protobuf](https://developers.google.com/protocol-buffers) and [gRPC](https://grpc.io) stubs using [prost](https://github.com/tokio-rs/prost).
- [rust_protobuf](rust_protobuf.md): rules for generating [protobuf](https://developers.google.com/protocol-buffers) and [gRPC](https://grpc.io) stubs with [rust-protobuf](https://github.com/stepancheg/rust-protobuf/)
- [rust_pyo3](rust_pyo3.md): Bazel rules for [PyO3](https://pyo3.rs/v0.23.4/).
- [rust_wasm_bindgen](rust_wasm_bindgen.md): rules for generating [WebAssembly](https://www.rust-lang.org/what/wasm) bindings.
4 changes: 4 additions & 0 deletions extensions/pyo3/.bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bazel-out
bazel-testlogs
bazel-pyo3
bazel-bin
92 changes: 92 additions & 0 deletions extensions/pyo3/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
###############################################################################
## Bazel Configuration Flags
##
## `.bazelrc` is a Bazel configuration file.
## https://bazel.build/docs/best-practices#bazelrc-file
###############################################################################

# https://bazel.build/reference/command-line-reference#flag--enable_platform_specific_config
common --enable_platform_specific_config

# Enable the only currently supported report type
# https://bazel.build/reference/command-line-reference#flag--combined_report
coverage --combined_report=lcov

# Avoid fully cached builds reporting no coverage and failing CI
# https://bazel.build/reference/command-line-reference#flag--experimental_fetch_all_coverage_outputs
coverage --experimental_fetch_all_coverage_outputs

# Disable network access in the sandbox by default.
build --sandbox_default_allow_network=false

# Do not use the host detected python toolchain. Always use one explicitly
# registered in the WORKSPACE.
common --repo_env=BAZEL_DO_NOT_DETECT_PYTHON_TOOLCHAIN=1

# # Enable rustfmt for all targets in the workspace
build --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
build:rustfmt --output_groups=+rustfmt_checks
build:no_rustfmt --output_groups=-rustfmt_checks

# Enable clippy for all targets in the workspace
build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect
build:clippy --output_groups=+clippy_checks
build:no_clippy --output_groups=-clippy_checks

# Enable unpretty for all targets in the workspace
build:unpretty --aspects=@rules_rust//rust:defs.bzl%rust_unpretty_aspect
build:unpretty --output_groups=+rust_unpretty

# `unpretty` requires the nightly toolchain. See tracking issue:
# https://github.com/rust-lang/rust/issues/43364
build:unpretty --config=nightly

# Convenience configs for enabling linting and formatting
build:strict --config=rustfmt
build:strict --config=clippy
build:no_strict --config=no_rustfmt
build:no_strict --config=no_clippy

# When running test enable all linters and formatters
test --config=strict

###############################################################################
## Incompatibility flags
###############################################################################

# https://github.com/bazelbuild/bazel/issues/8195
build --incompatible_disallow_empty_glob=true

# https://github.com/bazelbuild/bazel/issues/12821
build --nolegacy_external_runfiles

# Required for cargo_build_script support before Bazel 7
build --incompatible_merge_fixed_and_default_shell_env

# Disable legacy __init__.py behavior which is known to conflict with
# modern python versions (3.9+)
build --incompatible_default_to_explicit_init_py

###############################################################################
## Bzlmod
###############################################################################

# A configuration for disabling bzlmod.
common:no-bzlmod --noenable_bzlmod --enable_workspace

# Disable the bzlmod lockfile, so we don't accidentally commit MODULE.bazel.lock
common --lockfile_mode=off

# Allow bazel configuration flags to locate the core rules to avoid adding local
# override paths to the `MODULE.bazel` file and breaking downstream consumers.
common --override_module=rules_rust=../../

###############################################################################
## Custom user flags
##
## This should always be the last thing in the `.bazelrc` file to ensure
## consistent behavior when setting flags in that file as `.bazelrc` files are
## evaluated top to bottom.
###############################################################################

try-import %workspace%/user.bazelrc
10 changes: 10 additions & 0 deletions extensions/pyo3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Git ignore patterns

/bazel-*
user.bazelrc

/*venv*/
/.vscode/

/rust-project.json
/target
78 changes: 78 additions & 0 deletions extensions/pyo3/3rdparty/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_vendor")

crates_vendor(
name = "crates_vendor",
annotations = {
"pyo3-build-config": [
crate.annotation(
build_script_data = [
"@rules_rust_pyo3//:current_pyo3_toolchain",
],
build_script_env = {
"PYO3_CROSS": "$(PYO3_CROSS)",
"PYO3_CROSS_LIB_DIR": "$(PYO3_CROSS_LIB_DIR)",
"PYO3_CROSS_PYTHON_IMPLEMENTATION": "$(PYO3_CROSS_PYTHON_IMPLEMENTATION)",
"PYO3_CROSS_PYTHON_VERSION": "$(PYO3_CROSS_PYTHON_VERSION)",
"PYO3_NO_PYTHON": "$(PYO3_NO_PYTHON)",
"PYO3_PYTHON": "$(PYO3_PYTHON)",
},
build_script_toolchains = [
"@rules_rust_pyo3//:current_pyo3_toolchain",
],
patch_args = ["-p1"],
patches = ["@rules_rust_pyo3//3rdparty/patches:resolve_cross_compile_config_path.patch"],
),
],
"pyo3-ffi": [
crate.annotation(
build_script_data = [
"@rules_rust_pyo3//:current_pyo3_toolchain",
],
build_script_env = {
"PYO3_CROSS": "$(PYO3_CROSS)",
"PYO3_CROSS_LIB_DIR": "$(PYO3_CROSS_LIB_DIR)",
"PYO3_CROSS_PYTHON_IMPLEMENTATION": "$(PYO3_CROSS_PYTHON_IMPLEMENTATION)",
"PYO3_CROSS_PYTHON_VERSION": "$(PYO3_CROSS_PYTHON_VERSION)",
"PYO3_NO_PYTHON": "$(PYO3_NO_PYTHON)",
"PYO3_PYTHON": "$(PYO3_PYTHON)",
},
build_script_toolchains = [
"@rules_rust_pyo3//:current_pyo3_toolchain",
],
),
],
},
cargo_lockfile = "Cargo.Bazel.lock",
mode = "remote",
packages = {
"pyo3": crate.spec(
features = [
"abi3",
"abi3-py311",
"extension-module",
"experimental-inspect",
],
version = "0.26.0",
),
"pyo3-ffi": crate.spec(
version = "0.26.0",
),
"pyo3-introspection": crate.spec(
version = "0.26.0",
),
},
# Name is short to avoid windows paths being too long
# https://github.com/bazelbuild/rules_rust/issues/1120
repository_name = "rpyo3c",
tags = ["manual"],
)

bzl_library(
name = "bzl_lib",
srcs = [
"//3rdparty/crates:crates.bzl",
"//3rdparty/crates:defs.bzl",
],
visibility = ["//:__pkg__"],
)
Loading