Commit Graph

21 Commits

Author SHA1 Message Date
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
Keith Smiley f3620bf8d6
Add MODULE.bazel.lock to gitignore (#2505)
This way this file doesn't need to be manually managed, but if someone
wants to build rules_rust offline they can have a local version
2024-02-21 10:06:57 +00:00
Chuck Grindel 6a9359232e
chore: add `//bzlmod:hello_world_test` and use it as BCR presubmit (#2347)
- Create `bzlmod/hello_world` package based upon
`examples/bzlmod/hello_world`.
- Add `rules_bazel_integration_test` so that `//bzlmod:hello_world_test`
can be executed as a test from the parent workspace.
- Add `filegroup` targets named `all_files` to collect files for all of
the packages that are necessary to use `rules_rust`. These are an input
to the `rules_bazel_integration_test` test.
- Replace `.bcr/presubmit.yml` to test `//bzlmod:hello_world_test`.
- Update CI to test `//bzlmod:hello_world_test`.

Related to
https://github.com/bazelbuild/bazel-central-registry/pull/1199#discussion_r1429129814.
2023-12-27 16:46:57 +00:00
scentini 80f0eb488a
Support for `no_std` mode (#1934)
Initial support for `no_std` mode.
This allows us to
1. Don't pass the whole standard library to compile actions that specify `no_std`
2. Conditionally select `crate_features` and `deps` based on whether `no_std` mode is used.
Currently the only supported modes are `off` and `alloc`, with a possibility to expand in the future.

The `no_std` support comes with the following caveats:
1. Targets in `exec` mode are still built with `std`; the logic here being that if a device has enough space to run bazel and rustc, std's presence would not be a problem. This also saves some additional transitions on `proc_macro`s (they need `std`), as they are built in `exec` mode.
2. Tests are still built with `std`, as `libtest` depends on `libstd`

There is quite an ugly hack to make us be able to `select` on the `no_std` flavor taking `exec` into account; I'm looking forward to the day where Bazel will expose better ways to inspect the cfg.

There is also one part I didn't manage to make work - having a `rust_test` that tests the `rust_shared_library` in `cc_common.link` mode; I got a link error for missing `__rg_alloc` & co. symbols, which should be present as we pass `--@rules_rust//rust/settings:experimental_use_global_allocator=True`. Unfortunately I could only spot this error on CI, and could not reproduce locally. I removed the test because the `rust_shared_library` is already tested via a `cc_test`. I will however give another shot at inspecting how my local setup differs from CI.

The `rust_binary` source code in `main.rs` was borrowed from https://github.com/jfarrell468/no_std_examples, big thanks to @jfarrell468 for letting me use it.

Co-authored-by: Krasimir Georgiev <krasimir@google.com>
Co-authored-by: UebelAndre <github@uebelandre.com>
2023-05-03 14:38:47 +02:00
Krasimir Georgiev 078c6908fc
add cc_common.link support for rust_library and rust_test (#1490)
* add cc_common.link support

* Update rust/private/rustc.bzl

Co-authored-by: scentini <rosica@google.com>

* Update rust/private/rustc.bzl

Co-authored-by: scentini <rosica@google.com>

Co-authored-by: scentini <rosica@google.com>
2022-08-12 14:50:57 +02:00
David Tolnay 61eee54c73
Add bazel-* directories in cargo_manifest_dir/external_crate to gitignore (#1279)
Previously running `bazel build ...` in examples/cargo_manfest_dir/external_crate
would leave the following untracked files:

    Untracked files:
      (use "git add <file>..." to include in what will be committed)
            examples/cargo_manifest_dir/external_crate/bazel-bin
            examples/cargo_manifest_dir/external_crate/bazel-external_crate
            examples/cargo_manifest_dir/external_crate/bazel-out
            examples/cargo_manifest_dir/external_crate/bazel-testlogs

I noticed that of the 5 workspaces found by `find . -name WORKSPACE.bazel`
three of them were ignoring "bazel-*" via the top-level .gitignore while
one had its own .gitignore containing only "bazel-*". I consolidated
that one into the top-level .gitignore and added the 5th.
2022-05-04 10:32:07 -07:00
UebelAndre acca6f4000
Add `user.bazelrc` support to each workspace (#1161) 2022-03-01 06:59:47 -08:00
UebelAndre 8c05ac765f
Rust Analyzer: Generate rust-project.json without explicit target list (#1010)
* Emit rust_analyzer_crate_spec files for all workspace crates

* Regenerated cargo-raze outputs

* Address PR feedback

* Increase Bazel min test version

* Addressed PR feedback

* Make sysroot_src a data dependency

* Fix runfiles path specifier

* Use bazel-like space separated target specification

* Fix out-of-date comment

* Addressed PR feedback

* Added additional testing

* Added test comment

Co-authored-by: David Marcin <david@metawork.com>
2021-11-17 12:50:20 -08:00
UebelAndre a04ff4182c
Added crate_universe examples to CI (#707)
* Added crate_universe examples to CI

* Update crate_universe/bootstrap.bzl

Co-authored-by: Daniel Wagner-Hall <dawagner@gmail.com>

* Updated docs

* Remove crate_universe.bazelrc

* Updated attribute names

* Deleted example lockfile

Co-authored-by: Daniel Wagner-Hall <dawagner@gmail.com>
2021-04-27 10:15:18 -07:00
UebelAndre a3c2741207
Added bootstrapping for crate_universe (#663)
* Added bootstrap script for crate_universe and github action for auto-releasing new binaries

* Addressed PR feedback

Co-authored-by: Daniel Wagner-Hall <dawagner@gmail.com>

* Updated local dev documentation

* Add announce_rc to crate_universe.bazelrc

* Addressed buildifier defect

* Addressed additional user feedback

* Apply suggestions from code review

Co-authored-by: Daniel Wagner-Hall <dawagner@gmail.com>

* Fixed missing extension for windows.

Co-authored-by: Daniel Wagner-Hall <dawagner@gmail.com>
2021-04-07 10:11:43 -07:00
UebelAndre 1c3907da6e
Added test script for ensuring docs are up to date. (#672)
* Added test script for ensuring docs are up to date.

* Fixed bug in doc attribute formatting.

* Regenerate documentation

* `_tidy` now ignores empty first lines

* Updated comment

* Regenerate documentation
2021-04-07 08:46:31 -07:00
Daniel Wagner-Hall dd7e458de8
crate_universe rule (#598)
This rule dynamically looks up crate dependencies as a repository rule.

See https://github.com/bazelbuild/rules_rust/issues/2 for context.

Note that this rule is currently experimental, and offers absolutely no stability guarantees. Expect significant churn in near future.
2021-03-25 10:38:08 +00:00
Marcel Hlopko acfce01740
Add //rust/private/BUILD (therefore create a package there) (#569)
This PR achieves the following:

* buildifier bzl-visibility check was not detecting violations as it assumes private package, not just a directory
* adds //rust:common.bzl file where all the publicly available and supported API for writing custom rules interacting with Rust will reside
* the private package now sets the stability expectations, and it forces us to think about API layering and abstractions.

This turned out to be much bigger PR than expected :(
2021-02-03 09:11:48 +01:00
Sitaktif 224fe6a81b
Handle external packages using CARGO_MANIFEST_DIR (#464) 2020-10-26 08:46:33 +00:00
UebelAndre 1d7f96752f
Made examples compatible with cargo-raze (#418)
Updated examples to be compatible with cargo raze which I then used to regenerate dependencies.
2020-09-29 21:22:23 +02:00
Damien Martin-Guillerez a37e0f43d9
Make stardoc our documentation tool (#359)
The current documentation was difficult to maintain and not in sync with the inline one.

These changes adjust the setting so we can generate the documentation in markdown format and it will continue to be served on Github pages, this time with an easy way to sync it.
2020-06-30 12:05:23 +02:00
Daniel Wagner-Hall 4cd1404b25
gitignore node_modules (#331)
Running examples generates a couple of these
2020-06-11 09:18:53 -07:00
Damien Martin-Guillerez e008ebe9a5 Protobuf support (#92)
* Also add the dependencies in /examples/WORKSPACE

This allow to runs the tests in examples as a remote repository
and as a local repository.

* Add a dummy Cargo craze to use cargo raze on it.

With this craze, and cargo raze, we can simply use raze generated repositories
to add the necessary dependencies.

* Add generated files for the raze package of protobuf

* Add rust_(proto|grpc)_library

Those library add protobuf / gRPC support to Rust language in Bazel
using the native proto_library. It generates one crate per proto_library
which is efficient for incrementality but can lead to naming collisions.

We expose a bit of rust_library internal to re-use it in rust_proto_library
and create a new provider "rust_libs" that will declare a group of rust libraries.

* Add a gRPC client/server example

And a test with it.

* Add documentation for the rust_(proto|grpc)_library

* Use the new runfiles library in the test rather than a custom algorithm

* Add the missing dependencies to examples/WORKSPACE

This new dependency is quite unfortunate, it make using rules_rust
more complex since it needs to import a bzl file from skylib to be
able to use rules_rust, that adds 10 lines in the WORKSPACE without
much improvement. I guess this cannot be better until recursive
workspace are a thing.

* Generates cargo raze files compatible with macOS and Linux

Also to keep the same lockfile, check in the Cargo.lock and have
a lever to not re-run cargo generate-lockfile.

* Compile all proto stubs in one library

This a workaround a bug in Bazel that prevent the toolchain from being
loaded with the target transition (see
https://github.com/bazelbuild/bazel/pull/5650).

This is not ideal because it recompiles several time the same
proto if you depends on it from several dependency path
and can lead to seeing two compilation of the same proto
as different type. This is also terrible for incremental build
and contrary to the (protobuf blog
entry)[https://blog.bazel.build/2017/02/27/protocol-buffers.html].

* Force set the lazy_static implementation configuration.

The lazy_static crates now set a configuration from the build.rs, ideally we would be
able to handle that but that is not the case with the current cargo raze method.

* Final touch: documenting and simplifying toolchain creation

  - Documents how to create your custom toolchain when you need to import
    your own crates (or to use a different protobuf/grpc stubs compiler).
  - Add extra_aliased_targets to simply the cargo-raze generation
  - Use skylark http_archive to import protobuf.
  - Regenerate crates with google/cargo-raze#77 so that we don't need to
    have custom rewriting policy. Hence, deleted the wrapper around
    cargo raze, an update to the build file should simply be
    `cargo genrate-lockfiles && cargo raze` now.

* Fix nits suggested by @mfarrugi

* Remove usage of CrateInfos

This was a leftover from compiling the crates in the proto aspect.

* Use python for the optional_output_wrapper

Also move the optional_output_wrapper from the toolchain to the library
itself.
For some reason the runfiles where not shipped to the actions with the
old way which wasn't important for Bash that did not had any runfiles
but it is important for python.

* fix: README format

* Second pass of nits from @mfarrugi

* fix: add back the list of grpc stubs to create if not created
2018-11-13 10:27:19 -08:00
Marco Farrugia 1678ed042f
Implement directory based runfiles lookup (#132)
* Move runfiles library to tools/
* Implement directory based runfiles lookup.
* Add doc_test for runfiles.
* Update CI config.
* Spice up runfiles example.
2018-10-20 00:36:03 +00:00
David Z. Chen d5fe629604 Generate documentation with Skydoc. (#28)
Fixes #12
2017-02-10 10:42:41 -08:00
Justine Tunney f7604fe04f Add .gitignore file (#18) 2016-07-18 21:03:01 -07:00