From 99721c47e9127af7505961f07063012287f91af9 Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Sat, 26 Jun 2021 10:45:57 -0700 Subject: [PATCH 1/7] `create_universe` no longer assumes the name of rust_repository repos --- crate_universe/bootstrap.bzl | 22 ++++--- crate_universe/defs.bzl | 29 ++++++--- crate_universe/private/util.bzl | 62 +++++++++++++++---- .../has_aliased_deps/Cargo.toml | 1 + 4 files changed, 86 insertions(+), 28 deletions(-) diff --git a/crate_universe/bootstrap.bzl b/crate_universe/bootstrap.bzl index d755b7d59a..0977815e43 100644 --- a/crate_universe/bootstrap.bzl +++ b/crate_universe/bootstrap.bzl @@ -1,6 +1,8 @@ """A module for declaraing a repository for bootstrapping crate_universe""" -load("//crate_universe/private:util.bzl", "get_host_info") +load("//crate_universe/private:util.bzl", "get_cargo_and_rustc", "get_host_triple") +load("//rust:repositories.bzl", "DEFAULT_RUST_VERSION") +load("//rust/platform:triple_mappings.bzl", "system_to_binary_ext", "triple_to_system") BOOTSTRAP_ENV_VAR = "RULES_RUST_CRATE_UNIVERSE_BOOTSTRAP" @@ -35,16 +37,15 @@ def _crate_universe_resolver_bootstrapping_impl(repository_ctx): repository_ctx.file("BUILD.bazel") return - resolver_triple, toolchain_repo, extension = get_host_info(repository_ctx) - - cargo_path = repository_ctx.path(Label(toolchain_repo + "//:bin/cargo" + extension)) - rustc_path = repository_ctx.path(Label(toolchain_repo + "//:bin/rustc" + extension)) + host_triple, _ = get_host_triple(repository_ctx) + tools = get_cargo_and_rustc(repository_ctx, host_triple) + extension = system_to_binary_ext(triple_to_system(host_triple)) repository_dir = repository_ctx.path(".") resolver_path = repository_ctx.path("release/crate_universe_resolver" + extension) args = [ - cargo_path, + tools.cargo, "build", "--release", "--locked", @@ -58,7 +59,7 @@ def _crate_universe_resolver_bootstrapping_impl(repository_ctx): result = repository_ctx.execute( args, environment = { - "RUSTC": str(rustc_path), + "RUSTC": str(tools.rustc), }, quiet = False, ) @@ -88,11 +89,18 @@ _crate_universe_resolver_bootstrapping = repository_rule( allow_single_file = ["Cargo.toml"], default = Label("//crate_universe:Cargo.toml"), ), + "iso_date": attr.string( + doc = "The iso_date of cargo binary the resolver should use. Note `version` must be `beta` or `nightly`", + ), "srcs": attr.label( doc = "Souces to the crate_universe resolver", allow_files = True, default = Label("//crate_universe:resolver_srcs"), ), + "version": attr.string( + doc = "The version of cargo the resolver should use", + default = DEFAULT_RUST_VERSION, + ), }, environ = [BOOTSTRAP_ENV_VAR], ) diff --git a/crate_universe/defs.bzl b/crate_universe/defs.bzl index 93c3155e9d..03c8c08dd1 100644 --- a/crate_universe/defs.bzl +++ b/crate_universe/defs.bzl @@ -1,8 +1,9 @@ """A module defining the `crate_universe` rule""" load("//crate_universe/private:defaults.bzl", "DEFAULT_SHA256_CHECKSUMS", "DEFAULT_URL_TEMPLATE") -load("//crate_universe/private:util.bzl", "get_host_info") -load("//rust:repositories.bzl", "DEFAULT_TOOLCHAIN_TRIPLES") +load("//crate_universe/private:util.bzl", "get_cargo_and_rustc", "get_host_triple") +load("//rust:repositories.bzl", "DEFAULT_RUST_VERSION", "DEFAULT_TOOLCHAIN_TRIPLES") +load("//rust/platform:triple_mappings.bzl", "system_to_binary_ext", "triple_to_system") load(":bootstrap.bzl", "BOOTSTRAP_ENV_VAR") DEFAULT_CRATE_REGISTRY_TEMPLATE = "https://crates.io/api/v1/crates/{crate}/{version}/download" @@ -64,11 +65,9 @@ def _crate_universe_resolve_impl(repository_ctx): - The user then calls defs.bzl%pinned_rust_install(). """ - # Get info about the current host's tool locations - resolver_triple, toolchain_repo, extension = get_host_info(repository_ctx) - - cargo_path = repository_ctx.path(Label(toolchain_repo + "//:bin/cargo" + extension)) - rustc_path = repository_ctx.path(Label(toolchain_repo + "//:bin/rustc" + extension)) + host_triple, resolver_triple = get_host_triple(repository_ctx) + tools = get_cargo_and_rustc(repository_ctx, host_triple) + extension = system_to_binary_ext(triple_to_system(host_triple)) if BOOTSTRAP_ENV_VAR in repository_ctx.os.environ and not "RULES_RUST_CRATE_UNIVERSE_RESOLVER_URL_OVERRIDE" in repository_ctx.os.environ: resolver_label = Label("@rules_rust_crate_universe_bootstrap//:release/crate_universe_resolver" + extension) @@ -108,7 +107,7 @@ def _crate_universe_resolve_impl(repository_ctx): overrides = repository_ctx.attr.overrides, registry_template = repository_ctx.attr.crate_registry_template, targets = repository_ctx.attr.supported_targets, - cargo_bin_path = cargo_path, + cargo_bin_path = tools.cargo, ) input_path = "{name}.resolver_config.json".format(name = repository_ctx.attr.name) @@ -135,8 +134,8 @@ def _crate_universe_resolve_impl(repository_ctx): environment = { # The resolver invokes `cargo metadata` which relies on `rustc` being on the $PATH # See https://github.com/rust-lang/cargo/issues/8219 - "CARGO": str(cargo_path), - "RUSTC": str(rustc_path), + "CARGO": str(tools.cargo), + "RUSTC": str(tools.rustc), "RUST_LOG": "info", }, quiet = False, @@ -169,6 +168,9 @@ Environment Variables: doc = "A template for where to download crates from for the default crate registry. This must contain `{version}` and `{crate}` templates.", default = DEFAULT_CRATE_REGISTRY_TEMPLATE, ), + "iso_date": attr.string( + doc = "The iso_date of cargo binary the resolver should use. Note `version` must be `beta` or `nightly`", + ), "lockfile": attr.label( doc = ( "The path to a file which stores pinned information about the generated dependency graph. " + @@ -200,6 +202,9 @@ Environment Variables: doc = "Dictionary of host_triple -> sha256 for resolver binary.", default = DEFAULT_SHA256_CHECKSUMS, ), + "sha256s": attr.string_dict( + doc = "The sha256 checksum of the desired rust artifacts", + ), "supported_targets": attr.string_list( doc = ( "A list of supported [platform triples](https://doc.rust-lang.org/nightly/rustc/platform-support.html) " + @@ -208,6 +213,10 @@ Environment Variables: allow_empty = False, default = DEFAULT_TOOLCHAIN_TRIPLES.keys(), ), + "version": attr.string( + doc = "The version of cargo the resolver should use", + default = DEFAULT_RUST_VERSION, + ), }, environ = [ "REPIN", diff --git a/crate_universe/private/util.bzl b/crate_universe/private/util.bzl index bb95deb78f..b3e316ffc9 100644 --- a/crate_universe/private/util.bzl +++ b/crate_universe/private/util.bzl @@ -1,5 +1,8 @@ """Utility functions for the crate_universe resolver""" +load("//rust:repositories.bzl", "load_arbitrary_tool") +load("//rust/platform:triple_mappings.bzl", "system_to_binary_ext", "triple_to_system") + _CPU_ARCH_ERROR_MSG = """\ Command failed with exit code '{code}': {args} ----------stdout: @@ -61,14 +64,14 @@ def _query_cpu_architecture(repository_ctx, expected_archs, is_windows = False): return arch -def get_host_info(repository_ctx): - """Query host information for the appropriate triple and toolchain repo name +def get_host_triple(repository_ctx): + """Query host information for the appropriate triples for the crate_universe resolver Args: repository_ctx (repository_ctx): The rule's repository_ctx Returns: - tuple: A tuple containing a triple (str) and repository name (str) + tuple: The host triple and resolver triple """ # Detect the host's cpu architecture @@ -79,23 +82,60 @@ def get_host_info(repository_ctx): "windows": ["x86_64"], } - # The expected file extension of crate resolver binaries - extension = "" - if "linux" in repository_ctx.os.name: cpu = _query_cpu_architecture(repository_ctx, supported_architectures["linux"]) + host_triple = "{}-unknown-linux-gnu".format(cpu) resolver_triple = "{}-unknown-linux-gnu".format(cpu) - toolchain_repo = "@rust_linux_{}".format(cpu) elif "mac" in repository_ctx.os.name: cpu = _query_cpu_architecture(repository_ctx, supported_architectures["macos"]) + host_triple = "{}-apple-darwin".format(cpu) resolver_triple = "{}-apple-darwin".format(cpu) - toolchain_repo = "@rust_darwin_{}".format(cpu) elif "win" in repository_ctx.os.name: cpu = _query_cpu_architecture(repository_ctx, supported_architectures["windows"], True) + + # TODO: The resolver triple should be the same as the host but for the time being, + # the resolver is compiled with `-gnu` not `-msvc`. + host_triple = "{}-pc-windows-msvc".format(cpu) resolver_triple = "{}-pc-windows-gnu".format(cpu) - toolchain_repo = "@rust_windows_{}".format(cpu) - extension = ".exe" else: fail("Could not locate resolver for OS " + repository_ctx.os.name) - return (resolver_triple, toolchain_repo, extension) + return (host_triple, resolver_triple) + +def get_cargo_and_rustc(repository_ctx, host_triple): + """Download a cargo and rustc binary based on the host triple. + + Args: + repository_ctx (repository_ctx): The rule's context object + host_triple (str): The host's platform triple + + Returns: + struct: A struct containing the expected tools + """ + + if repository_ctx.attr.version in ("beta", "nightly"): + iso_date = repository_ctx.attr.iso_date + else: + iso_date = None + + # Get info about the current host's tool locations + (host_triple, resolver_triple) = get_host_triple(repository_ctx) + extension = system_to_binary_ext(triple_to_system(host_triple)) + + # Fetch all required rust components + load_arbitrary_tool( + repository_ctx, + iso_date = iso_date, + target_triple = host_triple, + tool_name = "rust", + tool_subdirectories = ["rustc", "cargo", "rust-std-" + host_triple], + version = repository_ctx.attr.version, + ) + + cargo_path = repository_ctx.path("bin/cargo" + extension) + rustc_path = repository_ctx.path("bin/rustc" + extension) + + return struct( + cargo = cargo_path, + rustc = rustc_path, + ) diff --git a/examples/crate_universe/has_aliased_deps/Cargo.toml b/examples/crate_universe/has_aliased_deps/Cargo.toml index d867d884c5..b05f588ac1 100644 --- a/examples/crate_universe/has_aliased_deps/Cargo.toml +++ b/examples/crate_universe/has_aliased_deps/Cargo.toml @@ -6,3 +6,4 @@ edition = "2018" [dependencies] reqwest = { version = "0.10.7", features = ["blocking", "json"] } +indexmap = { version = "1.5.2", features = ["std"] } From 33b7c9578ed3f926ba23d62f4dc7a5ddb22dfb8e Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Sat, 26 Jun 2021 10:47:32 -0700 Subject: [PATCH 2/7] Regenerate documentation --- docs/crate_universe.md | 8 ++++++-- docs/flatten.md | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/crate_universe.md b/docs/crate_universe.md index 78baf2444a..a564058f57 100644 --- a/docs/crate_universe.md +++ b/docs/crate_universe.md @@ -9,8 +9,9 @@ ## crate_universe
-crate_universe(name, cargo_toml_files, crate_registry_template, lockfile, overrides, packages,
-               repo_mapping, resolver_download_url_template, resolver_sha256s, supported_targets)
+crate_universe(name, cargo_toml_files, crate_registry_template, iso_date, lockfile, overrides,
+               packages, repo_mapping, resolver_download_url_template, resolver_sha256s, sha256s,
+               supported_targets, version)
 
A rule for downloading Rust dependencies (crates). @@ -33,13 +34,16 @@ Environment Variables: | name | A unique name for this repository. | Name | required | | | cargo_toml_files | A list of Cargo manifests (Cargo.toml files). | List of labels | optional | [] | | crate_registry_template | A template for where to download crates from for the default crate registry. This must contain {version} and {crate} templates. | String | optional | "https://crates.io/api/v1/crates/{crate}/{version}/download" | +| iso_date | The iso_date of cargo binary the resolver should use. Note version must be beta or nightly | String | optional | "" | | lockfile | The path to a file which stores pinned information about the generated dependency graph. this target must be a file and will be updated by the repository rule when the REPIN environment variable is set. If this is not set, dependencies will be re-resolved more often, setting this allows caching resolves, but will error if the cache is stale. | Label | optional | None | | overrides | Mapping of crate name to specification overrides. See [crate.override](#crateoverride) for more details. | Dictionary: String -> String | optional | {} | | packages | A list of crate specifications. See [crate.spec](#cratespec) for more details. | List of strings | 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 | | | 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}"} | +| 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.53.0" | diff --git a/docs/flatten.md b/docs/flatten.md index 2ac69dcbe0..8d47e3bcaa 100644 --- a/docs/flatten.md +++ b/docs/flatten.md @@ -42,8 +42,9 @@ ## crate_universe
-crate_universe(name, cargo_toml_files, crate_registry_template, lockfile, overrides, packages,
-               repo_mapping, resolver_download_url_template, resolver_sha256s, supported_targets)
+crate_universe(name, cargo_toml_files, crate_registry_template, iso_date, lockfile, overrides,
+               packages, repo_mapping, resolver_download_url_template, resolver_sha256s, sha256s,
+               supported_targets, version)
 
A rule for downloading Rust dependencies (crates). @@ -66,13 +67,16 @@ Environment Variables: | name | A unique name for this repository. | Name | required | | | cargo_toml_files | A list of Cargo manifests (Cargo.toml files). | List of labels | optional | [] | | crate_registry_template | A template for where to download crates from for the default crate registry. This must contain {version} and {crate} templates. | String | optional | "https://crates.io/api/v1/crates/{crate}/{version}/download" | +| iso_date | The iso_date of cargo binary the resolver should use. Note version must be beta or nightly | String | optional | "" | | lockfile | The path to a file which stores pinned information about the generated dependency graph. this target must be a file and will be updated by the repository rule when the REPIN environment variable is set. If this is not set, dependencies will be re-resolved more often, setting this allows caching resolves, but will error if the cache is stale. | Label | optional | None | | overrides | Mapping of crate name to specification overrides. See [crate.override](#crateoverride) for more details. | Dictionary: String -> String | optional | {} | | packages | A list of crate specifications. See [crate.spec](#cratespec) for more details. | List of strings | 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 | | | 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}"} | +| 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.53.0" | From c900f53f34adac2e404e2c94ba3c14f86a9fea40 Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Tue, 29 Jun 2021 11:17:27 -0700 Subject: [PATCH 3/7] Continue to use existing toolchain repositories --- crate_universe/bootstrap.bzl | 8 +++++++ crate_universe/defs.bzl | 8 +++++++ crate_universe/private/util.bzl | 38 ++++++++++++++++--------------- rust/platform/triple_mappings.bzl | 18 +++++++++++++++ rust/private/repository_utils.bzl | 8 ------- 5 files changed, 54 insertions(+), 26 deletions(-) diff --git a/crate_universe/bootstrap.bzl b/crate_universe/bootstrap.bzl index 0977815e43..6102d6b2e6 100644 --- a/crate_universe/bootstrap.bzl +++ b/crate_universe/bootstrap.bzl @@ -92,6 +92,14 @@ _crate_universe_resolver_bootstrapping = repository_rule( "iso_date": attr.string( doc = "The iso_date of cargo binary the resolver should use. Note `version` must be `beta` or `nightly`", ), + "rust_toolchain_repository_template": attr.string( + doc = ( + "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." + ), + default = "rust_{system}_{arch}", + ), "srcs": attr.label( doc = "Souces to the crate_universe resolver", allow_files = True, diff --git a/crate_universe/defs.bzl b/crate_universe/defs.bzl index 03c8c08dd1..2ba92a5f6f 100644 --- a/crate_universe/defs.bzl +++ b/crate_universe/defs.bzl @@ -202,6 +202,14 @@ Environment Variables: doc = "Dictionary of host_triple -> sha256 for resolver binary.", default = DEFAULT_SHA256_CHECKSUMS, ), + "rust_toolchain_repository_template": attr.string( + doc = ( + "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." + ), + default = "rust_{system}_{arch}", + ), "sha256s": attr.string_dict( doc = "The sha256 checksum of the desired rust artifacts", ), diff --git a/crate_universe/private/util.bzl b/crate_universe/private/util.bzl index b3e316ffc9..0c9ade2300 100644 --- a/crate_universe/private/util.bzl +++ b/crate_universe/private/util.bzl @@ -1,7 +1,11 @@ """Utility functions for the crate_universe resolver""" -load("//rust:repositories.bzl", "load_arbitrary_tool") -load("//rust/platform:triple_mappings.bzl", "system_to_binary_ext", "triple_to_system") +load( + "//rust/platform:triple_mappings.bzl", + "system_to_binary_ext", + "triple_to_arch", + "triple_to_system", +) _CPU_ARCH_ERROR_MSG = """\ Command failed with exit code '{code}': {args} @@ -114,26 +118,24 @@ def get_cargo_and_rustc(repository_ctx, host_triple): """ if repository_ctx.attr.version in ("beta", "nightly"): - iso_date = repository_ctx.attr.iso_date + version_str = "{}-{}".format(repository_ctx.attr.version, repository_ctx.attr.iso_date) else: - iso_date = None + version_str = repository_ctx.attr.version # Get info about the current host's tool locations (host_triple, resolver_triple) = get_host_triple(repository_ctx) - extension = system_to_binary_ext(triple_to_system(host_triple)) - - # Fetch all required rust components - load_arbitrary_tool( - repository_ctx, - iso_date = iso_date, - target_triple = host_triple, - tool_name = "rust", - tool_subdirectories = ["rustc", "cargo", "rust-std-" + host_triple], - version = repository_ctx.attr.version, - ) - - cargo_path = repository_ctx.path("bin/cargo" + extension) - rustc_path = repository_ctx.path("bin/rustc" + extension) + system = triple_to_system(host_triple) + extension = system_to_binary_ext(system) + arch = triple_to_arch(host_triple) + + rust_toolchain_repository = repository_ctx.attr.rust_toolchain_repository_template + rust_toolchain_repository = rust_toolchain_repository.replace("{version}", version_str) + rust_toolchain_repository = rust_toolchain_repository.replace("{system}", system) + rust_toolchain_repository = rust_toolchain_repository.replace("{triple}", host_triple) + rust_toolchain_repository = rust_toolchain_repository.replace("{arch}", arch) + + cargo_path = repository_ctx.path(Label("@{}{}".format(rust_toolchain_repository, "//:bin/cargo" + extension))) + rustc_path = repository_ctx.path(Label("@{}{}".format(rust_toolchain_repository, "//:bin/rustc" + extension))) return struct( cargo = cargo_path, diff --git a/rust/platform/triple_mappings.bzl b/rust/platform/triple_mappings.bzl index 8870c7fd6c..f3f666a47f 100644 --- a/rust/platform/triple_mappings.bzl +++ b/rust/platform/triple_mappings.bzl @@ -164,6 +164,24 @@ def triple_to_system(triple): return component_parts[2] +def triple_to_arch(triple): + """Returns a system architecture name for a given platform triple + + Args: + triple (str): A platform triple. eg: `x86_64-unknown-linux-gnu` + + Returns: + str: A cpu architecture + """ + if triple == "wasm32-wasi": + return "wasi" + + component_parts = triple.split("-") + if len(component_parts) < 3: + fail("Expected target triple to contain at least three sections separated by '-'") + + return component_parts[0] + def system_to_dylib_ext(system): return _SYSTEM_TO_DYLIB_EXT[system] diff --git a/rust/private/repository_utils.bzl b/rust/private/repository_utils.bzl index 8a1461d894..1560006afa 100644 --- a/rust/private/repository_utils.bzl +++ b/rust/private/repository_utils.bzl @@ -13,14 +13,6 @@ load( DEFAULT_TOOLCHAIN_NAME_PREFIX = "toolchain_for" DEFAULT_STATIC_RUST_URL_TEMPLATES = ["https://static.rust-lang.org/dist/{}.tar.gz"] -DEFAULT_TOOLCHAIN_TRIPLES = { - "aarch64-apple-darwin": "rust_darwin_aarch64", - "aarch64-unknown-linux-gnu": "rust_linux_aarch64", - "x86_64-apple-darwin": "rust_darwin_x86_64", - "x86_64-pc-windows-msvc": "rust_windows_x86_64", - "x86_64-unknown-freebsd": "rust_freebsd_x86_64", - "x86_64-unknown-linux-gnu": "rust_linux_x86_64", -} _build_file_for_compiler_template = """\ load("@rules_rust//rust:toolchain.bzl", "rust_toolchain") From 79e3b35d30db62096874352a4cfb266885a6686b Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Tue, 29 Jun 2021 11:20:08 -0700 Subject: [PATCH 4/7] Regenerate documentation --- docs/crate_universe.md | 5 +++-- docs/flatten.md | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/crate_universe.md b/docs/crate_universe.md index a564058f57..1c37e1174b 100644 --- a/docs/crate_universe.md +++ b/docs/crate_universe.md @@ -10,8 +10,8 @@
 crate_universe(name, cargo_toml_files, crate_registry_template, iso_date, lockfile, overrides,
-               packages, repo_mapping, resolver_download_url_template, resolver_sha256s, sha256s,
-               supported_targets, version)
+               packages, repo_mapping, resolver_download_url_template, resolver_sha256s,
+               rust_toolchain_repository_template, sha256s, supported_targets, version)
 
A rule for downloading Rust dependencies (crates). @@ -41,6 +41,7 @@ Environment Variables: | 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 | | | 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}" | | 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.53.0" | diff --git a/docs/flatten.md b/docs/flatten.md index 8d47e3bcaa..8c0e934ca1 100644 --- a/docs/flatten.md +++ b/docs/flatten.md @@ -43,8 +43,8 @@
 crate_universe(name, cargo_toml_files, crate_registry_template, iso_date, lockfile, overrides,
-               packages, repo_mapping, resolver_download_url_template, resolver_sha256s, sha256s,
-               supported_targets, version)
+               packages, repo_mapping, resolver_download_url_template, resolver_sha256s,
+               rust_toolchain_repository_template, sha256s, supported_targets, version)
 
A rule for downloading Rust dependencies (crates). @@ -74,6 +74,7 @@ Environment Variables: | 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 | | | 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}" | | 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.53.0" | From 4d3d8b6e394221baa1f73e9d62c50b99a539f300 Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Tue, 29 Jun 2021 11:25:42 -0700 Subject: [PATCH 5/7] Update crate_universe/bootstrap.bzl Co-authored-by: Daniel Wagner-Hall --- crate_universe/bootstrap.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crate_universe/bootstrap.bzl b/crate_universe/bootstrap.bzl index 6102d6b2e6..690d0cc115 100644 --- a/crate_universe/bootstrap.bzl +++ b/crate_universe/bootstrap.bzl @@ -90,7 +90,7 @@ _crate_universe_resolver_bootstrapping = repository_rule( default = Label("//crate_universe:Cargo.toml"), ), "iso_date": attr.string( - doc = "The iso_date of cargo binary the resolver should use. Note `version` must be `beta` or `nightly`", + doc = "The iso_date of cargo binary the resolver should use. Note: This can only be set if `version` is `beta` or `nightly`", ), "rust_toolchain_repository_template": attr.string( doc = ( From 80c4e1cd34c543d636f75071340e83fcc9529c6a Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Tue, 29 Jun 2021 11:26:29 -0700 Subject: [PATCH 6/7] Apply suggestions from code review Co-authored-by: Daniel Wagner-Hall --- crate_universe/defs.bzl | 2 +- crate_universe/private/util.bzl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crate_universe/defs.bzl b/crate_universe/defs.bzl index 2ba92a5f6f..ef05eb0db8 100644 --- a/crate_universe/defs.bzl +++ b/crate_universe/defs.bzl @@ -169,7 +169,7 @@ Environment Variables: default = DEFAULT_CRATE_REGISTRY_TEMPLATE, ), "iso_date": attr.string( - doc = "The iso_date of cargo binary the resolver should use. Note `version` must be `beta` or `nightly`", + doc = "The iso_date of cargo binary the resolver should use. Note: This can only be set if `version` is `beta` or `nightly`", ), "lockfile": attr.label( doc = ( diff --git a/crate_universe/private/util.bzl b/crate_universe/private/util.bzl index 0c9ade2300..ca6411637c 100644 --- a/crate_universe/private/util.bzl +++ b/crate_universe/private/util.bzl @@ -107,7 +107,7 @@ def get_host_triple(repository_ctx): return (host_triple, resolver_triple) def get_cargo_and_rustc(repository_ctx, host_triple): - """Download a cargo and rustc binary based on the host triple. + """Retrieve a cargo and rustc binary based on the host triple. Args: repository_ctx (repository_ctx): The rule's context object From 387bf8e17f22e7cfcac52a078f493ac6a6db2174 Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Tue, 29 Jun 2021 11:26:50 -0700 Subject: [PATCH 7/7] Regenerate documentation --- docs/crate_universe.md | 2 +- docs/flatten.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/crate_universe.md b/docs/crate_universe.md index 1c37e1174b..e1e5a203f5 100644 --- a/docs/crate_universe.md +++ b/docs/crate_universe.md @@ -34,7 +34,7 @@ Environment Variables: | name | A unique name for this repository. | Name | required | | | cargo_toml_files | A list of Cargo manifests (Cargo.toml files). | List of labels | optional | [] | | crate_registry_template | A template for where to download crates from for the default crate registry. This must contain {version} and {crate} templates. | String | optional | "https://crates.io/api/v1/crates/{crate}/{version}/download" | -| iso_date | The iso_date of cargo binary the resolver should use. Note version must be beta or nightly | 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 | "" | | lockfile | The path to a file which stores pinned information about the generated dependency graph. this target must be a file and will be updated by the repository rule when the REPIN environment variable is set. If this is not set, dependencies will be re-resolved more often, setting this allows caching resolves, but will error if the cache is stale. | Label | optional | None | | overrides | Mapping of crate name to specification overrides. See [crate.override](#crateoverride) for more details. | Dictionary: String -> String | optional | {} | | packages | A list of crate specifications. See [crate.spec](#cratespec) for more details. | List of strings | optional | [] | diff --git a/docs/flatten.md b/docs/flatten.md index 8c0e934ca1..18ca079eb3 100644 --- a/docs/flatten.md +++ b/docs/flatten.md @@ -67,7 +67,7 @@ Environment Variables: | name | A unique name for this repository. | Name | required | | | cargo_toml_files | A list of Cargo manifests (Cargo.toml files). | List of labels | optional | [] | | crate_registry_template | A template for where to download crates from for the default crate registry. This must contain {version} and {crate} templates. | String | optional | "https://crates.io/api/v1/crates/{crate}/{version}/download" | -| iso_date | The iso_date of cargo binary the resolver should use. Note version must be beta or nightly | 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 | "" | | lockfile | The path to a file which stores pinned information about the generated dependency graph. this target must be a file and will be updated by the repository rule when the REPIN environment variable is set. If this is not set, dependencies will be re-resolved more often, setting this allows caching resolves, but will error if the cache is stale. | Label | optional | None | | overrides | Mapping of crate name to specification overrides. See [crate.override](#crateoverride) for more details. | Dictionary: String -> String | optional | {} | | packages | A list of crate specifications. See [crate.spec](#cratespec) for more details. | List of strings | optional | [] |