diff --git a/docs/cargo.md b/docs/cargo.md index 7b5669d63e..4f0975d155 100644 --- a/docs/cargo.md +++ b/docs/cargo.md @@ -30,7 +30,7 @@ A rule for bootstrapping a Rust binary using [Cargo](https://doc.rust-lang.org/c | env_label | A mapping of platform triple to a set of environment variables. This attribute differs from env in that all variables passed here must be fully qualified labels of files. See [cargo_env](#cargo_env) for usage details. Additionally, the platform triple * applies to all platforms. | Dictionary: String -> String | optional | {} | | iso_date | The iso_date of cargo binary the resolver should use. Note: This can only be set if version is beta or nightly | String | optional | "" | | repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<p>For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target). | Dictionary: String -> String | required | | -| rust_toolchain_repository_template | The template to use for finding the host rust_toolchain repository. {version} (eg. '1.53.0'), {triple} (eg. 'x86_64-unknown-linux-gnu'), {system} (eg. 'darwin'), and {arch} (eg. 'aarch64') will be replaced in the string if present. | String | optional | "rust_{system}_{arch}" | +| rust_toolchain_repository_template | The template to use for finding the host rust_toolchain repository. {version} (eg. '1.53.0'), {triple} (eg. 'x86_64-unknown-linux-gnu'), {arch} (eg. 'aarch64'), {vendor} (eg. 'unknown'), {system} (eg. 'darwin'), {cfg} (eg. 'exec'), and {tool} (eg. 'rustc') will be replaced in the string if present. | String | optional | "rules_rust_{version}_{triple}_{cfg}_{tool}" | | srcs | Souce files of the crate to build. Passing source files here can be used to trigger rebuilds when changes are made | List of labels | optional | [] | | version | The version of cargo the resolver should use | String | optional | "1.55.0" | diff --git a/docs/crate_universe.md b/docs/crate_universe.md index ead3945b35..5ed6cf435d 100644 --- a/docs/crate_universe.md +++ b/docs/crate_universe.md @@ -159,7 +159,7 @@ Environment Variables: | resolver | The label of a crate_universe resolver. Resolvers can be built using cargo_bootstrap_repository but if possible, it's recommended to stick with downloading a resoler via resolver_download_url_template. | Label | optional | None | | resolver_download_url_template | URL template from which to download the resolver binary. {host_triple} and {extension} will be filled in according to the host platform. | String | optional | "{host_triple}{extension}" | | resolver_sha256s | Dictionary of host_triple -> sha256 for resolver binary. | Dictionary: String -> String | optional | {"aarch64-apple-darwin": "{aarch64-apple-darwin--sha256}", "aarch64-unknown-linux-gnu": "{aarch64-unknown-linux-gnu--sha256}", "x86_64-apple-darwin": "{x86_64-apple-darwin--sha256}", "x86_64-pc-windows-gnu": "{x86_64-pc-windows-gnu--sha256}", "x86_64-unknown-linux-gnu": "{x86_64-unknown-linux-gnu--sha256}"} | -| rust_toolchain_repository_template | The template to use for finding the host rust_toolchain repository. {version} (eg. '1.53.0'), {triple} (eg. 'x86_64-unknown-linux-gnu'), {system} (eg. 'darwin'), and {arch} (eg. 'aarch64') will be replaced in the string if present. | String | optional | "rust_{system}_{arch}" | +| rust_toolchain_repository_template | The template to use for finding the host rust_toolchain repository. {version} (eg. '1.53.0'), {triple} (eg. 'x86_64-unknown-linux-gnu'), {arch} (eg. 'aarch64'), {vendor} (eg. 'unknown'), {system} (eg. 'darwin'), {cfg} (eg. 'exec'), and {tool} (eg. 'rustc') will be replaced in the string if present. | String | optional | "rules_rust_{version}_{triple}_{cfg}_{tool}" | | sha256s | The sha256 checksum of the desired rust artifacts | Dictionary: String -> String | optional | {} | | supported_targets | A list of supported [platform triples](https://doc.rust-lang.org/nightly/rustc/platform-support.html) to consider when resoliving dependencies. | List of strings | optional | ["aarch64-apple-darwin", "aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-pc-windows-msvc", "x86_64-unknown-freebsd", "x86_64-unknown-linux-gnu"] | | version | The version of cargo the resolver should use | String | optional | "1.55.0" | diff --git a/docs/flatten.md b/docs/flatten.md index 1f32578ed4..50a217731f 100644 --- a/docs/flatten.md +++ b/docs/flatten.md @@ -20,10 +20,16 @@ * [rust_bindgen_library](#rust_bindgen_library) * [rust_bindgen_repositories](#rust_bindgen_repositories) * [rust_bindgen_toolchain](#rust_bindgen_toolchain) +* [rust_cargo_repository](#rust_cargo_repository) +* [rust_cargo_toolchain](#rust_cargo_toolchain) * [rust_clippy](#rust_clippy) * [rust_clippy_aspect](#rust_clippy_aspect) +* [rust_clippy_repository](#rust_clippy_repository) +* [rust_clippy_toolchain](#rust_clippy_toolchain) * [rust_doc](#rust_doc) * [rust_doc_test](#rust_doc_test) +* [rust_exec_toolchain](#rust_exec_toolchain) +* [rust_exec_toolchain_repository](#rust_exec_toolchain_repository) * [rust_grpc_library](#rust_grpc_library) * [rust_library](#rust_library) * [rust_proc_macro](#rust_proc_macro) @@ -33,14 +39,18 @@ * [rust_proto_transitive_repositories](#rust_proto_transitive_repositories) * [rust_repositories](#rust_repositories) * [rust_repository_set](#rust_repository_set) +* [rust_rustc_repository](#rust_rustc_repository) +* [rust_rustfmt_repository](#rust_rustfmt_repository) +* [rust_rustfmt_toolchain](#rust_rustfmt_toolchain) * [rust_shared_library](#rust_shared_library) * [rust_static_library](#rust_static_library) * [rust_stdlib_filegroup](#rust_stdlib_filegroup) +* [rust_stdlib_repository](#rust_stdlib_repository) +* [rust_target_toolchain](#rust_target_toolchain) +* [rust_target_toolchain_repository](#rust_target_toolchain_repository) * [rust_test](#rust_test) * [rust_test_suite](#rust_test_suite) * [rust_toolchain](#rust_toolchain) -* [rust_toolchain_repository](#rust_toolchain_repository) -* [rust_toolchain_repository_proxy](#rust_toolchain_repository_proxy) * [rust_wasm_bindgen](#rust_wasm_bindgen) * [rust_wasm_bindgen_repositories](#rust_wasm_bindgen_repositories) * [rust_wasm_bindgen_toolchain](#rust_wasm_bindgen_toolchain) @@ -91,7 +101,7 @@ A rule for bootstrapping a Rust binary using [Cargo](https://doc.rust-lang.org/c | env_label | A mapping of platform triple to a set of environment variables. This attribute differs from env in that all variables passed here must be fully qualified labels of files. See [cargo_env](#cargo_env) for usage details. Additionally, the platform triple * applies to all platforms. | Dictionary: String -> String | optional | {} | | iso_date | The iso_date of cargo binary the resolver should use. Note: This can only be set if version is beta or nightly | String | optional | "" | | repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<p>For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target). | Dictionary: String -> String | required | | -| rust_toolchain_repository_template | The template to use for finding the host rust_toolchain repository. {version} (eg. '1.53.0'), {triple} (eg. 'x86_64-unknown-linux-gnu'), {system} (eg. 'darwin'), and {arch} (eg. 'aarch64') will be replaced in the string if present. | String | optional | "rust_{system}_{arch}" | +| rust_toolchain_repository_template | The template to use for finding the host rust_toolchain repository. {version} (eg. '1.53.0'), {triple} (eg. 'x86_64-unknown-linux-gnu'), {arch} (eg. 'aarch64'), {vendor} (eg. 'unknown'), {system} (eg. 'darwin'), {cfg} (eg. 'exec'), and {tool} (eg. 'rustc') will be replaced in the string if present. | String | optional | "rules_rust_{version}_{triple}_{cfg}_{tool}" | | srcs | Souce files of the crate to build. Passing source files here can be used to trigger rebuilds when changes are made | List of labels | optional | [] | | version | The version of cargo the resolver should use | String | optional | "1.55.0" | @@ -136,7 +146,7 @@ Environment Variables: | resolver | The label of a crate_universe resolver. Resolvers can be built using cargo_bootstrap_repository but if possible, it's recommended to stick with downloading a resoler via resolver_download_url_template. | Label | optional | None | | resolver_download_url_template | URL template from which to download the resolver binary. {host_triple} and {extension} will be filled in according to the host platform. | String | optional | "{host_triple}{extension}" | | resolver_sha256s | Dictionary of host_triple -> sha256 for resolver binary. | Dictionary: String -> String | optional | {"aarch64-apple-darwin": "{aarch64-apple-darwin--sha256}", "aarch64-unknown-linux-gnu": "{aarch64-unknown-linux-gnu--sha256}", "x86_64-apple-darwin": "{x86_64-apple-darwin--sha256}", "x86_64-pc-windows-gnu": "{x86_64-pc-windows-gnu--sha256}", "x86_64-unknown-linux-gnu": "{x86_64-unknown-linux-gnu--sha256}"} | -| rust_toolchain_repository_template | The template to use for finding the host rust_toolchain repository. {version} (eg. '1.53.0'), {triple} (eg. 'x86_64-unknown-linux-gnu'), {system} (eg. 'darwin'), and {arch} (eg. 'aarch64') will be replaced in the string if present. | String | optional | "rust_{system}_{arch}" | +| rust_toolchain_repository_template | The template to use for finding the host rust_toolchain repository. {version} (eg. '1.53.0'), {triple} (eg. 'x86_64-unknown-linux-gnu'), {arch} (eg. 'aarch64'), {vendor} (eg. 'unknown'), {system} (eg. 'darwin'), {cfg} (eg. 'exec'), and {tool} (eg. 'rustc') will be replaced in the string if present. | String | optional | "rules_rust_{version}_{triple}_{cfg}_{tool}" | | sha256s | The sha256 checksum of the desired rust artifacts | Dictionary: String -> String | optional | {} | | supported_targets | A list of supported [platform triples](https://doc.rust-lang.org/nightly/rustc/platform-support.html) to consider when resoliving dependencies. | List of strings | optional | ["aarch64-apple-darwin", "aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-pc-windows-msvc", "x86_64-unknown-freebsd", "x86_64-unknown-linux-gnu"] | | version | The version of cargo the resolver should use | String | optional | "1.55.0" | @@ -400,6 +410,50 @@ The tools required for the `rust_bindgen` rule. | rustfmt | The label of a rustfmt executable. If this is provided, generated sources will be formatted. | Label | optional | None | + + +## rust_cargo_repository + +
+rust_cargo_repository(name, auth, iso_date, repo_mapping, sha256, triple, urls, version)
+
+ +A repository rule for downloading a [Cargo](https://doc.rust-lang.org/cargo/) artifact for use in a `rust_cargo_toolchain`. + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this repository. | Name | required | | +| auth | Auth object compatible with repository_ctx.download to use when downloading files. See https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download for more details. | Dictionary: String -> String | optional | {} | +| iso_date | The date of the tool (or None, if the version is a specific version). | String | optional | "" | +| repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<p>For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target). | Dictionary: String -> String | required | | +| sha256 | The sha256 of the cargo artifact. | String | optional | "" | +| triple | The Rust-style target that this compiler runs on | String | required | | +| urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). | List of strings | optional | ["https://static.rust-lang.org/dist/{}.tar.gz"] | +| version | The version of the tool among "nightly", "beta", or an exact version. | String | required | | + + + + +## rust_cargo_toolchain + +
+rust_cargo_toolchain(name, cargo)
+
+ +Declares a [Cargo](https://doc.rust-lang.org/cargo/) toolchain for use. + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | +| cargo | The location of the cargo binary. | Label | required | | + + ## rust_clippy @@ -454,6 +508,50 @@ rust_clippy( | deps | Rust targets to run clippy on. | List of labels | optional | [] | + + +## rust_clippy_repository + +
+rust_clippy_repository(name, auth, iso_date, repo_mapping, sha256, triple, urls, version)
+
+ +A repository rule for defining a `rust_clippy_toolchain` from the requested version of [Clippy](https://github.com/rust-lang/rust-clippy#readme) + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this repository. | Name | required | | +| auth | Auth object compatible with repository_ctx.download to use when downloading files. See https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download for more details. | Dictionary: String -> String | optional | {} | +| iso_date | The date of the tool (or None, if the version is a specific version). | String | optional | "" | +| repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<p>For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target). | Dictionary: String -> String | required | | +| sha256 | The sha256 of the clippy-driver artifact. | String | optional | "" | +| triple | The Rust-style target that this compiler runs on | String | required | | +| urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). | List of strings | optional | ["https://static.rust-lang.org/dist/{}.tar.gz"] | +| version | The version of the tool among "nightly", "beta", or an exact version. | String | required | | + + + + +## rust_clippy_toolchain + +
+rust_clippy_toolchain(name, clippy_driver)
+
+ +Declares a [Clippy](https://github.com/rust-lang/rust-clippy#readme) toolchain for use. + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | +| clippy_driver | The location of the clippy-driver binary. | Label | required | | + + ## rust_doc @@ -569,6 +667,67 @@ Running `bazel test //hello_lib:hello_lib_doc_test` will run all documentation t | dep | __deprecated__: use crate | Label | optional | None | + + +## rust_exec_toolchain + +
+rust_exec_toolchain(name, default_edition, iso_date, os, rustc, rustc_lib, rustc_srcs, rustdoc,
+                    triple, version)
+
+ +Declares a Rust exec/host toolchain for use. + +This is for declaring a custom host toolchain (as described by [The rustc book](https://doc.rust-lang.org/stable/rustc/platform-support.html)), +eg. for configuring a particular version of rust or supporting a new platform. + +Example: + +Suppose the core rust team has ported the compiler to a new target CPU, called `cpuX`. This +support can be used in Bazel by defining a new toolchain definition and declaration: + +```python +load('@rules_rust//rust:toolchain.bzl', 'rust_exec_toolchain') + +rust_exec_toolchain( + name = "rust_cpuX_impl", + # see attributes... +) + +toolchain( + name = "rust_cpuX", + exec_compatible_with = [ + "@platforms//cpu:cpuX", + ], + toolchain = ":rust_cpuX_impl", + toolchain_type = "@rules_rust//rust:exec_toolchain", +) +``` + +Then, either add the label of the toolchain rule to `register_toolchains` in the WORKSPACE, or pass +it to the `"--extra_toolchains"` flag for Bazel, and it will be used. + +See @rules_rust//rust:repositories.bzl for examples of defining the @rust_cpuX repository +with the actual binaries and libraries. + + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | +| default_edition | The edition to use for rust_* rules that don't specify an edition. | String | optional | "1.55.0" | +| iso_date | The date of the tool (or None, if the version is a specific version). | String | optional | "" | +| os | The operating system for the current toolchain | String | required | | +| rustc | The location of the rustc binary. Can be a direct source or a filegroup containing one item. | Label | required | | +| rustc_lib | The location of the rustc binary. Can be a direct source or a filegroup containing one item. | Label | required | | +| rustc_srcs | The source code of rustc. | Label | optional | None | +| rustdoc | The location of the rustdoc binary. Can be a direct source or a filegroup containing one item. | Label | optional | None | +| triple | The platform triple for the toolchains execution environment. For more details see: https://docs.bazel.build/versions/master/skylark/rules.html#configurations | String | optional | "" | +| version | The date of the tool (or None, if the version is a specific version). | String | required | | + + ## rust_grpc_library @@ -834,13 +993,84 @@ See @rules_rust//proto:BUILD for examples of defining the toolchain. | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | | edition | The edition used by the generated rust source. | String | optional | "2018" | -| grpc_compile_deps | The crates the generated grpc libraries depends on. | List of labels | optional | [Label("//proto/raze:protobuf"), Label("//proto/raze:grpc"), Label("//proto/raze:tls_api"), Label("//proto/raze:tls_api_stub")] | +| grpc_compile_deps | The crates the generated grpc libraries depends on. | List of labels | optional | [Label("//proto/raze:protobuf"), Label("@rules_rust//proto/raze:grpc"), Label("@rules_rust//proto/raze:tls_api"), Label("@rules_rust//proto/raze:tls_api_stub")] | | grpc_plugin | The location of the Rust protobuf compiler plugin to generate rust gRPC stubs. | Label | optional | //proto:protoc_gen_rust_grpc | | proto_compile_deps | The crates the generated protobuf libraries depends on. | List of labels | optional | [Label("//proto/raze:protobuf")] | | proto_plugin | The location of the Rust protobuf compiler plugin used to generate rust sources. | Label | optional | //proto:protoc_gen_rust | | protoc | The location of the protoc binary. It should be an executable target. | Label | optional | @com_google_protobuf//:protoc | + + +## rust_rustc_repository + +
+rust_rustc_repository(name, auth, dev_components, iso_date, repo_mapping, sha256s, triple, urls,
+                      version)
+
+ +must be a host toolchain + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this repository. | Name | required | | +| auth | Auth object compatible with repository_ctx.download to use when downloading files. See https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download for more details. | Dictionary: String -> String | optional | {} | +| dev_components | Whether to download the rustc-dev components (defaults to False). Requires version to be "nightly". | Boolean | optional | False | +| iso_date | The date of the tool (or None, if the version is a specific version). | String | optional | "" | +| repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<p>For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target). | Dictionary: String -> String | required | | +| sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_repositories](#rust_repositories) for more details. | Dictionary: String -> String | optional | {} | +| triple | The Rust-style target that this compiler runs on | String | required | | +| urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). | List of strings | optional | ["https://static.rust-lang.org/dist/{}.tar.gz"] | +| version | The version of the tool among "nightly", "beta", or an exact version. | String | required | | + + + + +## rust_rustfmt_repository + +
+rust_rustfmt_repository(name, auth, iso_date, repo_mapping, sha256, triple, urls, version)
+
+ +A repository rule for downloading a [Rustfmt](https://github.com/rust-lang/rustfmt#readme) artifact for use in a `rust_rustfmt_toolchain`. + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this repository. | Name | required | | +| auth | Auth object compatible with repository_ctx.download to use when downloading files. See https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download for more details. | Dictionary: String -> String | optional | {} | +| iso_date | The date of the tool (or None, if the version is a specific version). | String | optional | "" | +| repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<p>For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target). | Dictionary: String -> String | required | | +| sha256 | The sha256 of the rustfmt artifact. | String | optional | "" | +| triple | The Rust-style target that this compiler runs on | String | required | | +| urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). | List of strings | optional | ["https://static.rust-lang.org/dist/{}.tar.gz"] | +| version | The version of the tool among "nightly", "beta", or an exact version. | String | required | | + + + + +## rust_rustfmt_toolchain + +
+rust_rustfmt_toolchain(name, rustfmt)
+
+ +Declares a [Rustfmt](https://github.com/rust-lang/rustfmt#readme) toolchain for use. + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | +| rustfmt | The location of the rustfmt binary. | Label | required | | + + ## rust_shared_library @@ -944,6 +1174,93 @@ A dedicated filegroup-like rule for Rust stdlib artifacts. | srcs | The list of targets/files that are components of the rust-stdlib file group | List of labels | required | | + + +## rust_stdlib_repository + +
+rust_stdlib_repository(name, auth, iso_date, repo_mapping, sha256s, triple, urls, version)
+
+ +A repository rule for fetching the `rust-std` ([Rust Standard Library](https://doc.rust-lang.org/std/)) artifact for the requested platform. + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this repository. | Name | required | | +| auth | Auth object compatible with repository_ctx.download to use when downloading files. See https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download for more details. | Dictionary: String -> String | optional | {} | +| iso_date | The date of the tool (or None, if the version is a specific version). | String | optional | "" | +| repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<p>For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target). | Dictionary: String -> String | required | | +| sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_repositories](#rust_repositories) for more details. | Dictionary: String -> String | optional | {} | +| triple | The Rust-style target that this compiler runs on | String | required | | +| urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). | List of strings | optional | ["https://static.rust-lang.org/dist/{}.tar.gz"] | +| version | The version of the tool among "nightly", "beta", or an exact version. | String | required | | + + + + +## rust_target_toolchain + +
+rust_target_toolchain(name, allocator_library, binary_ext, debug_info, dylib_ext, iso_date,
+                      opt_level, os, rust_stdlib, staticlib_ext, stdlib_linkflags, target_json,
+                      triple, version)
+
+ +Declares a Rust target toolchain for use. + +This is for declaring a custom toolchain which contains details about the target platform as well as +provide a `rust-std` artifact to the sysroot for targets that depend on the stardard library. + +Example: + +Suppose the core rust team has added a new platform to tier 2 support with a `rust-std` artifact called +`aarch256-raven-microcyber`. This support can be used in Bazel by defining a new toolchain definition +and declaration: + +```python +load('@rules_rust//rust:toolchain.bzl', 'rust_target_toolchain') + +rust_target_toolchain( + name = "rust_aarch256_raven_microcyber_impl", + # see attributes... +) + +toolchain( + name = "rust_aarch256_raven_microcyber", + target_compatible_with = [ + "@platforms//cpu:aarch2077", + "@platforms//os:microcyber", + ], + toolchain = ":rust_aarch256_raven_microcyber_impl", + toolchain_type = "@rules_rust//rust:target_toolchain", +) +``` + + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | +| allocator_library | Target that provides allocator functions when rust_library targets are embedded in a cc_binary. | Label | optional | None | +| binary_ext | The extension for binaries created from rustc. | String | required | | +| debug_info | Rustc debug info levels per opt level | Dictionary: String -> String | optional | {"dbg": "2", "fastbuild": "0", "opt": "0"} | +| dylib_ext | The extension for dynamic libraries created from rustc. | String | required | | +| iso_date | The date of the tool (or None, if the version is a specific version). | String | optional | "" | +| opt_level | Rustc optimization levels. | Dictionary: String -> String | optional | {"dbg": "0", "fastbuild": "0", "opt": "3"} | +| os | The operating system for the current toolchain | String | required | | +| rust_stdlib | The rust standard library. | Label | required | | +| staticlib_ext | The extension for static libraries created from rustc. | String | required | | +| stdlib_linkflags | Additional linker libs used when std lib is linked, see https://github.com/rust-lang/rust/blob/master/src/libstd/build.rs | List of strings | required | | +| target_json | Override the target_triple with a custom target specification. For more details see: https://doc.rust-lang.org/rustc/targets/custom.html | Label | optional | None | +| triple | The platform triple for the toolchains execution environment. For more details see: https://docs.bazel.build/versions/master/skylark/rules.html#configurations | String | optional | "" | +| version | The version of the tool among "nightly", "beta", or an exact version. | String | required | | + + ## rust_test @@ -1112,51 +1429,43 @@ Run the test with `bazel build //hello_lib:hello_lib_test`. ## rust_toolchain
-rust_toolchain(name, allocator_library, binary_ext, cargo, clippy_driver, debug_info,
-               default_edition, dylib_ext, exec_triple, opt_level, os, rust_doc, rust_lib, rustc,
-               rustc_lib, rustc_srcs, rustfmt, staticlib_ext, stdlib_linkflags, target_json,
-               target_triple)
+rust_toolchain(name)
 
-Declares a Rust toolchain for use. - -This is for declaring a custom toolchain, eg. for configuring a particular version of rust or supporting a new platform. - -Example: - -Suppose the core rust team has ported the compiler to a new target CPU, called `cpuX`. This support can be used in Bazel by defining a new toolchain definition and declaration: +Declares a Rust exec/host + target toolchain for use. -```python -load('@rules_rust//rust:toolchain.bzl', 'rust_toolchain') +This takes a [rust_exec_toolchain](#rust_exec_toolchain) and a [rust_target_toolchain](#rust_target_toolchain) and creates +a [sysroot](https://doc.rust-lang.org/stable/rustc/command-line-arguments.html#--sysroot-override-the-system-root) +containing all Rust components needed to build in the execution environment for the target platform. This +toolchain allows Bazel's toolchain resolution to, on-demand, gather the necessary components to perform an action +without forcing users to generate complete sysroots for all combinations of `exec -> target(s)` expected to be +built. -rust_toolchain( - name = "rust_cpuX_impl", - rustc = "@rust_cpuX//:rustc", - rustc_lib = "@rust_cpuX//:rustc_lib", - rust_lib = "@rust_cpuX//:rust_lib", - rust_doc = "@rust_cpuX//:rustdoc", - binary_ext = "", - staticlib_ext = ".a", - dylib_ext = ".so", - stdlib_linkflags = ["-lpthread", "-ldl"], - os = "linux", -) +A generated sysroot is expected to look like the following: -toolchain( - name = "rust_cpuX", - exec_compatible_with = [ - "@platforms//cpu:cpuX", - ], - target_compatible_with = [ - "@platforms//cpu:cpuX", - ], - toolchain = ":rust_cpuX_impl", -) +```text +rust/toolchain/current/ + bin/ + rustc -> ${CACHE_LOCATION}/rustc + rustdoc -> ${CACHE_LOCATION}/rustdoc + lib/ + lib*.so -> ${CACHE_LOCATION}/lib*.so + ... + rustlib/ + x86_64-unknown-linux-gnu/ + bin/ + rust-lld -> ${CACHE_LOCATION}/rust-lld + lib/ + lib*.rlib -> ${CACHE_LOCATION}/lib*.rlib + ... + rules_rust.sysroot -> ${CACHE_LOCATION}/rules_rust.sysroot ``` -Then, either add the label of the toolchain rule to `register_toolchains` in the WORKSPACE, or pass it to the `"--extra_toolchains"` flag for Bazel, and it will be used. - -See @rules_rust//rust:repositories.bzl for examples of defining the @rust_cpuX repository with the actual binaries and libraries. +The tree above assumes that the contents of `rust_exec_toolchain` and `rust_target_toolchain` can +be directly used in the sysroot, meaning the files use the same paths from the root of their +repositories and are not expected to contain any conflicts. Though, both toolchains may provide +contents for the same directory, where above `./lib/rustlib/x86_64-unknown-linux-gnu` contains a +`bin` directory from the exec toolchain and a `lib` directory from the target toolchain. **ATTRIBUTES** @@ -1165,85 +1474,6 @@ See @rules_rust//rust:repositories.bzl for examples of defining the @rust_cpuX r | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | -| allocator_library | Target that provides allocator functions when rust_library targets are embedded in a cc_binary. | Label | optional | None | -| binary_ext | The extension for binaries created from rustc. | String | required | | -| cargo | The location of the cargo binary. Can be a direct source or a filegroup containing one item. | Label | optional | None | -| clippy_driver | The location of the clippy-driver binary. Can be a direct source or a filegroup containing one item. | Label | optional | None | -| debug_info | Rustc debug info levels per opt level | Dictionary: String -> String | optional | {"dbg": "2", "fastbuild": "0", "opt": "0"} | -| default_edition | The edition to use for rust_* rules that don't specify an edition. | String | optional | "2018" | -| dylib_ext | The extension for dynamic libraries created from rustc. | String | required | | -| exec_triple | The platform triple for the toolchains execution environment. For more details see: https://docs.bazel.build/versions/master/skylark/rules.html#configurations | String | optional | "" | -| opt_level | Rustc optimization levels. | Dictionary: String -> String | optional | {"dbg": "0", "fastbuild": "0", "opt": "3"} | -| os | The operating system for the current toolchain | String | required | | -| rust_doc | The location of the rustdoc binary. Can be a direct source or a filegroup containing one item. | Label | optional | None | -| rust_lib | The rust standard library. | Label | optional | None | -| rustc | The location of the rustc binary. Can be a direct source or a filegroup containing one item. | Label | optional | None | -| rustc_lib | The libraries used by rustc during compilation. | Label | optional | None | -| rustc_srcs | The source code of rustc. | Label | optional | None | -| rustfmt | The location of the rustfmt binary. Can be a direct source or a filegroup containing one item. | Label | optional | None | -| staticlib_ext | The extension for static libraries created from rustc. | String | required | | -| stdlib_linkflags | Additional linker libs used when std lib is linked, see https://github.com/rust-lang/rust/blob/master/src/libstd/build.rs | List of strings | required | | -| target_json | Override the target_triple with a custom target specification. For more details see: https://doc.rust-lang.org/rustc/targets/custom.html | Label | optional | None | -| target_triple | The platform triple for the toolchains target environment. For more details see: https://docs.bazel.build/versions/master/skylark/rules.html#configurations | String | optional | "" | - - - - -## rust_toolchain_repository - -
-rust_toolchain_repository(name, auth, dev_components, edition, exec_triple, extra_target_triples,
-                          include_rustc_srcs, iso_date, repo_mapping, rustfmt_version, sha256s,
-                          toolchain_name_prefix, urls, version)
-
- -Composes a single workspace containing the toolchain components for compiling on a given platform to a series of target platforms. - -A given instance of this rule should be accompanied by a rust_toolchain_repository_proxy invocation to declare its toolchains to Bazel; the indirection allows separating toolchain selection from toolchain fetching. - -**ATTRIBUTES** - - -| Name | Description | Type | Mandatory | Default | -| :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this repository. | Name | required | | -| auth | Auth object compatible with repository_ctx.download to use when downloading files. See https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download for more details. | Dictionary: String -> String | optional | {} | -| dev_components | Whether to download the rustc-dev components (defaults to False). Requires version to be "nightly". | Boolean | optional | False | -| edition | The rust edition to be used by default. | String | optional | "2018" | -| exec_triple | The Rust-style target that this compiler runs on | String | required | | -| extra_target_triples | Additional rust-style targets that this set of toolchains should support. | List of strings | optional | [] | -| include_rustc_srcs | Whether to download and unpack the rustc source files. These are very large, and slow to unpack, but are required to support rust analyzer. An environment variable RULES_RUST_TOOLCHAIN_INCLUDE_RUSTC_SRCS can also be used to control this attribute. This variable will take precedence over the hard coded attribute. Setting it to true to activates this attribute where all other values deactivate it. | Boolean | optional | False | -| iso_date | The date of the tool (or None, if the version is a specific version). | String | optional | "" | -| repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<p>For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target). | Dictionary: String -> String | required | | -| rustfmt_version | The version of the tool among "nightly", "beta", or an exact version. | String | optional | "" | -| sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_repositories](#rust_repositories) for more details. | Dictionary: String -> String | optional | {} | -| toolchain_name_prefix | The per-target prefix expected for the rust_toolchain declarations in the parent workspace. | String | optional | "" | -| urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). | List of strings | optional | ["https://static.rust-lang.org/dist/{}.tar.gz"] | -| version | The version of the tool among "nightly", "beta", or an exact version. | String | required | | - - - - -## rust_toolchain_repository_proxy - -
-rust_toolchain_repository_proxy(name, exec_triple, extra_target_triples, parent_workspace_name,
-                                repo_mapping, toolchain_name_prefix)
-
- -Generates a toolchain-bearing repository that declares the toolchains from some other rust_toolchain_repository. - -**ATTRIBUTES** - - -| Name | Description | Type | Mandatory | Default | -| :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this repository. | Name | required | | -| exec_triple | The Rust-style target triple for the compilation platform | String | required | | -| extra_target_triples | The Rust-style triples for extra compilation targets | List of strings | optional | [] | -| parent_workspace_name | The name of the other rust_toolchain_repository | String | required | | -| repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<p>For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target). | Dictionary: String -> String | required | | -| toolchain_name_prefix | The per-target prefix expected for the rust_toolchain declarations in the parent workspace. | String | optional | "" | @@ -1719,6 +1949,61 @@ Declare dependencies needed for bindgen. + + +## rust_exec_toolchain_repository + +
+rust_exec_toolchain_repository(name, triple, dev_components, edition, exec_compatible_with,
+                               include_rustc_srcs, iso_date, rustfmt_iso_date, rustfmt_version,
+                               sha256s, target_compatible_with, urls, version)
+
+ +A repository rule for defining a [rust_exec_toolchain](#rust_exec_toolchain). + +This repository rule generates repositories for host tools (as described by [The rustc book][trc]) and wires +them into a `rust_exec_toolchain` target. Note that the `rust_exec_toolchain` only includes `rustc` and it's +dependencies. Additional host tools such as `Cargo`, `Clippy`, and `Rustfmt` are all declared as separate +toolchains. This rule should be used to define more customized exec toolchains than those created by +`rust_repositories`. + +Tool Repositories Created: +- [rust_cargo_repository](#rust_cargo_repository) +- [rust_clippy_repository](#rust_clippy_repository) +- [rust_rustc_repository](#rust_rustc_repository) +- [rust_rustfmt_repository](#rust_rustfmt_repository) +- [rust_srcs_repository](#rust_srcs_repository) + +Toolchains Created: +- [rust_exec_toolchain](#rust_exec_toolchain) +- [rust_cargo_toolchain](#rust_cargo_toolchain) +- [rust_clippy_toolchain](#rust_clippy_toolchain) +- [rust_rustfmt_toolchain](#rust_rustfmt_toolchain) + + +[trc]: https://doc.rust-lang.org/stable/rustc/platform-support.html + + +**PARAMETERS** + + +| Name | Description | Default Value | +| :------------- | :------------- | :------------- | +| name | The name of the toolchain repository as well as the prefix for each individual 'tool repository'. | none | +| triple | The platform triple of the execution environment. | none | +| dev_components | [description]. Defaults to False. | False | +| edition | The rust edition to be used by default. | "2018" | +| exec_compatible_with | Optional exec constraints for the toolchain. If unset, a default will be used based on the value of triple. See @rules_rust//rust/platform:triple_mappings.bzl for more details. | None | +| include_rustc_srcs | Whether to download and unpack the rustc source files. These are very large, and slow to unpack, but are required to support rust analyzer. | False | +| iso_date | The date of the tool (or None, if the version is a specific version). | None | +| rustfmt_iso_date | Similar to iso_date but specific to Rustfmt. If unspecified, iso_date will be used. | None | +| rustfmt_version | Similar to version but specific to Rustfmt. If unspecified, version will be used. | None | +| sha256s | A dict associating tool subdirectories to sha256 hashes. | None | +| target_compatible_with | Optional target constraints for the toolchain. | [] | +| urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). | ["https://static.rust-lang.org/dist/{}.tar.gz"] | +| version | The version of the tool among "nightly", "beta", or an exact version. | "1.55.0" | + + ## rust_proto_repositories @@ -1756,13 +2041,15 @@ This macro should be called immediately after the `rust_proto_repositories` macr ## rust_repositories
-rust_repositories(version, iso_date, rustfmt_version, edition, dev_components, sha256s,
-                  include_rustc_srcs, urls)
+rust_repositories(dev_components, edition, include_rustc_srcs, iso_date, prefix,
+                  register_toolchains, rustfmt_version, sha256s, urls, version)
 
-Emits a default set of toolchains for Linux, MacOS, and Freebsd +Instantiate repositories and toolchains required by `rules_rust`. -Skip this macro and call the `rust_repository_set` macros directly if you need a compiler for other hosts or for additional target triples. +Skip this macro and call the [rust_exec_toolchain_repository](#rust_exec_toolchain_repository) or +[rust_target_toolchain_repository](#rust_target_toolchain_repository) rules directly if you need a +compiler for other hosts or for additional target triples. The `sha256` attribute represents a dict associating tool subdirectories to sha256 hashes. As an example: ```python @@ -1772,9 +2059,6 @@ The `sha256` attribute represents a dict associating tool subdirectories to sha2 "rust-std-1.46.0-x86_64-unknown-linux-gnu": "ac04aef80423f612c0079829b504902de27a6997214eb58ab0765d02f7ec1dbc", } ``` -This would match for `exec_triple = "x86_64-unknown-linux-gnu"`. If not specified, rules_rust pulls from a non-exhaustive list of known checksums.. - -See `load_arbitrary_tool` in `@rules_rust//rust:repositories.bzl` for more details. **PARAMETERS** @@ -1782,14 +2066,16 @@ See `load_arbitrary_tool` in `@rules_rust//rust:repositories.bzl` for more detai | Name | Description | Default Value | | :------------- | :------------- | :------------- | -| version | The version of Rust. Either "nightly", "beta", or an exact version. Defaults to a modern version. | "1.55.0" | -| iso_date | The date of the nightly or beta release (ignored if the version is a specific version). | None | -| rustfmt_version | The version of rustfmt. Either "nightly", "beta", or an exact version. Defaults to version if not specified. | None | -| edition | The rust edition to be used by default (2015, 2018 (default), or 2021) | None | -| dev_components | Whether to download the rustc-dev components (defaults to False). Requires version to be "nightly". | False | -| sha256s | A dict associating tool subdirectories to sha256 hashes. Defaults to None. | None | +| dev_components | Whether to download the rustc-dev components. | False | +| edition | The rust edition to be used by default (2015, 2018 (default), or 2021) | "2018" | | include_rustc_srcs | Whether to download rustc's src code. This is required in order to use rust-analyzer support. See [rust_toolchain_repository.include_rustc_srcs](#rust_toolchain_repository-include_rustc_srcs). for more details | False | -| urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). Defaults to ['https://static.rust-lang.org/dist/{}.tar.gz'] | ["https://static.rust-lang.org/dist/{}.tar.gz"] | +| iso_date | The date of the nightly or beta release (or None, if the version is a specific version). | None | +| prefix | The prefix used for all generated repositories. Eg. {prefix}_{repository}. | "rules_rust" | +| register_toolchains | Whether or not to register any toolchains. Setting this to false will allow for other repositories the rules depend on to get defined while allowing users to have full control over their toolchains | True | +| rustfmt_version | Same as version but is only used for rustfmt | None | +| sha256s | A dict associating tool subdirectories to sha256 hashes. | None | +| urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). | ["https://static.rust-lang.org/dist/{}.tar.gz"] | +| version | The version of Rust. Either "nightly", "beta", or an exact version. Defaults to a modern version. | "1.55.0" | @@ -1801,9 +2087,11 @@ rust_repository_set(name, rustfmt_version, edition, dev_components, sha256s, urls, auth) -Assembles a remote repository for the given toolchain params, produces a proxy repository to contain the toolchain declaration, and registers the toolchains. +A convenience macro for defining an exec toolchain and a collection of extra target toolchains. -N.B. A "proxy repository" is needed to allow for registering the toolchain (with constraints) without actually downloading the toolchain. +For more information see on what specifically is generated by this macro, see the +[rust_exec_toolchain_repository](#rust_exec_toolchain_repository) and +[rust_target_toolchain_repository](#rust_target_toolchain_repository) rules. **PARAMETERS** @@ -1821,10 +2109,51 @@ N.B. A "proxy repository" is needed to allow for registering the toolchain (with | edition | The rust edition to be used by default (2015, 2018 (if None), or 2021). | None | | dev_components | Whether to download the rustc-dev components. Requires version to be "nightly". Defaults to False. | False | | sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_repositories](#rust_repositories) for more details. | None | -| urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). Defaults to ['https://static.rust-lang.org/dist/{}.tar.gz'] | ["https://static.rust-lang.org/dist/{}.tar.gz"] | +| urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). | ["https://static.rust-lang.org/dist/{}.tar.gz"] | | auth | Auth object compatible with repository_ctx.download to use when downloading files. See https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download for more details. | None | + + +## rust_target_toolchain_repository + +
+rust_target_toolchain_repository(name, triple, allocator_library, exec_compatible_with, iso_date,
+                                 sha256s, stdlib_linkflags, target_compatible_with, urls, version)
+
+ +A repository rule for defining a [rust_target_toolchain](#rust_target_toolchain). + +This rule declares repository rules for components that may be required to build for the target platform +such as the `rust-std` artifact. The targets that represent these components are wired into the +`rust_target_toolchain` that's created which is then consumed by a `rust_toolchain` target for generating +the sysroot to use in a `Rustc` action. This rule should be used to define more customized target toolchains +than those created by `rust_repositories`. + +Tool Repositories Created: +- [rust_stdlib_repository](#rust_stdlib_repository) + +Toolchains Created: +- [rust_target_toolchain](#rust_target_toolchain) + + +**PARAMETERS** + + +| Name | Description | Default Value | +| :------------- | :------------- | :------------- | +| name | The name of the toolchain repository as well as the prefix for each individual 'tool repository'. | none | +| triple | The platform triple of the target environment. | none | +| allocator_library | Target that provides allocator functions when rust_library targets are embedded in a cc_binary. | None | +| exec_compatible_with | Optional exec constraints for the toolchain. | [] | +| iso_date | The date of the tool (or None, if the version is a specific version). | None | +| sha256s | A dict associating tool subdirectories to sha256 hashes. | None | +| stdlib_linkflags | The repository name for a rust_stdlib_repository. | None | +| target_compatible_with | Optional target constraints for the toolchain. If unset, a default will be used based on the value of triple. See @rules_rust//rust/platform:triple_mappings.bzl for more details. | None | +| urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). | ["https://static.rust-lang.org/dist/{}.tar.gz"] | +| version | The version of the tool among "nightly", "beta", or an exact version. | "1.55.0" | + + ## rust_test_suite diff --git a/docs/rust_proto.md b/docs/rust_proto.md index dfba0b2b68..4357ff0a93 100644 --- a/docs/rust_proto.md +++ b/docs/rust_proto.md @@ -253,7 +253,7 @@ See @rules_rust//proto:BUILD for examples of defining the toolchain. | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | | edition | The edition used by the generated rust source. | String | optional | "2018" | -| grpc_compile_deps | The crates the generated grpc libraries depends on. | List of labels | optional | [Label("//proto/raze:protobuf"), Label("//proto/raze:grpc"), Label("//proto/raze:tls_api"), Label("//proto/raze:tls_api_stub")] | +| grpc_compile_deps | The crates the generated grpc libraries depends on. | List of labels | optional | [Label("//proto/raze:protobuf"), Label("@rules_rust//proto/raze:grpc"), Label("@rules_rust//proto/raze:tls_api"), Label("@rules_rust//proto/raze:tls_api_stub")] | | grpc_plugin | The location of the Rust protobuf compiler plugin to generate rust gRPC stubs. | Label | optional | //proto:protoc_gen_rust_grpc | | proto_compile_deps | The crates the generated protobuf libraries depends on. | List of labels | optional | [Label("//proto/raze:protobuf")] | | proto_plugin | The location of the Rust protobuf compiler plugin used to generate rust sources. | Label | optional | //proto:protoc_gen_rust | diff --git a/docs/rust_repositories.md b/docs/rust_repositories.md index a0dc3b1a1b..8ac2915645 100644 --- a/docs/rust_repositories.md +++ b/docs/rust_repositories.md @@ -1,65 +1,136 @@ # Rust Repositories +* [rust_cargo_repository](#rust_cargo_repository) +* [rust_cargo_toolchain](#rust_cargo_toolchain) +* [rust_clippy_repository](#rust_clippy_repository) +* [rust_clippy_toolchain](#rust_clippy_toolchain) +* [rust_exec_toolchain_repository](#rust_exec_toolchain_repository) +* [rust_exec_toolchain](#rust_exec_toolchain) * [rust_repositories](#rust_repositories) * [rust_repository_set](#rust_repository_set) -* [rust_toolchain](#rust_toolchain) -* [rust_toolchain_repository](#rust_toolchain_repository) -* [rust_toolchain_repository_proxy](#rust_toolchain_repository_proxy) +* [rust_rustc_repository](#rust_rustc_repository) +* [rust_rustfmt_repository](#rust_rustfmt_repository) +* [rust_rustfmt_toolchain](#rust_rustfmt_toolchain) * [rust_stdlib_filegroup](#rust_stdlib_filegroup) +* [rust_stdlib_repository](#rust_stdlib_repository) +* [rust_target_toolchain_repository](#rust_target_toolchain_repository) +* [rust_target_toolchain](#rust_target_toolchain) +* [rust_toolchain](#rust_toolchain) - + -## rust_stdlib_filegroup +## rust_cargo_repository
-rust_stdlib_filegroup(name, srcs)
+rust_cargo_repository(name, auth, iso_date, repo_mapping, sha256, triple, urls, version)
 
-A dedicated filegroup-like rule for Rust stdlib artifacts. +A repository rule for downloading a [Cargo](https://doc.rust-lang.org/cargo/) artifact for use in a `rust_cargo_toolchain`. **ATTRIBUTES** | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this target. | Name | required | | -| srcs | The list of targets/files that are components of the rust-stdlib file group | List of labels | required | | +| name | A unique name for this repository. | Name | required | | +| auth | Auth object compatible with repository_ctx.download to use when downloading files. See https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download for more details. | Dictionary: String -> String | optional | {} | +| iso_date | The date of the tool (or None, if the version is a specific version). | String | optional | "" | +| repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<p>For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target). | Dictionary: String -> String | required | | +| sha256 | The sha256 of the cargo artifact. | String | optional | "" | +| triple | The Rust-style target that this compiler runs on | String | required | | +| urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). | List of strings | optional | ["https://static.rust-lang.org/dist/{}.tar.gz"] | +| version | The version of the tool among "nightly", "beta", or an exact version. | String | required | | - + -## rust_toolchain +## rust_cargo_toolchain + +
+rust_cargo_toolchain(name, cargo)
+
+ +Declares a [Cargo](https://doc.rust-lang.org/cargo/) toolchain for use. + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | +| cargo | The location of the cargo binary. | Label | required | | + + + + +## rust_clippy_repository + +
+rust_clippy_repository(name, auth, iso_date, repo_mapping, sha256, triple, urls, version)
+
+ +A repository rule for defining a `rust_clippy_toolchain` from the requested version of [Clippy](https://github.com/rust-lang/rust-clippy#readme) + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this repository. | Name | required | | +| auth | Auth object compatible with repository_ctx.download to use when downloading files. See https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download for more details. | Dictionary: String -> String | optional | {} | +| iso_date | The date of the tool (or None, if the version is a specific version). | String | optional | "" | +| repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<p>For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target). | Dictionary: String -> String | required | | +| sha256 | The sha256 of the clippy-driver artifact. | String | optional | "" | +| triple | The Rust-style target that this compiler runs on | String | required | | +| urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). | List of strings | optional | ["https://static.rust-lang.org/dist/{}.tar.gz"] | +| version | The version of the tool among "nightly", "beta", or an exact version. | String | required | | + + + + +## rust_clippy_toolchain + +
+rust_clippy_toolchain(name, clippy_driver)
+
+ +Declares a [Clippy](https://github.com/rust-lang/rust-clippy#readme) toolchain for use. + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | +| clippy_driver | The location of the clippy-driver binary. | Label | required | | + + + + +## rust_exec_toolchain
-rust_toolchain(name, allocator_library, binary_ext, cargo, clippy_driver, debug_info,
-               default_edition, dylib_ext, exec_triple, opt_level, os, rust_doc, rust_lib, rustc,
-               rustc_lib, rustc_srcs, rustfmt, staticlib_ext, stdlib_linkflags, target_json,
-               target_triple)
+rust_exec_toolchain(name, default_edition, iso_date, os, rustc, rustc_lib, rustc_srcs, rustdoc,
+                    triple, version)
 
-Declares a Rust toolchain for use. +Declares a Rust exec/host toolchain for use. -This is for declaring a custom toolchain, eg. for configuring a particular version of rust or supporting a new platform. +This is for declaring a custom host toolchain (as described by [The rustc book](https://doc.rust-lang.org/stable/rustc/platform-support.html)), +eg. for configuring a particular version of rust or supporting a new platform. Example: -Suppose the core rust team has ported the compiler to a new target CPU, called `cpuX`. This support can be used in Bazel by defining a new toolchain definition and declaration: +Suppose the core rust team has ported the compiler to a new target CPU, called `cpuX`. This +support can be used in Bazel by defining a new toolchain definition and declaration: ```python -load('@rules_rust//rust:toolchain.bzl', 'rust_toolchain') +load('@rules_rust//rust:toolchain.bzl', 'rust_exec_toolchain') -rust_toolchain( +rust_exec_toolchain( name = "rust_cpuX_impl", - rustc = "@rust_cpuX//:rustc", - rustc_lib = "@rust_cpuX//:rustc_lib", - rust_lib = "@rust_cpuX//:rust_lib", - rust_doc = "@rust_cpuX//:rustdoc", - binary_ext = "", - staticlib_ext = ".a", - dylib_ext = ".so", - stdlib_linkflags = ["-lpthread", "-ldl"], - os = "linux", + # see attributes... ) toolchain( @@ -67,16 +138,16 @@ toolchain( exec_compatible_with = [ "@platforms//cpu:cpuX", ], - target_compatible_with = [ - "@platforms//cpu:cpuX", - ], toolchain = ":rust_cpuX_impl", + toolchain_type = "@rules_rust//rust:exec_toolchain", ) ``` -Then, either add the label of the toolchain rule to `register_toolchains` in the WORKSPACE, or pass it to the `"--extra_toolchains"` flag for Bazel, and it will be used. +Then, either add the label of the toolchain rule to `register_toolchains` in the WORKSPACE, or pass +it to the `"--extra_toolchains"` flag for Bazel, and it will be used. -See @rules_rust//rust:repositories.bzl for examples of defining the @rust_cpuX repository with the actual binaries and libraries. +See @rules_rust//rust:repositories.bzl for examples of defining the @rust_cpuX repository +with the actual binaries and libraries. **ATTRIBUTES** @@ -84,86 +155,300 @@ See @rules_rust//rust:repositories.bzl for examples of defining the @rust_cpuX r | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this target. | Name | required | | -| allocator_library | Target that provides allocator functions when rust_library targets are embedded in a cc_binary. | Label | optional | None | -| binary_ext | The extension for binaries created from rustc. | String | required | | -| cargo | The location of the cargo binary. Can be a direct source or a filegroup containing one item. | Label | optional | None | -| clippy_driver | The location of the clippy-driver binary. Can be a direct source or a filegroup containing one item. | Label | optional | None | -| debug_info | Rustc debug info levels per opt level | Dictionary: String -> String | optional | {"dbg": "2", "fastbuild": "0", "opt": "0"} | -| default_edition | The edition to use for rust_* rules that don't specify an edition. | String | optional | "2018" | -| dylib_ext | The extension for dynamic libraries created from rustc. | String | required | | -| exec_triple | The platform triple for the toolchains execution environment. For more details see: https://docs.bazel.build/versions/master/skylark/rules.html#configurations | String | optional | "" | -| opt_level | Rustc optimization levels. | Dictionary: String -> String | optional | {"dbg": "0", "fastbuild": "0", "opt": "3"} | -| os | The operating system for the current toolchain | String | required | | -| rust_doc | The location of the rustdoc binary. Can be a direct source or a filegroup containing one item. | Label | optional | None | -| rust_lib | The rust standard library. | Label | optional | None | -| rustc | The location of the rustc binary. Can be a direct source or a filegroup containing one item. | Label | optional | None | -| rustc_lib | The libraries used by rustc during compilation. | Label | optional | None | -| rustc_srcs | The source code of rustc. | Label | optional | None | -| rustfmt | The location of the rustfmt binary. Can be a direct source or a filegroup containing one item. | Label | optional | None | -| staticlib_ext | The extension for static libraries created from rustc. | String | required | | -| stdlib_linkflags | Additional linker libs used when std lib is linked, see https://github.com/rust-lang/rust/blob/master/src/libstd/build.rs | List of strings | required | | -| target_json | Override the target_triple with a custom target specification. For more details see: https://doc.rust-lang.org/rustc/targets/custom.html | Label | optional | None | -| target_triple | The platform triple for the toolchains target environment. For more details see: https://docs.bazel.build/versions/master/skylark/rules.html#configurations | String | optional | "" | +| name | A unique name for this target. | Name | required | | +| default_edition | The edition to use for rust_* rules that don't specify an edition. | String | optional | "1.55.0" | +| iso_date | The date of the tool (or None, if the version is a specific version). | String | optional | "" | +| os | The operating system for the current toolchain | String | required | | +| rustc | The location of the rustc binary. Can be a direct source or a filegroup containing one item. | Label | required | | +| rustc_lib | The location of the rustc binary. Can be a direct source or a filegroup containing one item. | Label | required | | +| rustc_srcs | The source code of rustc. | Label | optional | None | +| rustdoc | The location of the rustdoc binary. Can be a direct source or a filegroup containing one item. | Label | optional | None | +| triple | The platform triple for the toolchains execution environment. For more details see: https://docs.bazel.build/versions/master/skylark/rules.html#configurations | String | optional | "" | +| version | The date of the tool (or None, if the version is a specific version). | String | required | | - + -## rust_toolchain_repository +## rust_rustc_repository
-rust_toolchain_repository(name, auth, dev_components, edition, exec_triple, extra_target_triples,
-                          include_rustc_srcs, iso_date, repo_mapping, rustfmt_version, sha256s,
-                          toolchain_name_prefix, urls, version)
+rust_rustc_repository(name, auth, dev_components, iso_date, repo_mapping, sha256s, triple, urls,
+                      version)
 
-Composes a single workspace containing the toolchain components for compiling on a given platform to a series of target platforms. +must be a host toolchain + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this repository. | Name | required | | +| auth | Auth object compatible with repository_ctx.download to use when downloading files. See https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download for more details. | Dictionary: String -> String | optional | {} | +| dev_components | Whether to download the rustc-dev components (defaults to False). Requires version to be "nightly". | Boolean | optional | False | +| iso_date | The date of the tool (or None, if the version is a specific version). | String | optional | "" | +| repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<p>For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target). | Dictionary: String -> String | required | | +| sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_repositories](#rust_repositories) for more details. | Dictionary: String -> String | optional | {} | +| triple | The Rust-style target that this compiler runs on | String | required | | +| urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). | List of strings | optional | ["https://static.rust-lang.org/dist/{}.tar.gz"] | +| version | The version of the tool among "nightly", "beta", or an exact version. | String | required | | + + + + +## rust_rustfmt_repository + +
+rust_rustfmt_repository(name, auth, iso_date, repo_mapping, sha256, triple, urls, version)
+
+ +A repository rule for downloading a [Rustfmt](https://github.com/rust-lang/rustfmt#readme) artifact for use in a `rust_rustfmt_toolchain`. + +**ATTRIBUTES** + -A given instance of this rule should be accompanied by a rust_toolchain_repository_proxy invocation to declare its toolchains to Bazel; the indirection allows separating toolchain selection from toolchain fetching. +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this repository. | Name | required | | +| auth | Auth object compatible with repository_ctx.download to use when downloading files. See https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download for more details. | Dictionary: String -> String | optional | {} | +| iso_date | The date of the tool (or None, if the version is a specific version). | String | optional | "" | +| repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<p>For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target). | Dictionary: String -> String | required | | +| sha256 | The sha256 of the rustfmt artifact. | String | optional | "" | +| triple | The Rust-style target that this compiler runs on | String | required | | +| urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). | List of strings | optional | ["https://static.rust-lang.org/dist/{}.tar.gz"] | +| version | The version of the tool among "nightly", "beta", or an exact version. | String | required | | + + + + +## rust_rustfmt_toolchain + +
+rust_rustfmt_toolchain(name, rustfmt)
+
+ +Declares a [Rustfmt](https://github.com/rust-lang/rustfmt#readme) toolchain for use. **ATTRIBUTES** | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this repository. | Name | required | | -| auth | Auth object compatible with repository_ctx.download to use when downloading files. See https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download for more details. | Dictionary: String -> String | optional | {} | -| dev_components | Whether to download the rustc-dev components (defaults to False). Requires version to be "nightly". | Boolean | optional | False | -| edition | The rust edition to be used by default. | String | optional | "2018" | -| exec_triple | The Rust-style target that this compiler runs on | String | required | | -| extra_target_triples | Additional rust-style targets that this set of toolchains should support. | List of strings | optional | [] | -| include_rustc_srcs | Whether to download and unpack the rustc source files. These are very large, and slow to unpack, but are required to support rust analyzer. An environment variable RULES_RUST_TOOLCHAIN_INCLUDE_RUSTC_SRCS can also be used to control this attribute. This variable will take precedence over the hard coded attribute. Setting it to true to activates this attribute where all other values deactivate it. | Boolean | optional | False | -| iso_date | The date of the tool (or None, if the version is a specific version). | String | optional | "" | -| repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<p>For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target). | Dictionary: String -> String | required | | -| rustfmt_version | The version of the tool among "nightly", "beta", or an exact version. | String | optional | "" | -| sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_repositories](#rust_repositories) for more details. | Dictionary: String -> String | optional | {} | -| toolchain_name_prefix | The per-target prefix expected for the rust_toolchain declarations in the parent workspace. | String | optional | "" | -| urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). | List of strings | optional | ["https://static.rust-lang.org/dist/{}.tar.gz"] | -| version | The version of the tool among "nightly", "beta", or an exact version. | String | required | | +| name | A unique name for this target. | Name | required | | +| rustfmt | The location of the rustfmt binary. | Label | required | | - + -## rust_toolchain_repository_proxy +## rust_stdlib_filegroup
-rust_toolchain_repository_proxy(name, exec_triple, extra_target_triples, parent_workspace_name,
-                                repo_mapping, toolchain_name_prefix)
+rust_stdlib_filegroup(name, srcs)
 
-Generates a toolchain-bearing repository that declares the toolchains from some other rust_toolchain_repository. +A dedicated filegroup-like rule for Rust stdlib artifacts. **ATTRIBUTES** | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this repository. | Name | required | | -| exec_triple | The Rust-style target triple for the compilation platform | String | required | | -| extra_target_triples | The Rust-style triples for extra compilation targets | List of strings | optional | [] | -| parent_workspace_name | The name of the other rust_toolchain_repository | String | required | | -| repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<p>For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target). | Dictionary: String -> String | required | | -| toolchain_name_prefix | The per-target prefix expected for the rust_toolchain declarations in the parent workspace. | String | optional | "" | +| name | A unique name for this target. | Name | required | | +| srcs | The list of targets/files that are components of the rust-stdlib file group | List of labels | required | | + + + + +## rust_stdlib_repository + +
+rust_stdlib_repository(name, auth, iso_date, repo_mapping, sha256s, triple, urls, version)
+
+ +A repository rule for fetching the `rust-std` ([Rust Standard Library](https://doc.rust-lang.org/std/)) artifact for the requested platform. + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this repository. | Name | required | | +| auth | Auth object compatible with repository_ctx.download to use when downloading files. See https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download for more details. | Dictionary: String -> String | optional | {} | +| iso_date | The date of the tool (or None, if the version is a specific version). | String | optional | "" | +| repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<p>For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target). | Dictionary: String -> String | required | | +| sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_repositories](#rust_repositories) for more details. | Dictionary: String -> String | optional | {} | +| triple | The Rust-style target that this compiler runs on | String | required | | +| urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). | List of strings | optional | ["https://static.rust-lang.org/dist/{}.tar.gz"] | +| version | The version of the tool among "nightly", "beta", or an exact version. | String | required | | + + + + +## rust_target_toolchain + +
+rust_target_toolchain(name, allocator_library, binary_ext, debug_info, dylib_ext, iso_date,
+                      opt_level, os, rust_stdlib, staticlib_ext, stdlib_linkflags, target_json,
+                      triple, version)
+
+ +Declares a Rust target toolchain for use. + +This is for declaring a custom toolchain which contains details about the target platform as well as +provide a `rust-std` artifact to the sysroot for targets that depend on the stardard library. + +Example: + +Suppose the core rust team has added a new platform to tier 2 support with a `rust-std` artifact called +`aarch256-raven-microcyber`. This support can be used in Bazel by defining a new toolchain definition +and declaration: + +```python +load('@rules_rust//rust:toolchain.bzl', 'rust_target_toolchain') + +rust_target_toolchain( + name = "rust_aarch256_raven_microcyber_impl", + # see attributes... +) + +toolchain( + name = "rust_aarch256_raven_microcyber", + target_compatible_with = [ + "@platforms//cpu:aarch2077", + "@platforms//os:microcyber", + ], + toolchain = ":rust_aarch256_raven_microcyber_impl", + toolchain_type = "@rules_rust//rust:target_toolchain", +) +``` + + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | +| allocator_library | Target that provides allocator functions when rust_library targets are embedded in a cc_binary. | Label | optional | None | +| binary_ext | The extension for binaries created from rustc. | String | required | | +| debug_info | Rustc debug info levels per opt level | Dictionary: String -> String | optional | {"dbg": "2", "fastbuild": "0", "opt": "0"} | +| dylib_ext | The extension for dynamic libraries created from rustc. | String | required | | +| iso_date | The date of the tool (or None, if the version is a specific version). | String | optional | "" | +| opt_level | Rustc optimization levels. | Dictionary: String -> String | optional | {"dbg": "0", "fastbuild": "0", "opt": "3"} | +| os | The operating system for the current toolchain | String | required | | +| rust_stdlib | The rust standard library. | Label | required | | +| staticlib_ext | The extension for static libraries created from rustc. | String | required | | +| stdlib_linkflags | Additional linker libs used when std lib is linked, see https://github.com/rust-lang/rust/blob/master/src/libstd/build.rs | List of strings | required | | +| target_json | Override the target_triple with a custom target specification. For more details see: https://doc.rust-lang.org/rustc/targets/custom.html | Label | optional | None | +| triple | The platform triple for the toolchains execution environment. For more details see: https://docs.bazel.build/versions/master/skylark/rules.html#configurations | String | optional | "" | +| version | The version of the tool among "nightly", "beta", or an exact version. | String | required | | + + + + +## rust_toolchain + +
+rust_toolchain(name)
+
+ +Declares a Rust exec/host + target toolchain for use. + +This takes a [rust_exec_toolchain](#rust_exec_toolchain) and a [rust_target_toolchain](#rust_target_toolchain) and creates +a [sysroot](https://doc.rust-lang.org/stable/rustc/command-line-arguments.html#--sysroot-override-the-system-root) +containing all Rust components needed to build in the execution environment for the target platform. This +toolchain allows Bazel's toolchain resolution to, on-demand, gather the necessary components to perform an action +without forcing users to generate complete sysroots for all combinations of `exec -> target(s)` expected to be +built. + +A generated sysroot is expected to look like the following: + +```text +rust/toolchain/current/ + bin/ + rustc -> ${CACHE_LOCATION}/rustc + rustdoc -> ${CACHE_LOCATION}/rustdoc + lib/ + lib*.so -> ${CACHE_LOCATION}/lib*.so + ... + rustlib/ + x86_64-unknown-linux-gnu/ + bin/ + rust-lld -> ${CACHE_LOCATION}/rust-lld + lib/ + lib*.rlib -> ${CACHE_LOCATION}/lib*.rlib + ... + rules_rust.sysroot -> ${CACHE_LOCATION}/rules_rust.sysroot +``` + +The tree above assumes that the contents of `rust_exec_toolchain` and `rust_target_toolchain` can +be directly used in the sysroot, meaning the files use the same paths from the root of their +repositories and are not expected to contain any conflicts. Though, both toolchains may provide +contents for the same directory, where above `./lib/rustlib/x86_64-unknown-linux-gnu` contains a +`bin` directory from the exec toolchain and a `lib` directory from the target toolchain. + + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | + + + + +## rust_exec_toolchain_repository + +
+rust_exec_toolchain_repository(name, triple, dev_components, edition, exec_compatible_with,
+                               include_rustc_srcs, iso_date, rustfmt_iso_date, rustfmt_version,
+                               sha256s, target_compatible_with, urls, version)
+
+ +A repository rule for defining a [rust_exec_toolchain](#rust_exec_toolchain). + +This repository rule generates repositories for host tools (as described by [The rustc book][trc]) and wires +them into a `rust_exec_toolchain` target. Note that the `rust_exec_toolchain` only includes `rustc` and it's +dependencies. Additional host tools such as `Cargo`, `Clippy`, and `Rustfmt` are all declared as separate +toolchains. This rule should be used to define more customized exec toolchains than those created by +`rust_repositories`. + +Tool Repositories Created: +- [rust_cargo_repository](#rust_cargo_repository) +- [rust_clippy_repository](#rust_clippy_repository) +- [rust_rustc_repository](#rust_rustc_repository) +- [rust_rustfmt_repository](#rust_rustfmt_repository) +- [rust_srcs_repository](#rust_srcs_repository) + +Toolchains Created: +- [rust_exec_toolchain](#rust_exec_toolchain) +- [rust_cargo_toolchain](#rust_cargo_toolchain) +- [rust_clippy_toolchain](#rust_clippy_toolchain) +- [rust_rustfmt_toolchain](#rust_rustfmt_toolchain) + + +[trc]: https://doc.rust-lang.org/stable/rustc/platform-support.html + + +**PARAMETERS** + + +| Name | Description | Default Value | +| :------------- | :------------- | :------------- | +| name | The name of the toolchain repository as well as the prefix for each individual 'tool repository'. | none | +| triple | The platform triple of the execution environment. | none | +| dev_components | [description]. Defaults to False. | False | +| edition | The rust edition to be used by default. | "2018" | +| exec_compatible_with | Optional exec constraints for the toolchain. If unset, a default will be used based on the value of triple. See @rules_rust//rust/platform:triple_mappings.bzl for more details. | None | +| include_rustc_srcs | Whether to download and unpack the rustc source files. These are very large, and slow to unpack, but are required to support rust analyzer. | False | +| iso_date | The date of the tool (or None, if the version is a specific version). | None | +| rustfmt_iso_date | Similar to iso_date but specific to Rustfmt. If unspecified, iso_date will be used. | None | +| rustfmt_version | Similar to version but specific to Rustfmt. If unspecified, version will be used. | None | +| sha256s | A dict associating tool subdirectories to sha256 hashes. | None | +| target_compatible_with | Optional target constraints for the toolchain. | [] | +| urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). | ["https://static.rust-lang.org/dist/{}.tar.gz"] | +| version | The version of the tool among "nightly", "beta", or an exact version. | "1.55.0" | @@ -171,13 +456,15 @@ Generates a toolchain-bearing repository that declares the toolchains from some ## rust_repositories
-rust_repositories(version, iso_date, rustfmt_version, edition, dev_components, sha256s,
-                  include_rustc_srcs, urls)
+rust_repositories(dev_components, edition, include_rustc_srcs, iso_date, prefix,
+                  register_toolchains, rustfmt_version, sha256s, urls, version)
 
-Emits a default set of toolchains for Linux, MacOS, and Freebsd +Instantiate repositories and toolchains required by `rules_rust`. -Skip this macro and call the `rust_repository_set` macros directly if you need a compiler for other hosts or for additional target triples. +Skip this macro and call the [rust_exec_toolchain_repository](#rust_exec_toolchain_repository) or +[rust_target_toolchain_repository](#rust_target_toolchain_repository) rules directly if you need a +compiler for other hosts or for additional target triples. The `sha256` attribute represents a dict associating tool subdirectories to sha256 hashes. As an example: ```python @@ -187,9 +474,6 @@ The `sha256` attribute represents a dict associating tool subdirectories to sha2 "rust-std-1.46.0-x86_64-unknown-linux-gnu": "ac04aef80423f612c0079829b504902de27a6997214eb58ab0765d02f7ec1dbc", } ``` -This would match for `exec_triple = "x86_64-unknown-linux-gnu"`. If not specified, rules_rust pulls from a non-exhaustive list of known checksums.. - -See `load_arbitrary_tool` in `@rules_rust//rust:repositories.bzl` for more details. **PARAMETERS** @@ -197,14 +481,16 @@ See `load_arbitrary_tool` in `@rules_rust//rust:repositories.bzl` for more detai | Name | Description | Default Value | | :------------- | :------------- | :------------- | -| version | The version of Rust. Either "nightly", "beta", or an exact version. Defaults to a modern version. | "1.55.0" | -| iso_date | The date of the nightly or beta release (ignored if the version is a specific version). | None | -| rustfmt_version | The version of rustfmt. Either "nightly", "beta", or an exact version. Defaults to version if not specified. | None | -| edition | The rust edition to be used by default (2015, 2018 (default), or 2021) | None | -| dev_components | Whether to download the rustc-dev components (defaults to False). Requires version to be "nightly". | False | -| sha256s | A dict associating tool subdirectories to sha256 hashes. Defaults to None. | None | +| dev_components | Whether to download the rustc-dev components. | False | +| edition | The rust edition to be used by default (2015, 2018 (default), or 2021) | "2018" | | include_rustc_srcs | Whether to download rustc's src code. This is required in order to use rust-analyzer support. See [rust_toolchain_repository.include_rustc_srcs](#rust_toolchain_repository-include_rustc_srcs). for more details | False | -| urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). Defaults to ['https://static.rust-lang.org/dist/{}.tar.gz'] | ["https://static.rust-lang.org/dist/{}.tar.gz"] | +| iso_date | The date of the nightly or beta release (or None, if the version is a specific version). | None | +| prefix | The prefix used for all generated repositories. Eg. {prefix}_{repository}. | "rules_rust" | +| register_toolchains | Whether or not to register any toolchains. Setting this to false will allow for other repositories the rules depend on to get defined while allowing users to have full control over their toolchains | True | +| rustfmt_version | Same as version but is only used for rustfmt | None | +| sha256s | A dict associating tool subdirectories to sha256 hashes. | None | +| urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). | ["https://static.rust-lang.org/dist/{}.tar.gz"] | +| version | The version of Rust. Either "nightly", "beta", or an exact version. Defaults to a modern version. | "1.55.0" | @@ -216,9 +502,11 @@ rust_repository_set(name, rustfmt_version, edition, dev_components, sha256s, urls, auth) -Assembles a remote repository for the given toolchain params, produces a proxy repository to contain the toolchain declaration, and registers the toolchains. +A convenience macro for defining an exec toolchain and a collection of extra target toolchains. -N.B. A "proxy repository" is needed to allow for registering the toolchain (with constraints) without actually downloading the toolchain. +For more information see on what specifically is generated by this macro, see the +[rust_exec_toolchain_repository](#rust_exec_toolchain_repository) and +[rust_target_toolchain_repository](#rust_target_toolchain_repository) rules. **PARAMETERS** @@ -236,7 +524,48 @@ N.B. A "proxy repository" is needed to allow for registering the toolchain (with | edition | The rust edition to be used by default (2015, 2018 (if None), or 2021). | None | | dev_components | Whether to download the rustc-dev components. Requires version to be "nightly". Defaults to False. | False | | sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_repositories](#rust_repositories) for more details. | None | -| urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). Defaults to ['https://static.rust-lang.org/dist/{}.tar.gz'] | ["https://static.rust-lang.org/dist/{}.tar.gz"] | +| urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). | ["https://static.rust-lang.org/dist/{}.tar.gz"] | | auth | Auth object compatible with repository_ctx.download to use when downloading files. See https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download for more details. | None | + + +## rust_target_toolchain_repository + +
+rust_target_toolchain_repository(name, triple, allocator_library, exec_compatible_with, iso_date,
+                                 sha256s, stdlib_linkflags, target_compatible_with, urls, version)
+
+ +A repository rule for defining a [rust_target_toolchain](#rust_target_toolchain). + +This rule declares repository rules for components that may be required to build for the target platform +such as the `rust-std` artifact. The targets that represent these components are wired into the +`rust_target_toolchain` that's created which is then consumed by a `rust_toolchain` target for generating +the sysroot to use in a `Rustc` action. This rule should be used to define more customized target toolchains +than those created by `rust_repositories`. + +Tool Repositories Created: +- [rust_stdlib_repository](#rust_stdlib_repository) + +Toolchains Created: +- [rust_target_toolchain](#rust_target_toolchain) + + +**PARAMETERS** + + +| Name | Description | Default Value | +| :------------- | :------------- | :------------- | +| name | The name of the toolchain repository as well as the prefix for each individual 'tool repository'. | none | +| triple | The platform triple of the target environment. | none | +| allocator_library | Target that provides allocator functions when rust_library targets are embedded in a cc_binary. | None | +| exec_compatible_with | Optional exec constraints for the toolchain. | [] | +| iso_date | The date of the tool (or None, if the version is a specific version). | None | +| sha256s | A dict associating tool subdirectories to sha256 hashes. | None | +| stdlib_linkflags | The repository name for a rust_stdlib_repository. | None | +| target_compatible_with | Optional target constraints for the toolchain. If unset, a default will be used based on the value of triple. See @rules_rust//rust/platform:triple_mappings.bzl for more details. | None | +| urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). | ["https://static.rust-lang.org/dist/{}.tar.gz"] | +| version | The version of the tool among "nightly", "beta", or an exact version. | "1.55.0" | + +