fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
7edda6f1
main
1"""`local_crate_mirror` rule implementation.""" 2 3load ( "//crate_universe/private:common_utils.bzl" , "execute" ) 4load ( "//crate_universe/private:generate_utils.bzl" , "get_generator" ) 5load ( "//crate_universe/private:urls.bzl" , "CARGO_BAZEL_SHA256S" , "CARGO_BAZEL_URLS" ) 6load ( "//rust/platform:triple.bzl" , "get_host_triple" ) 7 8def _local_crate_mirror_impl ( repository_ctx ): 9path = repository_ctx . path ( repository_ctx . attr . path ) 10 11host_triple = get_host_triple ( repository_ctx ) 12 13generator , _generator_sha256 = get_generator ( repository_ctx , host_triple . str ) 14 15# TODO: Work out why we can't just symlink here and actually copy. 16# illicitonion thinks it may be that symlinks didn't get invalidated properly? 17for child in repository_ctx . path ( path ). readdir (): 18repository_ctx . execute ([ "cp" , "-r" , child , repository_ctx . path ( child . basename )]) 19 20paths_to_track = execute ( repository_ctx , [ "find" , path , "-type" , "f" ]). stdout . strip (). split ( "\n ") 21for path_to_track in paths_to_track : 22if path_to_track : 23repository_ctx . read ( path_to_track ) 24 25execute ( repository_ctx , [ generator , "render" , "--options-json" , repository_ctx . attr . options_json , "--output-path" , repository_ctx . path ( "BUILD.bazel" )]) 26 27repository_ctx . file ( "WORKSPACE.bazel" , "" ) 28 29local_crate_mirror = repository_rule ( 30doc = """This is a private implementation detail of crate_universe, and should not be relied on in manually written code. 31 32This is effectively a `local_repository` rule impementation, but where the BUILD.bazel file is generated using the `cargo-bazel render` command.""" , 33implementation = _local_crate_mirror_impl , 34attrs = { 35"generator" : attr . string ( 36doc = ( 37"The absolute label of a generator. Eg. `@cargo_bazel_bootstrap//:cargo-bazel`. " + 38"This is typically used when bootstrapping" 39), 40), 41"generator_sha256s" : attr . string_dict ( 42doc = "Dictionary of `host_triple` -> `sha256` for a `cargo-bazel` binary." , 43default = CARGO_BAZEL_SHA256S , 44), 45"generator_urls" : attr . string_dict ( 46doc = ( 47"URL template from which to download the `cargo-bazel` binary. `{host_triple}` and will be " + 48"filled in according to the host platform." 49), 50default = CARGO_BAZEL_URLS , 51), 52"options_json" : attr . string ( 53doc = "JSON serialized instance of a crate_universe::context::SingleBuildFileRenderContext" , 54), 55"path" : attr . string ( 56# TODO: Verify what happens if this is not an absolute path. 57doc = "Absolute path to the BUILD.bazel file to generate." , 58), 59"quiet" : attr . bool ( 60doc = "If stdout and stderr should not be printed to the terminal." , 61default = True , 62), 63}, 64)