Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
480 changes: 284 additions & 196 deletions .bazelci/presubmit.yml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.direnv
bzlmod
crate_universe/private/bootstrap
crate_universe/tests/integration
docs
examples
extensions
Expand Down
12 changes: 6 additions & 6 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
**/cargo-bazel-lock.json linguist-generated
crate_universe/3rdparty/crates/** linguist-generated
crate_universe/test_data/metadata/*/metadata.json linguist-generated
examples/hello_world/third-party/crates/** linguist-generated
crate_universe/tests/integration/vendor/3rdparty/crates/** linguist-generated
crate_universe/tests/integration/vendor/local_manifests/crates/** linguist-generated
crate_universe/tests/integration/vendor/local_pkgs/crates/** linguist-generated
crate_universe/tests/integration/vendor/remote_manifests/crates/** linguist-generated
crate_universe/tests/integration/vendor/remote_pkgs/crates/** linguist-generated
examples/crate_universe_unnamed/vendor_remote_manifests/crates/** linguist-generated
examples/crate_universe_unnamed/vendor_remote_pkgs/crates/** linguist-generated
examples/crate_universe/vendor_external/crates/** linguist-generated
examples/crate_universe/vendor_local_manifests/crates/** linguist-generated
examples/crate_universe/vendor_local_pkgs/crates/** linguist-generated
examples/crate_universe/vendor_remote_manifests/crates/** linguist-generated
examples/crate_universe/vendor_remote_pkgs/crates/** linguist-generated
examples/hello_world/third-party/crates/** linguist-generated
examples/sys/basic/3rdparty/crates/** linguist-generated
examples/sys/complex/3rdparty/crates/** linguist-generated
extensions/bindgen/3rdparty/crates/** linguist-generated
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
/bzlmod/hello_world/bazel-*
/examples/bazel-*
/examples/cargo_manifest_dir/external_crate/bazel-*
/examples/crate_universe/bazel-*
/examples/crate_universe/*/bazel-*
/crate_universe/tests/integration/*/bazel-*
/crate_universe/tests/integration/vendor/*/bazel-*
/test/cc_common_link/bazel-*
/test/cc_common_link/with_global_alloc/bazel-*
/test/no_std/bazel-*
Expand Down
6 changes: 3 additions & 3 deletions crate_universe/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ call above or [crates_repository::generator_urls](#crates_repository-generator_u

The [`crates_repository`](#crates_repository) rule (the primary repository rule of `rules_rust`'s cargo support) supports a number of different
ways users can express and organize their dependencies. The most common are listed below though there are more to be found in
the [./examples/crate_universe](https://github.com/bazelbuild/rules_rust/tree/main/examples/crate_universe) directory.
the [crate_universe/tests/integration](https://github.com/bazelbuild/rules_rust/tree/main/crate_universe/tests/integration) directory.

### Cargo Workspaces

Expand Down Expand Up @@ -272,15 +272,15 @@ Some build scripts can be made to work by pulling in some extra files and making

Commonly this is done by passing the file to the `build_script_data` annotation for the crate, and using `build_script_env` to tell the build script where the file is. That env var may often use `$(execroot)` to get the path to the label, or `$${pwd}/` as a prefix if the path given is relative to the execroot (as will frequently happen when using a toolchain).A

There is an example of this in the "complicated dependencies" section of https://github.com/bazelbuild/rules_rust/blob/main/examples/crate_universe/WORKSPACE.bazel which builds boring-sys.
There is an example of this in the complicated_dependencies integration test at https://github.com/bazelbuild/rules_rust/tree/main/crate_universe/tests/integration/complicated_dependencies which builds boring-sys.

### Building with Bazel and supplying via an override

Some build scripts have hooks to allow replacing parts that are complicated to build with output prepared by Bazel.

We can use those hooks by specifying paths (generally using the `build_script_data` and `build_script_env` annotations) and pointing them at labels which Bazel will then build. These env vars may often use `$(execroot)` to get the path to the label, or `$${pwd}/` as a prefix if the path given is relative to the execroot (as will frequently happen when using a toolchain).

There is an example of this in the "complicated dependencies" section of https://github.com/bazelbuild/rules_rust/blob/main/examples/crate_universe/WORKSPACE.bazel which builds boring-sys.
There is an example of this in the complicated_dependencies integration test at https://github.com/bazelbuild/rules_rust/tree/main/crate_universe/tests/integration/complicated_dependencies which builds boring-sys.

---

Expand Down
2 changes: 1 addition & 1 deletion crate_universe/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ We don't have such easy facilities available in bazel besides specifying it as a
To mimic cargo's bindeps feature we use the unstable feature called [artifact-dependencies](https://doc.rust-lang.org/nightly/cargo/reference/unstable.html?highlight=feature#artifact-dependencies)
which integrates well with bazel concepts.

You could use the syntax specified in the above document to place it in `Cargo.toml`. For that you can consult the following [example](https://github.com/bazelbuild/rules_rust/blob/main/examples/crate_universe/MODULE.bazel#L279-L291).
You could use the syntax specified in the above document to place it in `Cargo.toml`. For that you can consult the following [example](https://github.com/bazelbuild/rules_rust/blob/main/crate_universe/tests/integration/cargo_bindeps/MODULE.bazel).

This method has the following consequences:
* if you use shared dependency tree with your project these binary dependencies will interfere with yours (may conflict)
Expand Down
2 changes: 1 addition & 1 deletion crate_universe/test_data/cargo_bazel_lockfile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## `multi_package-cargo-bazel-lock.json`

This was copied from `examples/crate_universe/multi_package/cargo-bazel-lock.json` at commit 53daac71c0755680c29f4c55ac5238cc063e8b31.
This was copied from `crate_universe/tests/integration/multi_package/cargo-bazel-lock.json` at commit 53daac71c0755680c29f4c55ac5238cc063e8b31.

It's intended to be an example of a realistic and meaningfully complex lockfile.

Expand Down
201 changes: 201 additions & 0 deletions crate_universe/tests/integration/alias_rule/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
module(
name = "cu_test_alias_rule",
version = "0.0.0",
)

bazel_dep(name = "rules_rust", version = "0.0.0")
local_path_override(
module_name = "rules_rust",
path = "../../../..",
)

rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
use_repo(rust, "rust_toolchains")

register_toolchains("@rust_toolchains//:all")

alias_rule_global_alias_annotation_none = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
alias_rule_global_alias_annotation_none.annotation(
alias_rule = "",
crate = "test_data_passing_crate",
repositories = ["alias_rule_global_alias_annotation_none"],
)
alias_rule_global_alias_annotation_none.render_config(
default_alias_rule_name = "alias",
repositories = ["alias_rule_global_alias_annotation_none"],
)
alias_rule_global_alias_annotation_none.spec(
package = "test_data_passing_crate",
repositories = ["alias_rule_global_alias_annotation_none"],
version = "0.1.0",
)
alias_rule_global_alias_annotation_none.from_specs(
name = "alias_rule_global_alias_annotation_none",
cargo_lockfile = "//:Cargo.lock",
lockfile = "//:cargo-bazel-lock_global_alias_annotation_none.json",
)
use_repo(
alias_rule_global_alias_annotation_none,
"alias_rule_global_alias_annotation_none",
)

alias_rule_global_alias_annotation_opt = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
alias_rule_global_alias_annotation_opt.annotation(
alias_rule = "opt",
crate = "test_data_passing_crate",
repositories = ["alias_rule_global_alias_annotation_opt"],
)
alias_rule_global_alias_annotation_opt.spec(
package = "test_data_passing_crate",
repositories = ["alias_rule_global_alias_annotation_opt"],
version = "0.1.0",
)
alias_rule_global_alias_annotation_opt.render_config(
default_alias_rule_name = "alias",
repositories = ["alias_rule_global_alias_annotation_opt"],
)
alias_rule_global_alias_annotation_opt.from_specs(
name = "alias_rule_global_alias_annotation_opt",
cargo_lockfile = "//:Cargo.lock",
lockfile = "//:cargo-bazel-lock_global_alias_annotation_opt.json",
)
use_repo(
alias_rule_global_alias_annotation_opt,
"alias_rule_global_alias_annotation_opt",
)

alias_rule_global_opt_annotation_none = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
alias_rule_global_opt_annotation_none.annotation(
alias_rule = "",
crate = "test_data_passing_crate",
repositories = ["alias_rule_global_opt_annotation_none"],
)
alias_rule_global_opt_annotation_none.spec(
package = "test_data_passing_crate",
repositories = ["alias_rule_global_opt_annotation_none"],
version = "0.1.0",
)
alias_rule_global_opt_annotation_none.render_config(
default_alias_rule_name = "opt",
repositories = ["alias_rule_global_opt_annotation_none"],
)
alias_rule_global_opt_annotation_none.from_specs(
name = "alias_rule_global_opt_annotation_none",
cargo_lockfile = "//:Cargo.lock",
lockfile = "//:cargo-bazel-lock_global_opt_annotation_none.json",
)
use_repo(
alias_rule_global_opt_annotation_none,
"alias_rule_global_opt_annotation_none",
)

alias_rule_global_opt_annotation_alias = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
alias_rule_global_opt_annotation_alias.annotation(
alias_rule = "alias",
crate = "test_data_passing_crate",
repositories = ["alias_rule_global_opt_annotation_alias"],
)
alias_rule_global_opt_annotation_alias.spec(
package = "test_data_passing_crate",
repositories = ["alias_rule_global_opt_annotation_alias"],
version = "0.1.0",
)
alias_rule_global_opt_annotation_alias.render_config(
default_alias_rule_name = "opt",
repositories = ["alias_rule_global_opt_annotation_alias"],
)
alias_rule_global_opt_annotation_alias.from_specs(
name = "alias_rule_global_opt_annotation_alias",
cargo_lockfile = "//:Cargo.lock",
lockfile = "//:cargo-bazel-lock_global_opt_annotation_alias.json",
)
use_repo(
alias_rule_global_opt_annotation_alias,
"alias_rule_global_opt_annotation_alias",
)

alias_rule_global_opt_annotation_dbg = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
alias_rule_global_opt_annotation_dbg.annotation(
alias_rule = "dbg",
crate = "test_data_passing_crate",
repositories = ["alias_rule_global_opt_annotation_dbg"],
)
alias_rule_global_opt_annotation_dbg.spec(
package = "test_data_passing_crate",
repositories = ["alias_rule_global_opt_annotation_dbg"],
version = "0.1.0",
)
alias_rule_global_opt_annotation_dbg.spec(
package = "test_data_passing_crate",
repositories = ["alias_rule_global_opt_annotation_dbg"],
version = "0.1.0",
)
alias_rule_global_opt_annotation_dbg.render_config(
default_alias_rule_name = "opt",
repositories = ["alias_rule_global_opt_annotation_dbg"],
)
alias_rule_global_opt_annotation_dbg.from_specs(
name = "alias_rule_global_opt_annotation_dbg",
cargo_lockfile = "//:Cargo.lock",
lockfile = "//:cargo-bazel-lock_global_opt_annotation_dbg.json",
)
use_repo(
alias_rule_global_opt_annotation_dbg,
"alias_rule_global_opt_annotation_dbg",
)

alias_rule_global_dbg_annotation_fastbuild = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
alias_rule_global_dbg_annotation_fastbuild.annotation(
alias_rule = "fastbuild",
crate = "test_data_passing_crate",
repositories = ["alias_rule_global_dbg_annotation_fastbuild"],
)
alias_rule_global_dbg_annotation_fastbuild.spec(
package = "test_data_passing_crate",
repositories = ["alias_rule_global_dbg_annotation_fastbuild"],
version = "0.1.0",
)
alias_rule_global_dbg_annotation_fastbuild.spec(
package = "test_data_passing_crate",
repositories = ["alias_rule_global_dbg_annotation_fastbuild"],
version = "0.1.0",
)
alias_rule_global_dbg_annotation_fastbuild.render_config(
default_alias_rule_name = "dbg",
repositories = ["alias_rule_global_dbg_annotation_fastbuild"],
)
alias_rule_global_dbg_annotation_fastbuild.from_specs(
name = "alias_rule_global_dbg_annotation_fastbuild",
cargo_lockfile = "//:Cargo.lock",
lockfile = "//:cargo-bazel-lock_global_dbg_annotation_fastbuild.json",
)
use_repo(
alias_rule_global_dbg_annotation_fastbuild,
"alias_rule_global_dbg_annotation_fastbuild",
)

alias_rule_global_custom_annotation_none = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
alias_rule_global_custom_annotation_none.annotation(
alias_rule = "",
crate = "test_data_passing_crate",
repositories = ["alias_rule_global_custom_annotation_none"],
)
alias_rule_global_custom_annotation_none.spec(
package = "test_data_passing_crate",
repositories = ["alias_rule_global_custom_annotation_none"],
version = "0.1.0",
)
alias_rule_global_custom_annotation_none.render_config(
default_alias_rule_bzl = "//:alias_rules.bzl",
default_alias_rule_name = "alias_rule",
repositories = ["alias_rule_global_custom_annotation_none"],
)
alias_rule_global_custom_annotation_none.from_specs(
name = "alias_rule_global_custom_annotation_none",
cargo_lockfile = "//:Cargo.lock",
lockfile = "//:cargo-bazel-lock_global_custom_annotation_none.json",
)
use_repo(
alias_rule_global_custom_annotation_none,
"alias_rule_global_custom_annotation_none",
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "6033174055cf5b1786c366022933666de9b4fb9f0f9c6de37a2a5b9979e14637",
"checksum": "eb457701cf165e124b2df57e7fe464b61b2d0fbda73347c056e03bc2a54cedbc",
"crates": {
"direct-cargo-bazel-deps 0.0.1": {
"name": "direct-cargo-bazel-deps",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "01f20c8f5c6c20ea63cc953b65a51175cb08a04ad410762806978fd8aaef3abb",
"checksum": "ac6fb5b695b7657125755697ae6187985d70f06bf7ea065956c4d83eca4dd57b",
"crates": {
"direct-cargo-bazel-deps 0.0.1": {
"name": "direct-cargo-bazel-deps",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "610a59c0920b67655a3fabc86ffbd830c73c1657e28c867dd3a92cfbce32a591",
"checksum": "dce0208c8faca2b652d3814570d6a77c5f2eae97272c6b5d1af25afbc53d3533",
"crates": {
"direct-cargo-bazel-deps 0.0.1": {
"name": "direct-cargo-bazel-deps",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "af3df28047e66fcc801b254dbb32f27d81910a457b268c438125c2b748654f15",
"checksum": "c4191e7837ed195a24e7ab3fb694f7e3ce4968a5411488a2fed51edcbaf78721",
"crates": {
"direct-cargo-bazel-deps 0.0.1": {
"name": "direct-cargo-bazel-deps",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "a691c31bb7444340c5172d90ca442041633eaff22e2d3abd23c7586655512228",
"checksum": "52e944acd8b1c373924564eac8d4468fd765f0ad7b28ebe0dd177f881f8be32f",
"crates": {
"direct-cargo-bazel-deps 0.0.1": {
"name": "direct-cargo-bazel-deps",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "0e20b36220f7877a204cd154e66e494bb8dc2072bb17e342b5cd30cf4bf52e8e",
"checksum": "1a1a7502dc5f893053769b53b759ff8e5670f4aa60c02cbb3d7fa13846f98ed6",
"crates": {
"direct-cargo-bazel-deps 0.0.1": {
"name": "direct-cargo-bazel-deps",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "2aa7359d90b03382508448ed162acfe21de46562be731d6f21ad5c92d3718934",
"checksum": "48ddb86418d9571663f03c92dd2187b477ed6da06f99c94db950b60255fef44a",
"crates": {
"direct-cargo-bazel-deps 0.0.1": {
"name": "direct-cargo-bazel-deps",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,6 @@
## 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

# Required for some of the tests
# https://bazel.build/reference/command-line-reference#flag--experimental_cc_shared_library
common --experimental_cc_shared_library

###############################################################################
## Unique configuration groups
###############################################################################

# Enable use of the nightly toolchains.
build:nightly --@rules_rust//rust/toolchain/channel=nightly

# Enable rustfmt for all targets in the workspace
build:rustfmt --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
build:rustfmt --output_groups=+rustfmt_checks
Expand All @@ -35,14 +13,6 @@ build:rustfmt --output_groups=+rustfmt_checks
build:clippy --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect
build: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

###############################################################################
## Incompatibility flags
###############################################################################
Expand All @@ -56,6 +26,9 @@ build --nolegacy_external_runfiles
# https://github.com/bazelbuild/bazel/issues/23043.
build --incompatible_autoload_externally=

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

###############################################################################
## Bzlmod
###############################################################################
Expand Down
Loading
Loading