Commit Graph

1687 Commits

Author SHA1 Message Date
Daniel Wagner-Hall 813669bc2e
Add version to bindgen dep (#2768)
I don't know how this ever worked before. I've picked the version that
happens to be in the lockfile at the moment.

Fixes #2752
2024-07-30 20:41:18 +00:00
Duarte Nunes b5ecaea4b5
Respect "--no-typescript" flag in wasm_bindgen (#2765)
Don't expect typescript outputs if this flag is set.

---------

Co-authored-by: Daniel Wagner-Hall <dawagner@gmail.com>
2024-07-29 22:05:24 +00:00
Amelia f0276ea585
Allow for unnamed workspaces/modules when using crates_vendor (#2730)
Addresses https://github.com/bazelbuild/rules_rust/issues/2661

If the workspace name is empty, the crate_module_template will use a
label like `Label(//<stuff>)` instead of `Label(@//<stuff>)`

Most of the changes in this are just regenerating the vendor'ed crates
in the examples. I ran the tests in all the relevant examples to ensure
they still worked.
2024-07-29 15:22:11 +00:00
Krasimir Georgiev e7fe164839
toolchain: support `$(location)` expansion in `extra_rustc_flags` (#2761)
This is similar to our `$(location)` expansion support for
`stdlib_linkflags`. We found ourselves needing this when defining a
custom rust dfsan-enabled toolchain. There, rustc needs an extra
`-Zsanitizer-dataflow-abilist=/path/to/abilist.txt` flag.

This patch lets us do this by specifying the abilist file in
`rust_stdlib_filegroup.srcs` and passing it as
`rust_toolchain.extra_rustc_flags =
["-Zsanitizer-dataflow-abilist=$(location :dfsan_abilist)"]`.

While looking into this, I noticed and fixed an issue: the sources of
the `rust_stdlib_filegroup` passed to `rust_toolchain.rust_std` weren't
made available downstream to the compile actions. I believe location
expansion was working before for `stdlib_linkflags` just because the
targets used in this location expansion were made available indirectly
e.g., implicitly by the underlying C++ toolchain, or via `rustc_lib`.
2024-07-29 14:51:53 +00:00
UebelAndre ad615c702c
Added Rust 1.80.0 (#2763)
https://blog.rust-lang.org/2024/07/25/Rust-1.80.0.html
2024-07-29 14:45:19 +00:00
Daniel Wagner-Hall d1e84e3b03
Add missing local_path_overrides in examples (#2747)
Otherwise these test a released rules_rust not an in-repo one, and
breaking changes will always fail CI.
2024-07-29 10:05:32 +00:00
Krasimir Georgiev 64a4b529a1
rust_stdlib_filegroup: update to support srcs from another package (#2735)
The `rust_stdlib_filegroup` rule would sometimes break when passing
`.rlib`-s originating from another package to `srcs`.
The root cause is the logic inside it that creates `.a` -> `.rlib`
symlinks, where the `.a` symlink is declared sibling of the `.rlib`.
Bazel only allows symlink siblings to be in the same package as the
rule.

This updates the logic to detect this and create an intermediary `.rlib`
under the rule's package, allowing the `.a` to be symlinked to that.

---------

Co-authored-by: scentini <rosica@google.com>
2024-07-23 13:11:56 +00:00
Steve Barrau 4a530aa5d9
feat(crates_repository): customizable repin instructions (#2756)
Add customizable instructions to re-pin the repository if required. Many
people have wrapper scripts for keeping dependencies up to date, and
would like to point users to that instead of the default.

This follows the logic of
https://github.com/bazelbuild/rules_jvm_external/pull/1000

---------

Co-authored-by: Daniel Wagner-Hall <dawagner@gmail.com>
2024-07-22 20:43:27 +00:00
Daniel Wagner-Hall 6b10ce3e39
Release 0.48.0 (#2750) 2024-07-19 12:57:10 +00:00
Daniel Wagner-Hall ffe8eff049
Support incompatible enable proto toolchain resolution (#2741)
This allows using a shared (generally pre-built) protoc definition,
rather than needing to supply one via a label.

We allow (but deprecate) users to still bring along their own protoc as
a label, but if they want to do so, they will need to ensure they have
the correct repositories registered in order to build/bring their
protoc, rather than us setting them up by default.
2024-07-19 08:10:10 +00:00
Milan Vukov ca7a3df6d2
Fix collecting cc deps in collect_deps (#2699)
In my repo https://github.com/mvukov/rules_ros2/pull/316 I have a
use-case that I want to pass some cc-deps via dep_variant_info as in
https://github.com/mvukov/rules_ros2/pull/316/files#diff-58917867447a8263989afcfff01c87ad154b41562efc3f6d789807efb26e298fR231-R253.
This PR enables that.
2024-07-18 09:48:04 +00:00
Marcel Hlopko 6a140b21a8
Make rustfmt toolchain optional in bindgen (#2744) 2024-07-17 14:00:46 +00:00
Marcel Hlopko 147886f6db
Make it possible to not specify clang binary in bindgen (#2746)
Co-authored-by: Krasimir Georgiev <krasimir@google.com>
2024-07-17 13:10:55 +00:00
Marcel Hlopko db89d83ce5
Pass toolchain param in ctx.action.run in bindgen (#2745) 2024-07-17 12:43:38 +00:00
Marcel Hlopko 6c2bd67af0
Add support for --wrap-extern-fns to bindgen rules (#2743) 2024-07-16 07:42:40 +00:00
Marvin Hansen c177ccc1a7
Bazelmod documentation and code examples. (#2713)
This PR provides documentation of Bazelmod and several code examples
that addresses a number of issues related to Bazelmod.

Preview of the documentation:
https://github.com/marvin-hansen/rules_rust/blob/main/docs/crate_universe_bzlmod.md

First and foremost it paves the way for a meaningful update the Bazelmod
documentation that references these and existing code examples. This
touches at least the following issues:
* #2670
* #2181


The compile_opt example addresses or resolves:
*  #515
* #2701

The musl_cross_compilling example addresses or resolves
* #390 
* #276

The oci_container does not relate to any open issue, 
although the tokio example in it gives a nice end to end example so 
this definitely helps those looking for something non-trivial.

The proto example addresses or resolves:
*  #2668
*  #302
* #2534
* Possibly a few more if I were to search longer

Formalities
* I've signed the CLA
* I've signed all commits

---------

Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
Co-authored-by: Daniel Wagner-Hall <dawagner@gmail.com>
2024-07-12 12:31:00 +00:00
Ivan Carvalho b3fe74cc97
Add support for shared test-only modules (#2734)
Currently, `rust_test_suite` is not capable of supporting integration
tests with shared modules. A very basic example is:
```
[crate]/
    src/
        lib.rs
    tests/
        integration_test_a.rs
        integration_test_b.rs
        util/
            mod.rs
```
With `integration_test_a.rs` and `integration_test_b.rs` importing code
from `util`.

This PR adds a `shared_srcs` argument to `rust_test_suite`. That way, we
can finally compile and run those tests with:
```python
rust_test_suite(
    name = "integrated_tests_suite",
    srcs = glob(["tests/**"]),
    shared_srcs = ["tests/util/mod.rs"],
    deps = [":example_dep"],
)
```
2024-07-10 14:02:35 +00:00
Oliver Graff 6080e4985d
Use newer macos runners (#2732) 2024-07-09 03:16:33 +00:00
Marcel Hlopko 116f6db8fa
Update bindgen.bzl to use toolchain system include directories as well (#2727)
This is needed when using toolchains that use custom include
directories.
2024-07-08 09:06:59 +00:00
UebelAndre a5fd6951c9
Release 0.47.0 (#2725) 2024-07-04 16:12:30 +00:00
matt-duch 4110601dcd
crate-universe allows workspaces with MODULE.bazel only (#2720)
According to the [migration
guide](https://bazel.build/external/migration), `WORKSPACE.bazel` is no
longer required with Bazel 6.3 or later. This updates `crate_universe`
to respect that, allowing `MODULE.bazel` to be the root marker of a
workspace, without requiring a `WORKSPACE` or `WORKSPACE.bazel`.

Happy to iterate on this.
2024-07-04 15:37:29 +00:00
UebelAndre 3877078566
Updated rust-analyzer to use repo vs generated files as crate roots (#2717)
This change updates the `rust_analyzer_aspect` to attempt to match
generated crate root sources to `srcs` inputs and use the the path of
the source file in place of the generated path. The generated path is
then added to `sources.include_dirs` for compatibility. The impact of
this can be seen in the following diff of the
`@rules_rust//:rust-project.json` file:
```diff
--- rust-project.old.json	2024-06-28 09:00:51
+++ rust-project.json	2024-06-28 09:04:43
@@ -821,10 +821,16 @@
         },
         {
             "display_name": "libgensrc_with_crate_root",
-            "root_module": "/private/var/tmp/_bazel_user/76282c66b0dfe3c5cb9a230bdc913a52/execroot/rules_rust/bazel-out/darwin_arm64-fastbuild/bin/test/generated_inputs/lib.rs",
+            "root_module": "test/generated_inputs/lib.rs",
             "edition": "2018",
             "deps": [],
             "is_workspace_member": true,
+            "source": {
+                "include_dirs": [
+                    "/private/var/tmp/_bazel_user/76282c66b0dfe3c5cb9a230bdc913a52/execroot/rules_rust/bazel-out/darwin_arm64-fastbuild/bin/test/generated_inputs"
+                ],
+                "exclude_dirs": []
+            },
             "cfg": [
                 "test",
                 "debug_assertions"
@@ -850,10 +856,16 @@
...
...
...
```

closes https://github.com/bazelbuild/rules_rust/issues/2716
2024-07-04 15:35:09 +00:00
Oliver Graff 2a0698fb65
Clean up downloads that go through the API instead of the CDN (#2718)
This is useful as it seems crates.io is starting to deny some direct
requests, not sure if its based off user agent or remote how IP.
2024-06-29 13:37:23 +00:00
Peter Kolloch c1ab10aaad
upstream wrappers for cargo, rustc, cargo-clippy (#2703)
...and a bazel_env example.

As discussed in
https://bazelbuild.slack.com/archives/CSV56UT0F/p1718207171652029?thread_ts=1718182474.631279&cid=CSV56UT0F
2024-06-25 11:34:39 +00:00
Alex Kirszenberg c888ebdd9a
Update wasm-bindgen to 0.2.92 (#2714) 2024-06-24 20:33:21 +00:00
UebelAndre c2014b6e3c
Updated external dependencies docs (#2711) 2024-06-24 19:50:46 +00:00
Daniel Wagner-Hall c014c618f9
crate_universe docs: Split bzlmod from workspace (#2700)
Previously the bzlmod symbols were not documented at all, and in places
they are different from the WORKSPACE versions.

This at least hosts both.

Fixes #2696
2024-06-21 14:51:12 +00:00
Daniel Wagner-Hall 4ea03d6fd0
rust-analyzer: Factor aliases into the project (#2709)
Fixes #2707
2024-06-20 15:47:56 +00:00
Nicolas Mattia 78c68d60d9
Apply extra_rustc_flags list to all toolchains (#2693)
Fixes #2692 

This fixes `rust_register_toolchains` to correctly call
`rust_toolchain_repository` with a list of `extra_rustc_flags`.

Previously, the `extra_rustc_flags` argument of
`rust_register_toolchains` was assumed (when set) to be a dict of
toolchain triple to list. With this change, a `list` parameter is used
for all toolchain triples.

Co-authored-by: UebelAndre <github@uebelandre.com>
2024-06-14 13:23:55 +00:00
Daniel Wagner-Hall bb73b64e29
Add example of using JNI to call into Rust (#2690) 2024-06-14 08:46:12 +00:00
Cornelius Riemenschneider d0b0553aab
`crate_universe`: Make module extension restarts less expensive. (#2691)
This PR reduces the number of expensive module extension implementation
restarts in combination with multiple `from_cargo` configurations.

As each configuration processing calls `module_ctx.path` (which can and
will cause restarts), we executed _generate_hub_and_spokes (i.e.
`cargo-bazel`) _a lot_ and then threw that away on the next restart.
Triggering `module_ctx.path` early is therefore a significant
performance optimization.

On our repository, this gives us a 10sec speedup on module extension
processing (local M1 mac, nothing happening in parallel), see our
[MODULE.bazel](https://github.com/github/codeql/blob/main/MODULE.bazel)
if you're interested in what we're doing.

This excessive restarting also exposed an upstream bazel bug on Windows
2019, where bazel spuriously fails to clean up the working directory
(c.f. https://github.com/bazelbuild/bazel/issues/22710).

Co-authored-by: Daniel Wagner-Hall <dwagnerhall@apple.com>
2024-06-14 08:45:12 +00:00
UebelAndre 67b3571d7e
Added Rust 1.79.0 (#2695)
https://blog.rust-lang.org/2024/06/13/Rust-1.79.0.html
2024-06-13 17:03:32 +00:00
UebelAndre d83c86581c
Add flag to refer to a `sh_toolchain` for process wrapper bootstrap shebangs (#2694)
This introduces the flag
`--@rules_rust//rust/settings:experimental_use_sh_toolchain_for_bootstrap_process_wrapper`
which can be used to embed the shell path from
`@bazel_tools//tools/sh:toolchain_type` in the rustc bootstrap process
wrapper.
2024-06-13 16:37:40 +00:00
Daniel Wagner-Hall 9c672947a1
Remote vendor doesn't require srcs present (#2688)
Before this, if we re-generate all of the BUILD.bazel files for our
vendored deps, they are invalid because they only have BUILD.bazel files
and the globs present in them expect srcs.

First two commits are real changes, third commit is just a repin.
2024-06-13 16:13:39 +00:00
Daniel Wagner-Hall a6529a7014
Release 0.46.0 (#2686) 2024-06-10 12:51:27 +00:00
Amelia bbbeb681d9
Add support for override_target when using bzlmod (#2683)
The ability to override crate targets when using crate_universe was
added here: https://github.com/bazelbuild/rules_rust/pull/2674

However, this change did not expose that functionality when using
bzlmod.

This change adds that functionality in. Because of the limited set of
options we have for dictionaries in tag classes, I had to split out
"override_targets" into four different options, each taking a Label.

I have added in an example based on the example given in #2674 , but
using bzlmod instead. I have also tested that example and found it to be
working.
2024-06-10 10:28:18 +00:00
Pieter Agten ada2e524a9
[Bugfix] Convert metadata keys to screaming snake case instead of screaming kebab case in `cargo_build_script_runner` (#2682)
The `cargo_build_script_runner` currently converts the keys from
`cargo:KEY=VALUE` metadata build script output lines into uppercase.
This is not completely correct, however, because Cargo converts those
keys to uppercase AND replaces dashes with underscores (effectively
doing a conversion to SCREAMING_SNAKE_CASE).

To verify that Cargo is indeed doing the dash-to-underscore conversion,
have a look at
10b7d38435/src/cargo/core/compiler/custom_build.rs (L46),
which is the code responsible for building the
`DEP_{crate-name}_{metadata-key}` env variables in Cargo. The code is
```rust
cmd.env(
    &format!("DEP_{}_{}", super::envify(&name), super::envify(key)),
    value,
);
```
where `super::envify()` is defined as
```rust
fn envify(s: &str) -> String {
    s.chars()
        .flat_map(|c| c.to_uppercase())
        .map(|c| if c == '-' { '_' } else { c })
        .collect()
}
```

This PR adds the dash-to-underscore conversion to
`cargo_build_script_runner`.
2024-06-07 15:23:46 +00:00
Ed Schouten 837b7f892a
Depend on a copy of rustfmt for the target (#2685)
The toolchain_files() and current_rust_toolchain() rules return files
for the current 'exec' platform. This is perfecly reasonable if you want
to use these tools as part of ctx.actions.run(). But if you want to use
these as part of 'data = []' (runfiles), they must be built for the
target.

Fixes: https://github.com/bazelbuild/rules_rust/issues/2684
2024-06-07 14:54:21 +00:00
Oliver Graff 33f93ace38
Allow overriding crate universe packages to local packages (#2674)
Allow external crates to be aliased to local targets

In some cases it may be desirable to alias a public crate to a locally
define rust_library target, even for dependencies of crates that are not
being overriden.
Support this use case by swapping out `alias` for `rust_library` when
a user overrides the target using an annotation.

---------

Co-authored-by: Daniel Wagner-Hall <dwagnerhall@apple.com>
2024-06-06 16:55:07 +00:00
Matt e3a77c4dfb
Ensure that running `bazel build` on a cargo_build_script target actually runs the build script (#2680)
Co-authored-by: Daniel Wagner-Hall <dwagnerhall@apple.com>
2024-06-06 10:47:46 +00:00
Matthieu MOREL 7f2b47cb3e
use bazel_ci_rules bazel_dep instead of http_archive (#2678)
bazel_ci_rules@1.0.0 module has been published to the BCR, see
https://github.com/bazelbuild/bazel-central-registry/pull/2058

This use it has a bazel_dep instead of a http_archive

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2024-06-06 10:28:40 +00:00
Ed Schouten 9d34479407
Ensure dynamic library dependencies end up in the runfiles directory (#2671)
Right now the runfiles directory only contains "data" that is attached
to a rust_binary() or one of its dependencies. This is inconsistent with
cc_binary() and go_binary(), which also include an `_solib_*/` directory
containing shared library dependencies.

When doing a plain 'bazel run' against the resulting executable, this is
not a noticeable issue. The reason being that the runtime dynamic linker
will use `${execroot}/_solib_*`. However, it does become a problem when
`pkg_tar(include_runfiles = True)` is used to construct an archive of
the binary so that it can be placed in a container image.

This change extends the runfiles gathering logic to merge all
LibraryToLink.dynamic_library files in there as well.
2024-06-05 12:20:27 +00:00
Cornelius Riemenschneider e3f6258b1e
crate_universe: Don't include crate name in build script path. (#2663)
This PR shortens the path to the build script (potentially
significantly), which helps with long-path issues on Windows.
This change is motivated by the crate `tree-sitter-embedded-template`,
which has a too long path to the compiled build script otherwise, and
which then fails to build on Windows in a `bzlmod` setting.
Fixes https://github.com/bazelbuild/rules_rust/issues/2520.

The cargo build script name was used to automatically derive the cargo
package name, this now went into a separate override parameter that is
generated by the crate-universe tooling.
There's never two build scripts in a single crate, so I don't see how
having a single build script target with a single name would be a
problem.
2024-06-03 13:09:39 +00:00
Matt a92de54fcd
Fix cargo_build_script executables. (#2675)
This allows it to work with new-style toolchains that use action configs
(see https://github.com/bazelbuild/bazel/issues/22561).

It also allows you to specify a seperate C compiler and C++ compiler.
2024-06-03 13:00:26 +00:00
Matt 0c5e67c908
Fix protobuf generated srcs to include all sources (#2676) 2024-06-03 12:58:22 +00:00
David Zbarsky dc08bde7a8
Use repo-mapping-aware runfiles API in rust-analyzer (#2666)
Fixes https://github.com/bazelbuild/rules_rust/issues/2615 and
https://github.com/bazelbuild/rules_rust/issues/2438
2024-05-31 00:23:58 +00:00
Matt Mackay df80ce61e4
fix: default rustfmt version to supplied rust version (#2660)
Modifies the default of `rustfmt_version` so that it uses the first
version in the `versions` list. If there are multiple versions given
then falls back to the original default of `DEFAULT_NIGHTLY_VERSION`.

We tripped over this where supply a single Rust version (non-nightly),
but started using nightly features in `rustfmt.toml` and could no longer
format directly with `cargo fmt`. This helped align the versions of both
toolchains.

---------

Co-authored-by: Daniel Wagner-Hall <dwagnerhall@apple.com>
2024-05-17 16:59:51 +00:00
Daniel Wagner-Hall 0d8d3e02b0
Fixup from #2657 (#2659) 2024-05-16 18:54:16 +00:00
UebelAndre 3bd4eeb9f1
Release 0.45.0 (#2658) 2024-05-16 15:56:22 +00:00
UebelAndre 4023d94a4d
Added logging to crate_universe checksum validation (#2657)
When `CARGO_BAZEL_DEBUG=1` is enabled, the following log lines will
print when determining repins.
```
Query 2024-05-16T15:17:26.592139Z DEBUG cargo_bazel::lockfile: cargo-bazel version hash: ef009193262ad048e8890de3f6c4c66f8f26584396e9b6f544894b337ab951ce
Query 2024-05-16T15:17:26.592402Z DEBUG cargo_bazel::lockfile: lockfile context hash: a89c68580b8ac127d1c3d3a700c3c895d107d0826a84c6594c0b4d6c55459af8
Query 2024-05-16T15:17:26.592417Z DEBUG cargo_bazel::lockfile: workspace config hash: baf129ecaaf01eda9020a45991fe804ce7def5e3dc600e8f4f9b99c814ab5635
Query 2024-05-16T15:17:26.592453Z DEBUG cargo_bazel::lockfile: splicing manifest hash: dceb142aa8d5be9cec3bf5d6318150b17c874a7ac84ca3fd9a608b3df279435c
Query 2024-05-16T15:17:26.592456Z DEBUG cargo_bazel::lockfile: Cargo version hash: 573f7bac3e83c5bd86e2fc369f5ecdafc3db984a9641f9f72b6bf68ab060f9d6
Query 2024-05-16T15:17:26.592458Z DEBUG cargo_bazel::lockfile: Rustc version hash: 25b2309140d57d18083da87e1597ef66785a693f2c12dbd7c6912728a2fbce1c
Query 2024-05-16T15:17:26.592461Z DEBUG cargo_bazel::lockfile: Digest hash: 81997a51e91981729d56b9118839163206d491451a10bf9611c6037d1ae2f665
Error: Digests do not match: Current Digest("4cdd2a75d814f49c49d7c02588accb2bc780d3cb1c0f718a83d7edffe4bbebe0") != Expected Digest("81997a51e91981729d56b9118839163206d491451a10bf9611c6037d1ae2f665")
```
2024-05-16 15:49:42 +00:00