-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added crate_universe examples to CI (#707)
* Added crate_universe examples to CI * Update crate_universe/bootstrap.bzl Co-authored-by: Daniel Wagner-Hall <[email protected]> * Updated docs * Remove crate_universe.bazelrc * Updated attribute names * Deleted example lockfile Co-authored-by: Daniel Wagner-Hall <[email protected]>
- Loading branch information
1 parent
374c75e
commit a04ff41
Showing
17 changed files
with
342 additions
and
786 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
"""A module for declaraing a repository for bootstrapping crate_universe""" | ||
|
||
load("//crate_universe/private:util.bzl", "get_host_info") | ||
|
||
BOOTSTRAP_ENV_VAR = "RULES_RUST_CRATE_UNIVERSE_BOOTSTRAP" | ||
|
||
_INSTALL_SCRIPT_CONTENT = """\ | ||
#!/bin/bash | ||
set -euo pipefail | ||
cp "${CRATE_RESOLVER_BIN}" "$@" | ||
""" | ||
|
||
_BUILD_FILE_CONTENT = """\ | ||
package(default_visibility = ["//visibility:public"]) | ||
exports_files(["release/crate_universe_resolver{ext}"]) | ||
sh_binary( | ||
name = "install", | ||
data = [ | ||
":release/crate_universe_resolver{ext}", | ||
], | ||
env = {{ | ||
"CRATE_RESOLVER_BIN": "$(execpath :release/crate_universe_resolver{ext})", | ||
}}, | ||
srcs = ["install.sh"], | ||
) | ||
""" | ||
|
||
def _crate_universe_resolver_bootstrapping_impl(repository_ctx): | ||
# no-op if there has been no request for bootstrapping | ||
if BOOTSTRAP_ENV_VAR not in repository_ctx.os.environ: | ||
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)) | ||
|
||
repository_dir = repository_ctx.path(".") | ||
resolver_path = repository_ctx.path("release/crate_universe_resolver" + extension) | ||
|
||
args = [ | ||
cargo_path, | ||
"build", | ||
"--release", | ||
"--locked", | ||
"--target-dir", | ||
repository_dir, | ||
"--manifest-path", | ||
repository_ctx.path(repository_ctx.attr.cargo_toml), | ||
] | ||
|
||
repository_ctx.report_progress("bootstrapping crate_universe_resolver") | ||
result = repository_ctx.execute( | ||
args, | ||
environment = { | ||
"RUSTC": str(rustc_path), | ||
}, | ||
quiet = False, | ||
) | ||
|
||
if result.return_code != 0: | ||
fail("exit_code: {}".format( | ||
result.return_code, | ||
)) | ||
|
||
repository_ctx.file("install.sh", _INSTALL_SCRIPT_CONTENT) | ||
|
||
repository_ctx.file("BUILD.bazel", _BUILD_FILE_CONTENT.format( | ||
ext = extension, | ||
)) | ||
|
||
_crate_universe_resolver_bootstrapping = repository_rule( | ||
doc = "A rule for bootstrapping a crate_universe_resolver binary using [Cargo](https://doc.rust-lang.org/cargo/)", | ||
implementation = _crate_universe_resolver_bootstrapping_impl, | ||
attrs = { | ||
"cargo_lockfile": attr.label( | ||
doc = "The lockfile of the crate_universe resolver", | ||
allow_single_file = ["Cargo.lock"], | ||
default = Label("//crate_universe:Cargo.lock"), | ||
), | ||
"cargo_toml": attr.label( | ||
doc = "The path of the crate_universe resolver manifest (`Cargo.toml` file)", | ||
allow_single_file = ["Cargo.toml"], | ||
default = Label("//crate_universe:Cargo.toml"), | ||
), | ||
"srcs": attr.label( | ||
doc = "Souces to the crate_universe resolver", | ||
allow_files = True, | ||
default = Label("//crate_universe:resolver_srcs"), | ||
), | ||
}, | ||
environ = [BOOTSTRAP_ENV_VAR], | ||
) | ||
|
||
def crate_universe_bootstrap(): | ||
_crate_universe_resolver_bootstrapping( | ||
name = "rules_rust_crate_universe_bootstrap", | ||
) |
Oops, something went wrong.