diff --git a/WORKSPACE b/WORKSPACE index 67c7f5117c..23c8bb9cac 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -63,7 +63,7 @@ examples_repositories() load("@examples//:examples_deps.bzl", examples_deps = "deps") -examples_deps() +examples_deps(is_top_level = True) load("@examples//:examples_transitive_deps.bzl", examples_transitive_deps = "transitive_deps") diff --git a/cargo/crate_universe_resolver/CONTRIBUTING.md b/cargo/crate_universe_resolver/CONTRIBUTING.md new file mode 100644 index 0000000000..6f0958b0e7 --- /dev/null +++ b/cargo/crate_universe_resolver/CONTRIBUTING.md @@ -0,0 +1,40 @@ +# Contributing + +## Tour of the codebase + +We start at `workspace.bzl`, which invokes the resolver. + +The resolver: +* `config.rs`: Deserializes the Config +* `parser.rs`: Parses the Config, any `Cargo.toml` files, and any additional packages, into a single unified `Cargo.toml` file +* `resolver.rs`: Resolves all of the crates. +* `consolidator.rs`: Patches in any WORKSPACE-specified overrides, and deals with platform-specific concerns. +* `renderer.rs`: Generates BUILD files for each crate, as well as functions that can be called from BUILD files. + +The code started off as a very hacky Week of Code project, and there are some clear remnants of that in the codebase - nothing is sacred, feel free to improve anything! + +Some areas have unit testing, there are a few (very brittle) integration tests, and some examples. + +## How to test local changes + +To use a local version, first build it: +```console +resolver $ cargo build +``` + +Then run a bazel build with this environment variable: +```console +RULES_RUST_RESOLVER_URL_OVERRIDE=file:///path/to/resolver/target/debug/resolver bazel build //whatever +``` + +To get verbose logging, edit `workspace.bzl` to set `RUST_LOG` to `debug` or `trace` instead of `info`. In particular, that will print out the generated Cargo.toml, and the path to the generated workspace file. + +Note that you may need to `bazel shutdown` between bazel commands. Hopefully not, but if you're seeing stale results, try it out. This only affects local development. + +## Testing + +To test with the `resolver` built from source: + +```bash +bin/test +``` diff --git a/cargo/crate_universe_resolver/Cargo.lock b/cargo/crate_universe_resolver/Cargo.lock new file mode 100644 index 0000000000..555c5b6cee --- /dev/null +++ b/cargo/crate_universe_resolver/Cargo.lock @@ -0,0 +1,2391 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "adler" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" + +[[package]] +name = "aho-corasick" +version = "0.7.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5" +dependencies = [ + "memchr", +] + +[[package]] +name = "ansi_term" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +dependencies = [ + "winapi", +] + +[[package]] +name = "anyhow" +version = "1.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afddf7f520a80dbf76e6f50a35bca42a2331ef227a28b3b6dc5c2e2338d114b1" + +[[package]] +name = "assert_cmd" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c88b9ca26f9c16ec830350d309397e74ee9abdfd8eb1f71cb6ecc71a3fc818da" +dependencies = [ + "doc-comment", + "predicates", + "predicates-core", + "predicates-tree", + "wait-timeout", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" + +[[package]] +name = "block-buffer" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" +dependencies = [ + "block-padding", + "byte-tools", + "byteorder", + "generic-array 0.12.3", +] + +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array 0.14.4", +] + +[[package]] +name = "block-padding" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" +dependencies = [ + "byte-tools", +] + +[[package]] +name = "bstr" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "473fc6b38233f9af7baa94fb5852dca389e3d95b8e21c8e3719301462c5d9faf" +dependencies = [ + "memchr", +] + +[[package]] +name = "bumpalo" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" + +[[package]] +name = "byte-tools" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" + +[[package]] +name = "byteorder" +version = "1.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" + +[[package]] +name = "bytes" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" + +[[package]] +name = "bytes" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" + +[[package]] +name = "cargo-clone-crate" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b78a45c9c653977a5f6513261370501ce16de5ddcef970adbff135cf63540fe" +dependencies = [ + "anyhow", + "flate2", + "log", + "regex", + "reqwest", + "semver", + "serde_json", + "tar", +] + +[[package]] +name = "cargo-lock" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bad00408e56f778335802ea240b8d70bebf6ea6c43c7508ebb6259431b5f16c2" +dependencies = [ + "semver", + "serde", + "toml", + "url", +] + +[[package]] +name = "cargo-platform" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0226944a63d1bf35a3b5f948dd7c59e263db83695c9e8bffc4037de02e30f1d7" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo-raze" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7adfabaf75ccef7664e1a837f75df2dabada636771f955da1dad2cdf2e5726d8" +dependencies = [ + "anyhow", + "cargo-clone-crate", + "cargo-lock", + "cargo-platform", + "cargo_metadata", + "cargo_toml", + "cfg-expr 0.5.1", + "crates-index", + "docopt", + "glob", + "itertools 0.10.0", + "log", + "pathdiff", + "regex", + "rustc-serialize", + "semver", + "serde", + "serde_derive", + "serde_json", + "slug", + "spdx", + "tempfile", + "tera", + "toml", + "url", +] + +[[package]] +name = "cargo_metadata" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7714a157da7991e23d90686b9524b9e12e0407a108647f52e9328f4b3d51ac7f" +dependencies = [ + "cargo-platform", + "semver", + "semver-parser", + "serde", + "serde_json", +] + +[[package]] +name = "cargo_toml" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "513d17226888c7b8283ac02a1c1b0d8a9d4cbf6db65dfadb79f598f5d7966fe9" +dependencies = [ + "serde", + "serde_derive", + "toml", +] + +[[package]] +name = "cc" +version = "1.0.62" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1770ced377336a88a67c473594ccc14eca6f4559217c34f64aac8f83d641b40" +dependencies = [ + "jobserver", +] + +[[package]] +name = "cfg-expr" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c2be76f06820200669a77ae59a8328c6b8fe4496e8fb7fed02f2806a442c5ff" +dependencies = [ + "smallvec", +] + +[[package]] +name = "cfg-expr" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf3029692edb3cd77a7fb51dbbbdc4b550c958f7b2147cb7691e38b070f96b5d" +dependencies = [ + "smallvec", +] + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +dependencies = [ + "libc", + "num-integer", + "num-traits", + "time", + "winapi", +] + +[[package]] +name = "chrono-tz" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2554a3155fec064362507487171dcc4edc3df60cb10f3a1fb10ed8094822b120" +dependencies = [ + "chrono", + "parse-zoneinfo", +] + +[[package]] +name = "clap" +version = "2.33.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" +dependencies = [ + "ansi_term", + "atty", + "bitflags", + "strsim 0.8.0", + "textwrap", + "unicode-width", + "vec_map", +] + +[[package]] +name = "core-foundation" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" + +[[package]] +name = "cpuid-bool" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" + +[[package]] +name = "crate_universe_resolver" +version = "0.2.0" +dependencies = [ + "anyhow", + "assert_cmd", + "cargo-raze", + "cargo_metadata", + "cfg-expr 0.4.1", + "env_logger", + "hex", + "indoc", + "itertools 0.9.0", + "libssh2-sys", + "log", + "maplit", + "predicates", + "semver", + "serde", + "serde_json", + "sha2", + "spectral", + "structopt", + "tempfile", + "tera", + "toml", + "url", + "uuid", +] + +[[package]] +name = "crates-index" +version = "0.16.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24823d553339d125040d989d2a593a01b034fe5ac17714423bcd2c3d168878" +dependencies = [ + "git2", + "glob", + "hex", + "home", + "memchr", + "semver", + "serde", + "serde_derive", + "serde_json", + "smartstring", +] + +[[package]] +name = "crc32fast" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "crossbeam-utils" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" +dependencies = [ + "autocfg", + "cfg-if 0.1.10", + "lazy_static", +] + +[[package]] +name = "deunicode" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "850878694b7933ca4c9569d30a34b55031b9b139ee1fc7b94a527c4ef960d690" + +[[package]] +name = "difference" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" + +[[package]] +name = "digest" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +dependencies = [ + "generic-array 0.12.3", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array 0.14.4", +] + +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + +[[package]] +name = "docopt" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f525a586d310c87df72ebcd98009e57f1cc030c8c268305287a476beb653969" +dependencies = [ + "lazy_static", + "regex", + "serde", + "strsim 0.9.3", +] + +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + +[[package]] +name = "encoding_rs" +version = "0.8.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "801bbab217d7f79c0062f4f7205b5d4427c6d1a7bd7aafdd1475f7c59d62b283" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "env_logger" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "fake-simd" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" + +[[package]] +name = "filetime" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c122a393ea57648015bf06fbd3d372378992e86b9ff5a7a497b076a28c79efe" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "redox_syscall", + "winapi", +] + +[[package]] +name = "flate2" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7411863d55df97a419aa64cb4d2f167103ea9d767e2c54a1868b7ac3f6b47129" +dependencies = [ + "cfg-if 1.0.0", + "crc32fast", + "libc", + "miniz_oxide", +] + +[[package]] +name = "float-cmp" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1267f4ac4f343772758f7b1bdcbe767c218bbab93bb432acbf5162bbf85a6c4" +dependencies = [ + "num-traits", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ece68d15c92e84fa4f19d3780f1294e5ca82a78a6d515f1efaabcc144688be00" +dependencies = [ + "matches", + "percent-encoding", +] + +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" + +[[package]] +name = "futures-channel" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b7109687aa4e177ef6fe84553af6280ef2778bdb7783ba44c9dc3399110fe64" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "847ce131b72ffb13b6109a221da9ad97a64cbe48feb1028356b836b47b8f1748" + +[[package]] +name = "futures-io" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "611834ce18aaa1bd13c4b374f5d653e1027cf99b6b502584ff8c9a64413b30bb" + +[[package]] +name = "futures-sink" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f878195a49cee50e006b02b93cf7e0a95a38ac7b776b4c4d9cc1207cd20fcb3d" + +[[package]] +name = "futures-task" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c554eb5bf48b2426c4771ab68c6b14468b6e76cc90996f528c3338d761a4d0d" +dependencies = [ + "once_cell", +] + +[[package]] +name = "futures-util" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d304cff4a7b99cfb7986f7d43fbe93d175e72e704a8860787cc95e9ffd85cbd2" +dependencies = [ + "futures-core", + "futures-io", + "futures-task", + "memchr", + "pin-project 1.0.1", + "pin-utils", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" +dependencies = [ + "typenum", +] + +[[package]] +name = "generic-array" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" +dependencies = [ + "cfg-if 0.1.10", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", +] + +[[package]] +name = "git2" +version = "0.13.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca6f1a0238d7f8f8fd5ee642f4ebac4dbc03e03d1f78fbe7a3ede35dcf7e2224" +dependencies = [ + "bitflags", + "libc", + "libgit2-sys", + "log", + "openssl-probe", + "openssl-sys", + "url", +] + +[[package]] +name = "glob" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" + +[[package]] +name = "globset" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c152169ef1e421390738366d2f796655fec62621dabbd0fd476f905934061e4a" +dependencies = [ + "aho-corasick", + "bstr", + "fnv", + "log", + "regex", +] + +[[package]] +name = "globwalk" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93e3af942408868f6934a7b85134a3230832b9977cf66125df2f9edcfce4ddcc" +dependencies = [ + "bitflags", + "ignore", + "walkdir", +] + +[[package]] +name = "h2" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b67e66362108efccd8ac053abafc8b7a8d86a37e6e48fc4f6f7485eb5e9e6a5" +dependencies = [ + "bytes 1.0.1", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", + "tracing-futures", +] + +[[package]] +name = "hashbrown" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" + +[[package]] +name = "heck" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "hermit-abi" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8" +dependencies = [ + "libc", +] + +[[package]] +name = "hex" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" +dependencies = [ + "serde", +] + +[[package]] +name = "home" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2456aef2e6b6a9784192ae780c0f15bc57df0e918585282325e8c8ac27737654" +dependencies = [ + "winapi", +] + +[[package]] +name = "http" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d569972648b2c512421b5f2a405ad6ac9666547189d0c5477a3f200f3e02f9" +dependencies = [ + "bytes 0.5.6", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2861bd27ee074e5ee891e8b539837a9430012e249d7f0ca2d795650f579c1994" +dependencies = [ + "bytes 1.0.1", + "http", +] + +[[package]] +name = "httparse" +version = "1.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" + +[[package]] +name = "httpdate" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47" + +[[package]] +name = "humansize" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6cab2627acfc432780848602f3f558f7e9dd427352224b0d9324025796d2a5e" + +[[package]] +name = "humantime" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" +dependencies = [ + "quick-error", +] + +[[package]] +name = "hyper" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12219dc884514cb4a6a03737f4413c0e01c23a1b059b0156004b23f1e19dccbe" +dependencies = [ + "bytes 1.0.1", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project 1.0.1", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes 1.0.1", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + +[[package]] +name = "idna" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "ignore" +version = "0.4.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22dcbf2a4a289528dbef21686354904e1c694ac642610a9bff9e7df730d9ec72" +dependencies = [ + "crossbeam-utils", + "globset", + "lazy_static", + "log", + "memchr", + "regex", + "same-file", + "thread_local", + "walkdir", + "winapi-util", +] + +[[package]] +name = "indexmap" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55e2e4c765aa53a0424761bf9f41aa7a6ac1efa87238f59560640e27fca028f2" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "indoc" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5a75aeaaef0ce18b58056d306c27b07436fbb34b8816c53094b76dd81803136" +dependencies = [ + "unindent", +] + +[[package]] +name = "ipnet" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47be2f14c678be2fdcab04ab1171db51b2762ce6f0a8ee87c8dd4a04ed216135" + +[[package]] +name = "itertools" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" +dependencies = [ + "either", +] + +[[package]] +name = "itertools" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37d572918e350e82412fe766d24b15e6682fb2ed2bbe018280caa810397cb319" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" + +[[package]] +name = "jobserver" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c71313ebb9439f74b00d9d2dcec36440beaf57a6aa0623068441dd7cd81a7f2" +dependencies = [ + "libc", +] + +[[package]] +name = "js-sys" +version = "0.3.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca059e81d9486668f12d455a4ea6daa600bd408134cd17e3d3fb5a32d1f016f8" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614" + +[[package]] +name = "libgit2-sys" +version = "0.12.14+1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f25af58e6495f7caf2919d08f212de550cfa3ed2f5e744988938ea292b9f549" +dependencies = [ + "cc", + "libc", + "libssh2-sys", + "libz-sys", + "openssl-sys", + "pkg-config", +] + +[[package]] +name = "libssh2-sys" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca46220853ba1c512fc82826d0834d87b06bcd3c2a42241b7de72f3d2fe17056" +dependencies = [ + "cc", + "libc", + "libz-sys", + "openssl-sys", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "libz-sys" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "602113192b08db8f38796c4e85c39e960c145965140e918018bcde1952429655" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "log" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" +dependencies = [ + "cfg-if 0.1.10", +] + +[[package]] +name = "maplit" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" + +[[package]] +name = "matches" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" + +[[package]] +name = "memchr" +version = "2.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" + +[[package]] +name = "mime" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" + +[[package]] +name = "miniz_oxide" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f2d26ec3309788e423cfbf68ad1800f061638098d76a83681af979dc4eda19d" +dependencies = [ + "adler", + "autocfg", +] + +[[package]] +name = "mio" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e50ae3f04d169fcc9bde0b547d1c205219b7157e07ded9c5aff03e0637cb3ed7" +dependencies = [ + "libc", + "log", + "miow", + "ntapi", + "winapi", +] + +[[package]] +name = "miow" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a33c1b55807fbed163481b5ba66db4b2fa6cde694a5027be10fb724206c5897" +dependencies = [ + "socket2", + "winapi", +] + +[[package]] +name = "native-tls" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fcc7939b5edc4e4f86b1b4a04bb1498afaaf871b1a6691838ed06fcb48d3a3f" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "normalize-line-endings" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" + +[[package]] +name = "ntapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" +dependencies = [ + "winapi", +] + +[[package]] +name = "num" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + +[[package]] +name = "num-bigint" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e63899ad0da84ce718c14936262a41cee2c79c981fc0a0e7c7beb47d5a07e8c1" +dependencies = [ + "num-integer", + "num-traits", + "rand 0.4.6", + "rustc-serialize", +] + +[[package]] +name = "num-complex" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b288631d7878aaf59442cffd36910ea604ecd7745c36054328595114001c9656" +dependencies = [ + "num-traits", + "rustc-serialize", +] + +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee314c74bd753fc86b4780aa9475da469155f3848473a261d2d18e35245a784e" +dependencies = [ + "num-bigint", + "num-integer", + "num-traits", + "rustc-serialize", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "260e51e7efe62b592207e9e13a68e43692a7a279171d6ba57abd208bf23645ad" + +[[package]] +name = "opaque-debug" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" + +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + +[[package]] +name = "openssl" +version = "0.10.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d575eff3665419f9b83678ff2815858ad9d11567e082f5ac1814baba4e2bcb4" +dependencies = [ + "bitflags", + "cfg-if 0.1.10", + "foreign-types", + "lazy_static", + "libc", + "openssl-sys", +] + +[[package]] +name = "openssl-probe" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" + +[[package]] +name = "openssl-src" +version = "111.12.0+1.1.1h" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "858a4132194f8570a7ee9eb8629e85b23cbc4565f2d4a162e87556e5956abf61" +dependencies = [ + "cc", +] + +[[package]] +name = "openssl-sys" +version = "0.9.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a842db4709b604f0fe5d1170ae3565899be2ad3d9cbc72dedc789ac0511f78de" +dependencies = [ + "autocfg", + "cc", + "libc", + "openssl-src", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parse-zoneinfo" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c705f256449c60da65e11ff6626e0c16a0a0b96aaa348de61376b249bc340f41" +dependencies = [ + "regex", +] + +[[package]] +name = "pathdiff" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877630b3de15c0b64cc52f659345724fbf6bdad9bd9566699fc53688f3c34a34" + +[[package]] +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" + +[[package]] +name = "pest" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" +dependencies = [ + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "833d1ae558dc601e9a60366421196a8d94bc0ac980476d0b67e1d0988d72b2d0" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99b8db626e31e5b81787b9783425769681b347011cc59471e33ea46d2ea0cf55" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pest_meta" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54be6e404f5317079812fc8f9f5279de376d8856929e21c184ecf6bbd692a11d" +dependencies = [ + "maplit", + "pest", + "sha-1", +] + +[[package]] +name = "pin-project" +version = "0.4.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ffbc8e94b38ea3d2d8ba92aea2983b503cd75d0888d75b86bb37970b5698e15" +dependencies = [ + "pin-project-internal 0.4.27", +] + +[[package]] +name = "pin-project" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee41d838744f60d959d7074e3afb6b35c7456d0f61cad38a24e35e6553f73841" +dependencies = [ + "pin-project-internal 1.0.1", +] + +[[package]] +name = "pin-project-internal" +version = "0.4.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65ad2ae56b6abe3a1ee25f15ee605bacadb9a764edaba9c2bf4103800d4a1895" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-internal" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81a4ffa594b66bff340084d4081df649a7dc049ac8d7fc458d8e628bfbbb2f86" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c917123afa01924fc84bb20c4c03f004d9c38e5127e3c039bbf7f4b9c76a2f6b" + +[[package]] +name = "pin-project-lite" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439697af366c49a6d0a010c56a0d97685bc140ce0d377b13a2ea2aa42d64a827" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" + +[[package]] +name = "ppv-lite86" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" + +[[package]] +name = "predicates" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96bfead12e90dccead362d62bb2c90a5f6fc4584963645bc7f71a735e0b0735a" +dependencies = [ + "difference", + "float-cmp", + "normalize-line-endings", + "predicates-core", + "regex", +] + +[[package]] +name = "predicates-core" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06075c3a3e92559ff8929e7a280684489ea27fe44805174c3ebd9328dcb37178" + +[[package]] +name = "predicates-tree" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e63c4859013b38a76eca2414c64911fba30def9e3202ac461a2d22831220124" +dependencies = [ + "predicates-core", + "treeline", +] + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + +[[package]] +name = "quote" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" +dependencies = [ + "fuchsia-cprng", + "libc", + "rand_core 0.3.1", + "rdrand", + "winapi", +] + +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom 0.1.15", + "libc", + "rand_chacha 0.2.2", + "rand_core 0.5.1", + "rand_hc 0.2.0", +] + +[[package]] +name = "rand" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18519b42a40024d661e1714153e9ad0c3de27cd495760ceb09710920f1098b1e" +dependencies = [ + "libc", + "rand_chacha 0.3.0", + "rand_core 0.6.1", + "rand_hc 0.3.0", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core 0.5.1", +] + +[[package]] +name = "rand_chacha" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.1", +] + +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +dependencies = [ + "rand_core 0.4.2", +] + +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom 0.1.15", +] + +[[package]] +name = "rand_core" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c026d7df8b298d90ccbbc5190bd04d85e159eaf5576caeacf8741da93ccbd2e5" +dependencies = [ + "getrandom 0.2.2", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core 0.5.1", +] + +[[package]] +name = "rand_hc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" +dependencies = [ + "rand_core 0.6.1", +] + +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "redox_syscall" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" + +[[package]] +name = "regex" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38cf2c13ed4745de91a5eb834e11c00bcc3709e773173b2ce4c56c9fbde04b9c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", + "thread_local", +] + +[[package]] +name = "regex-syntax" +version = "0.6.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189" + +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + +[[package]] +name = "reqwest" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd281b1030aa675fb90aa994d07187645bb3c8fc756ca766e7c3070b439de9de" +dependencies = [ + "base64", + "bytes 1.0.1", + "encoding_rs", + "futures-core", + "futures-util", + "http", + "http-body", + "hyper", + "hyper-tls", + "ipnet", + "js-sys", + "lazy_static", + "log", + "mime", + "native-tls", + "percent-encoding", + "pin-project-lite 0.2.4", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-native-tls", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + +[[package]] +name = "rustc-serialize" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" + +[[package]] +name = "ryu" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "schannel" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" +dependencies = [ + "lazy_static", + "winapi", +] + +[[package]] +name = "security-framework" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1759c2e3c8580017a484a7ac56d3abc5a6c1feadf88db2f3633f12ae4268c69" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f99b9d5e26d2a71633cc4f2ebae7cc9f874044e0c351a27e17892d76dce5678b" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "semver" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" +dependencies = [ + "semver-parser", + "serde", +] + +[[package]] +name = "semver-parser" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" +dependencies = [ + "pest", +] + +[[package]] +name = "serde" +version = "1.0.120" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "166b2349061381baf54a58e4b13c89369feb0ef2eaa57198899e2312aac30aab" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.120" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ca2a8cb5805ce9e3b95435e3765b7b553cecc762d938d409434338386cb5775" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fceb2595057b6891a4ee808f70054bd2d12f0e97f1cbb78689b59f676df325a" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha-1" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df" +dependencies = [ + "block-buffer 0.7.3", + "digest 0.8.1", + "fake-simd", + "opaque-debug 0.2.3", +] + +[[package]] +name = "sha2" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e7aab86fe2149bad8c507606bdb3f4ef5e7b2380eb92350f56122cca72a42a8" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if 1.0.0", + "cpuid-bool", + "digest 0.9.0", + "opaque-debug 0.3.0", +] + +[[package]] +name = "slab" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" + +[[package]] +name = "slug" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3bc762e6a4b6c6fcaade73e77f9ebc6991b676f88bb2358bddb56560f073373" +dependencies = [ + "deunicode", +] + +[[package]] +name = "smallvec" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252" + +[[package]] +name = "smartstring" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5579edba9651e6b9ccf0d516c4457521a149dadeb77e88b03eb1ae3183fe180a" +dependencies = [ + "serde", + "static_assertions", +] + +[[package]] +name = "socket2" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "winapi", +] + +[[package]] +name = "spdx" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a68f874c9aa7762aa10401e2ae004d977e7b6156074668eb4ce78dd0cb28255" +dependencies = [ + "lazy_static", + "regex", + "smallvec", +] + +[[package]] +name = "spectral" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae3c15181f4b14e52eeaac3efaeec4d2764716ce9c86da0c934c3e318649c5ba" +dependencies = [ + "num", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + +[[package]] +name = "strsim" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" + +[[package]] +name = "structopt" +version = "0.3.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "126d630294ec449fae0b16f964e35bf3c74f940da9dca17ee9b905f7b3112eb8" +dependencies = [ + "clap", + "lazy_static", + "structopt-derive", +] + +[[package]] +name = "structopt-derive" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65e51c492f9e23a220534971ff5afc14037289de430e3c83f9daf6a1b6ae91e8" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "syn" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc60a3d73ea6594cd712d830cc1f0390fd71542d8c8cd24e70cc54cdfd5e05d5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "tar" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "489997b7557e9a43e192c527face4feacc78bfbe6eed67fd55c4c9e381cba290" +dependencies = [ + "filetime", + "libc", + "redox_syscall", +] + +[[package]] +name = "tempfile" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" +dependencies = [ + "cfg-if 0.1.10", + "libc", + "rand 0.7.3", + "redox_syscall", + "remove_dir_all", + "winapi", +] + +[[package]] +name = "tera" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac6ab7eacf40937241959d540670f06209c38ceadb62116999db4a950fbf8dc" +dependencies = [ + "chrono", + "chrono-tz", + "globwalk", + "humansize", + "lazy_static", + "percent-encoding", + "pest", + "pest_derive", + "rand 0.8.2", + "regex", + "serde", + "serde_json", + "slug", + "unic-segment", +] + +[[package]] +name = "termcolor" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "thread_local" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "time" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +dependencies = [ + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", + "winapi", +] + +[[package]] +name = "tinyvec" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "238ce071d267c5710f9d31451efec16c5ee22de34df17cc05e56cbc92e967117" + +[[package]] +name = "tokio" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ca04cec6ff2474c638057b65798f60ac183e5e79d3448bb7163d36a39cff6ec" +dependencies = [ + "autocfg", + "bytes 1.0.1", + "libc", + "memchr", + "mio", + "num_cpus", + "pin-project-lite 0.2.4", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76066865172052eb8796c686f0b441a93df8b08d40a950b062ffb9a426f00edd" +dependencies = [ + "futures-core", + "pin-project-lite 0.2.4", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12ae4751faa60b9f96dd8344d74592e5a17c0c9a220413dbc6942d14139bbfcc" +dependencies = [ + "bytes 1.0.1", + "futures-core", + "futures-sink", + "log", + "pin-project-lite 0.2.4", + "tokio", + "tokio-stream", +] + +[[package]] +name = "toml" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" +dependencies = [ + "serde", +] + +[[package]] +name = "tower-service" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" + +[[package]] +name = "tracing" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0987850db3733619253fe60e17cb59b82d37c7e6c0236bb81e4d6b87c879f27" +dependencies = [ + "cfg-if 0.1.10", + "pin-project-lite 0.1.11", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f50de3927f93d202783f4513cda820ab47ef17f624b03c096e86ef00c67e6b5f" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "tracing-futures" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab7bb6f14721aa00656086e9335d363c5c8747bae02ebe32ea2c7dece5689b4c" +dependencies = [ + "pin-project 0.4.27", + "tracing", +] + +[[package]] +name = "treeline" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41" + +[[package]] +name = "try-lock" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" + +[[package]] +name = "typenum" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" + +[[package]] +name = "ucd-trie" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" + +[[package]] +name = "unic-char-property" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8c57a407d9b6fa02b4795eb81c5b6652060a15a7903ea981f3d723e6c0be221" +dependencies = [ + "unic-char-range", +] + +[[package]] +name = "unic-char-range" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0398022d5f700414f6b899e10b8348231abf9173fa93144cbc1a43b9793c1fbc" + +[[package]] +name = "unic-common" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80d7ff825a6a654ee85a63e80f92f054f904f21e7d12da4e22f9834a4aaa35bc" + +[[package]] +name = "unic-segment" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4ed5d26be57f84f176157270c112ef57b86debac9cd21daaabbe56db0f88f23" +dependencies = [ + "unic-ucd-segment", +] + +[[package]] +name = "unic-ucd-segment" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2079c122a62205b421f499da10f3ee0f7697f012f55b675e002483c73ea34700" +dependencies = [ + "unic-char-property", + "unic-char-range", + "unic-ucd-version", +] + +[[package]] +name = "unic-ucd-version" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96bd2f2237fe450fcd0a1d2f5f4e91711124f7857ba2e964247776ebeeb7b0c4" +dependencies = [ + "unic-common", +] + +[[package]] +name = "unicode-bidi" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" +dependencies = [ + "matches", +] + +[[package]] +name = "unicode-normalization" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fb19cf769fa8c6a80a162df694621ebeb4dafb606470b2b2fce0be40a98a977" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-segmentation" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0" + +[[package]] +name = "unicode-width" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" + +[[package]] +name = "unicode-xid" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" + +[[package]] +name = "unindent" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f14ee04d9415b52b3aeab06258a3f07093182b88ba0f9b8d203f211a7a7d41c7" + +[[package]] +name = "url" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5909f2b0817350449ed73e8bcd81c8c3c8d9a7a5d8acba4b27db277f1868976e" +dependencies = [ + "form_urlencoded", + "idna", + "matches", + "percent-encoding", + "serde", +] + +[[package]] +name = "uuid" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fde2f6a4bea1d6e007c4ad38c6839fa71cbb63b6dbf5b595aa38dc9b1093c11" +dependencies = [ + "rand 0.7.3", +] + +[[package]] +name = "vcpkg" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c" + +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + +[[package]] +name = "version_check" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" + +[[package]] +name = "wait-timeout" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +dependencies = [ + "libc", +] + +[[package]] +name = "walkdir" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d" +dependencies = [ + "same-file", + "winapi", + "winapi-util", +] + +[[package]] +name = "want" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +dependencies = [ + "log", + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + +[[package]] +name = "wasm-bindgen" +version = "0.2.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ac64ead5ea5f05873d7c12b545865ca2b8d28adfc50a49b84770a3a97265d42" +dependencies = [ + "cfg-if 0.1.10", + "serde", + "serde_json", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f22b422e2a757c35a73774860af8e112bff612ce6cb604224e8e47641a9e4f68" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7866cab0aa01de1edf8b5d7936938a7e397ee50ce24119aef3e1eaa3b6171da" +dependencies = [ + "cfg-if 0.1.10", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b13312a745c08c469f0b292dd2fcd6411dba5f7160f593da6ef69b64e407038" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f249f06ef7ee334cc3b8ff031bfc11ec99d00f34d86da7498396dc1e3b1498fe" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d649a3145108d7d3fbcde896a468d1bd636791823c9921135218ad89be08307" + +[[package]] +name = "web-sys" +version = "0.3.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bf6ef87ad7ae8008e15a355ce696bed26012b7caa21605188cfd8214ab51e2d" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "winreg" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" +dependencies = [ + "winapi", +] diff --git a/cargo/crate_universe_resolver/Cargo.toml b/cargo/crate_universe_resolver/Cargo.toml new file mode 100644 index 0000000000..67e152a99d --- /dev/null +++ b/cargo/crate_universe_resolver/Cargo.toml @@ -0,0 +1,41 @@ +[package] +name = "crate_universe_resolver" +version = "0.2.0" +authors = [ + "Daniel Wagner-Hall ", + "Romain Chossart ", + "Gibson Fahnestock ", +] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +# Several of these dependencies need to be compatible with the version cargo-raze is using. + +anyhow = "1" +cargo-raze = "0.9" +cargo_metadata = "0.12.1" +cfg-expr = "0.4.1" +env_logger = "0.7" +hex = "0.4" +indoc = "1.0.2" +itertools = "0.9" +log = "0.4" +semver = { version = "0.11", features = ["serde"] } +serde = { version = "1", features = ["derive"] } +serde_json = "1" +sha2 = "0.9" +structopt = "0.3" +tempfile = "3" +tera = "1.6" +toml = "0.5.6" +url = { version = "2.2", features = ["serde"] } +uuid = { version = "0.8", features = ["v4"] } +libssh2-sys = { version = "0.2.19", features = ["vendored-openssl"] } + +[dev-dependencies] +assert_cmd = "1" +maplit = "1" +predicates = "1" +spectral = "0.6" diff --git a/cargo/crate_universe_resolver/src/config.rs b/cargo/crate_universe_resolver/src/config.rs new file mode 100644 index 0000000000..b6c699e52c --- /dev/null +++ b/cargo/crate_universe_resolver/src/config.rs @@ -0,0 +1,145 @@ +use std::collections::{BTreeMap, BTreeSet, HashMap}; +use std::path::PathBuf; + +use semver::VersionReq; +use serde::{Deserialize, Serialize}; +use url::Url; + +use crate::consolidator::{ConsolidatorConfig, ConsolidatorOverride}; +use crate::parser::merge_cargo_tomls; +use crate::renderer::RenderConfig; +use crate::resolver::{Resolver, ResolverConfig}; + +#[derive(Debug, Deserialize, Serialize, Ord, Eq, PartialOrd, PartialEq)] +pub struct Package { + pub name: String, + pub semver: VersionReq, + pub features: Vec, +} + +#[derive(Debug, Deserialize, Serialize)] +#[serde(deny_unknown_fields)] +pub struct Override { + // Mapping of environment variables key -> value. + pub extra_rust_env_vars: BTreeMap, + // Mapping of environment variables key -> value. + pub extra_build_script_env_vars: BTreeMap, + // Mapping of target triple or spec -> extra bazel target dependencies. + pub extra_bazel_deps: BTreeMap>, + // Mapping of target triple or spec -> extra bazel target data dependencies. + pub extra_bazel_data_deps: BTreeMap>, + // Mapping of target triple or spec -> extra bazel target build script dependencies. + pub extra_build_script_bazel_deps: BTreeMap>, + // Mapping of target triple or spec -> extra bazel target build script data dependencies. + pub extra_build_script_bazel_data_deps: BTreeMap>, + // Features to remove from crates (e.g. which are needed when building with Cargo but not with Bazel). + pub features_to_remove: BTreeSet, +} + +// Options which affect the contents of the generated output should be on this struct. +// These fields all end up hashed into the lockfile hash. +// +// Anything which doesn't affect the contents of the generated output should live on `Opt` in `main.rs`. +#[derive(Debug, Deserialize, Serialize)] +#[serde(deny_unknown_fields)] +pub struct Config { + pub repository_name: String, + + pub packages: Vec, + pub cargo_toml_files: BTreeMap, + pub overrides: HashMap, + + /// Template of the URL from which to download crates, which are assumed to be gzip'd tar files. + /// This string may contain arbitrarily many instances of {crate} and {version} which will be + /// replaced by crate names and versions. + #[serde(default = "default_repository_template")] + pub repository_template: String, + + pub target_triples: Vec, + pub cargo: PathBuf, + + #[serde(default = "default_rules_rust_workspace_name")] + pub rust_rules_workspace_name: String, + #[serde(default = "default_index_url")] + pub index_url: Url, +} + +impl Config { + pub fn preprocess(mut self) -> anyhow::Result { + self.packages.sort(); + + let (toml_contents, label_to_crates) = + merge_cargo_tomls(self.cargo_toml_files, self.packages)?; + + let overrides = self + .overrides + .into_iter() + .map(|(krate, overryde)| { + ( + krate, + ConsolidatorOverride { + extra_rust_env_vars: overryde.extra_rust_env_vars, + extra_build_script_env_vars: overryde.extra_build_script_env_vars, + extra_bazel_deps: overryde.extra_bazel_deps, + extra_build_script_bazel_deps: overryde.extra_build_script_bazel_deps, + extra_bazel_data_deps: overryde.extra_bazel_data_deps, + extra_build_script_bazel_data_deps: overryde + .extra_build_script_bazel_data_deps, + features_to_remove: overryde.features_to_remove, + }, + ) + }) + .collect(); + + Ok(Resolver::new( + toml_contents.into(), + ResolverConfig { + cargo: self.cargo, + index_url: self.index_url, + }, + ConsolidatorConfig { overrides }, + RenderConfig { + repo_rule_name: self.repository_name.clone(), + repository_template: self.repository_template.clone(), + rules_rust_workspace_name: self.rust_rules_workspace_name.clone(), + }, + self.target_triples, + label_to_crates, + )) + } +} + +// TODO: maybe remove the "+buildmetadata" suffix to consolidate e.g. "1.2.3+foo" and "1.2.3". +/// Generate the repo rule name from the target like cargo-raze. +/// e.g. `0.18.0-alpha.2+test` -> `0_18_0_alpha_2_test`. +pub fn crate_to_repo_rule_name(repo_rule_name: &str, name: &str, version: &str) -> String { + format!( + "{repo_rule_name}__{name}__{version}", + repo_rule_name = repo_rule_name, + name = name.replace("-", "_"), + version = version + .replace(".", "_") + .replace("+", "_") + .replace("-", "_") + ) +} + +pub fn crate_to_label(repo_rule_name: &str, crate_name: &str, crate_version: &str) -> String { + format!( + "@{repo_name}//:{name}", + repo_name = crate_to_repo_rule_name(repo_rule_name, crate_name, crate_version), + name = crate_name.replace("-", "_") + ) +} + +pub fn default_rules_rust_workspace_name() -> String { + String::from("rules_rust") +} + +pub fn default_index_url() -> Url { + Url::parse("https://github.com/rust-lang/crates.io-index").expect("Invalid default index URL") +} + +fn default_repository_template() -> String { + String::from("https://crates.io/api/v1/crates/{crate}/{version}/download") +} diff --git a/cargo/crate_universe_resolver/src/consolidator.rs b/cargo/crate_universe_resolver/src/consolidator.rs new file mode 100644 index 0000000000..6e14469667 --- /dev/null +++ b/cargo/crate_universe_resolver/src/consolidator.rs @@ -0,0 +1,259 @@ +use std::collections::{BTreeMap, BTreeSet}; + +use anyhow::anyhow; +use cargo_raze::context::{ + BuildableDependency, CrateContext, CrateDependencyContext, CrateTargetedDepContext, +}; +use itertools::Itertools; +use semver::Version; + +use crate::renderer::{RenderConfig, Renderer}; +use crate::resolver::Dependencies; +use cargo_raze::util::{generate_bazel_conditions, get_matching_bazel_triples}; +use cfg_expr::targets::get_builtin_target_by_triple; + +#[derive(Debug, Default)] +pub struct ConsolidatorOverride { + // Mapping of environment variables key -> value. + pub extra_rust_env_vars: BTreeMap, + // Mapping of environment variables key -> value. + pub extra_build_script_env_vars: BTreeMap, + // Mapping of target triple or spec -> extra bazel target dependencies. + pub extra_bazel_deps: BTreeMap>, + // Mapping of target triple or spec -> extra bazel target data dependencies. + pub extra_bazel_data_deps: BTreeMap>, + // Mapping of target triple or spec -> extra bazel target build script dependencies. + pub extra_build_script_bazel_deps: BTreeMap>, + // Mapping of target triple or spec -> extra bazel target build script data dependencies. + pub extra_build_script_bazel_data_deps: BTreeMap>, + + pub features_to_remove: BTreeSet, +} + +pub struct ConsolidatorConfig { + // Mapping of crate name to override struct. + pub overrides: BTreeMap, +} + +pub struct Consolidator { + consolidator_config: ConsolidatorConfig, + render_config: RenderConfig, + digest: String, + target_triples: Vec, + resolved_packages: Vec, + member_packages_version_mapping: Dependencies, + label_to_crates: BTreeMap>, +} + +impl Consolidator { + pub(crate) fn new( + consolidator_config: ConsolidatorConfig, + render_config: RenderConfig, + digest: String, + target_triples: Vec, + resolved_packages: Vec, + member_packages_version_mapping: Dependencies, + label_to_crates: BTreeMap>, + ) -> Self { + Consolidator { + consolidator_config, + render_config, + digest, + target_triples, + resolved_packages, + member_packages_version_mapping, + label_to_crates, + } + } + + fn targeted_dep_context_for( + target: &str, + target_triples_filter: &[String], + ) -> CrateTargetedDepContext { + let triples: Vec<_> = { + if target.starts_with("cfg(") { + // User passed a cfg(...) configuration. + get_matching_bazel_triples(&target.to_owned()) + .unwrap_or_default() + .into_iter() + .filter(|target| target_triples_filter.contains(target)) + .collect() + } else { + // User passed a triple. + match get_builtin_target_by_triple(&target) { + Some(_) => vec![target.to_owned()], + _ => vec![], + } + } + }; + if triples.is_empty() { + panic!( + "Target {} in rule attribute doesn't map to any triple", + &target + ) + } + + CrateTargetedDepContext { + target: target.to_owned(), + deps: CrateDependencyContext { + dependencies: vec![], + proc_macro_dependencies: vec![], + data_dependencies: vec![], + build_dependencies: vec![], + build_proc_macro_dependencies: vec![], + build_data_dependencies: vec![], + dev_dependencies: vec![], + aliased_dependencies: vec![], + }, + conditions: generate_bazel_conditions("rules_rust", &triples).unwrap(), // UNWRAP: the triple was generated by get_matching_bazel_triples() + } + } + + // Generate a Vec of CrateTargetedDepContext with the deps/data contents from the provided arguments. + fn extra_deps_as_targeted_deps( + target_triples_filter: &[String], + extra_bazel_deps: I, + extra_bazel_data_deps: I, + extra_build_script_bazel_deps: I, + extra_build_script_bazel_data_deps: I, + ) -> Vec + where + I: IntoIterator)>, + { + let mut crate_targeted_dep_contexts: BTreeMap = + Default::default(); + + let into_buildable_dependency = |dep: &String| BuildableDependency { + name: "".to_string(), + version: Version::new(0, 0, 0), + buildable_target: dep.clone(), + is_proc_macro: false, + }; + + extra_bazel_deps.into_iter().for_each(|(target, deps)| { + let targeted_dep_context = crate_targeted_dep_contexts + .entry(target.clone()) + .or_insert_with(|| Self::targeted_dep_context_for(&target, target_triples_filter)); + targeted_dep_context + .deps + .dependencies + .extend(deps.iter().map(into_buildable_dependency)); + }); + extra_bazel_data_deps + .into_iter() + .for_each(|(target, deps)| { + let targeted_dep_context = crate_targeted_dep_contexts + .entry(target.clone()) + .or_insert_with(|| { + Self::targeted_dep_context_for(&target, target_triples_filter) + }); + targeted_dep_context + .deps + .data_dependencies + .extend(deps.iter().map(into_buildable_dependency)); + }); + + extra_build_script_bazel_deps + .into_iter() + .for_each(|(target, deps)| { + let targeted_dep_context = crate_targeted_dep_contexts + .entry(target.clone()) + .or_insert_with(|| { + Self::targeted_dep_context_for(&target, target_triples_filter) + }); + targeted_dep_context + .deps + .build_dependencies + .extend(deps.iter().map(into_buildable_dependency)); + }); + + extra_build_script_bazel_data_deps + .into_iter() + .for_each(|(target, deps)| { + let targeted_dep_context = crate_targeted_dep_contexts + .entry(target.clone()) + .or_insert_with(|| { + Self::targeted_dep_context_for(&target, target_triples_filter) + }); + targeted_dep_context + .deps + .build_data_dependencies + .extend(deps.iter().map(into_buildable_dependency)); + }); + + crate_targeted_dep_contexts + .into_iter() + .sorted() + .map(|(_, targeted_dep_context)| targeted_dep_context) + .collect() + } + + pub fn consolidate(self) -> anyhow::Result { + let Self { + mut consolidator_config, + render_config, + digest, + target_triples, + mut resolved_packages, + member_packages_version_mapping, + label_to_crates, + } = self; + + let mut names_and_versions_to_count = BTreeMap::new(); + for pkg in &resolved_packages { + *names_and_versions_to_count + .entry((pkg.pkg_name.clone(), pkg.pkg_version.clone())) + .or_insert(0_usize) += 1_usize; + } + let duplicates: Vec<_> = names_and_versions_to_count + .into_iter() + .filter_map(|((name, version), value)| { + if value > 1 { + Some(format!("{} {}", name, version)) + } else { + None + } + }) + .collect(); + if !duplicates.is_empty() { + return Err(anyhow!( + "Got duplicate sources for identical crate name and version combination{}: {}", + if duplicates.len() == 1 { "" } else { "s" }, + duplicates.join(", ") + )); + } + + // Apply overrides specified in the crate_universe repo rule. + for pkg in &mut resolved_packages { + if let Some(overryde) = consolidator_config.overrides.remove(&pkg.pkg_name) { + // Add extra dependencies. + pkg.targeted_deps.extend(Self::extra_deps_as_targeted_deps( + &target_triples, + overryde.extra_bazel_deps.into_iter(), + overryde.extra_bazel_data_deps.into_iter(), + overryde.extra_build_script_bazel_deps.into_iter(), + overryde.extra_build_script_bazel_data_deps.into_iter(), + )); + // Add extra environment variables. + pkg.raze_settings + .additional_env + .extend(overryde.extra_rust_env_vars.into_iter()); + // Add extra build script environment variables. + pkg.raze_settings + .buildrs_additional_environment_variables + .extend(overryde.extra_build_script_env_vars.into_iter()); + + let features_to_remove = overryde.features_to_remove; + pkg.features.retain(|f| !features_to_remove.contains(f)); + } + } + + Ok(Renderer::new( + render_config, + digest, + resolved_packages, + member_packages_version_mapping, + label_to_crates, + )) + } +} diff --git a/cargo/crate_universe_resolver/src/lib.rs b/cargo/crate_universe_resolver/src/lib.rs new file mode 100644 index 0000000000..f20b19eec1 --- /dev/null +++ b/cargo/crate_universe_resolver/src/lib.rs @@ -0,0 +1,25 @@ +use std::path::{Path, PathBuf}; + +use std::io::Write; + +pub mod config; +pub mod consolidator; +pub mod parser; +pub mod renderer; +pub mod resolver; +mod serde_utils; + +pub struct NamedTempFile(tempfile::TempDir, PathBuf); + +impl NamedTempFile { + pub fn with_str_content>(name: P, content: &str) -> std::io::Result { + let dir = tempfile::tempdir()?; + let path = dir.path().join(name.as_ref()); + let mut file = std::fs::File::create(&path)?; + write!(file, "{}", content)?; + Ok(Self(dir, path)) + } + pub fn path(&self) -> &Path { + &self.1 + } +} diff --git a/cargo/crate_universe_resolver/src/main.rs b/cargo/crate_universe_resolver/src/main.rs new file mode 100644 index 0000000000..ed7107fce5 --- /dev/null +++ b/cargo/crate_universe_resolver/src/main.rs @@ -0,0 +1,111 @@ +use anyhow::{anyhow, Context}; +use log::*; +use crate_universe_resolver::config::Config; +use std::io::{BufRead, BufReader}; +use std::path::PathBuf; +use structopt::StructOpt; + +// Options which don't affect the contents of the generated should be on this struct. +// These fields are not factored into cache keys. +// +// Anything which affects the contents of the generated output should live on `config::Config`. +#[derive(StructOpt)] +struct Opt { + #[structopt(long)] + repo_name: String, + #[structopt(long = "input_path", parse(from_os_str))] + input_path: PathBuf, + #[structopt(long = "output_path", parse(from_os_str))] + output_path: PathBuf, + #[structopt(long = "lockfile", parse(from_os_str))] + lockfile: Option, + #[structopt(long = "update-lockfile")] + update_lockfile: bool, +} + +fn main() -> anyhow::Result<()> { + env_logger::init(); + + let opt = Opt::from_args(); + + trace!("Parsing config from {:?}", opt.input_path); + + let config: Config = { + let config_file = std::fs::File::open(&opt.input_path) + .with_context(|| format!("Failed to open config file at {:?}", opt.input_path))?; + serde_json::from_reader(config_file) + .with_context(|| format!("Failed to parse config file {:?}", opt.input_path))? + }; + let lockfile = opt.lockfile; + let repo_name = opt.repo_name; + let output_path = opt.output_path; + + trace!("Preprocessing config"); + let mut resolver = config.preprocess()?; + + if opt.update_lockfile { + if lockfile.is_none() { + eprintln!("Not updating lockfile for `crate_universe` repository with name \"{}\" because it has no `lockfile` attribute.", repo_name); + } + } else if let Some(lockfile) = lockfile { + let mut lockfile_format_version_line = String::new(); + let mut lockfile_hash_line = String::new(); + { + std::fs::File::open(&lockfile) + .map(BufReader::new) + .and_then(|mut f| { + f.read_line(&mut lockfile_format_version_line)?; + f.read_line(&mut lockfile_hash_line)?; + Ok(()) + }) + .with_context(|| format!("Failed to read lockfile header from {:?}", lockfile))?; + } + if lockfile_format_version_line != "# rules_rust crate_universe file format 1\n" { + return Err(anyhow!("Unrecognized lockfile format")); + } + if let Some(lockfile_hash) = lockfile_hash_line.strip_prefix("# config hash ") { + if resolver.digest()? == lockfile_hash.trim() { + std::fs::copy(&lockfile, &output_path).with_context(|| { + format!( + "Failed to copy lockfile from {:?} to {:?}", + lockfile, output_path + ) + })?; + return Ok(()); + } else { + return Err(anyhow!("rules_rust_external: Lockfile at {} is out of date, please either:\n1. Re-run bazel with the environment variable `RULES_RUST_UPDATE_CRATE_UNIVERSE_LOCKFILE=true`, to update the lockfile\n2. Remove the `lockfile` attribute from the `crate_universe` repository rule with name \"{}\" to use floating dependency versions", lockfile.display(), repo_name)); + } + } else { + return Err(anyhow!("Invalid lockfile")); + } + } + + // This will contain the mapping of the workspace member (i.e. toplevel) packages' direct + // dependencies package names to their package Bazel repository name (e.g. `bzip2 -> + // bzip2__0_3_3`), allowing the user to easily express dependencies with a `package()` macro + // without knowing the version in advance. + trace!("Resolving transitive dependencies"); + let consolidator = resolver.resolve()?; + trace!("Consolidating overrides"); + let renderer = consolidator.consolidate()?; + + trace!("Rendering output to: {:?}", output_path); + let output_file = std::fs::File::create(&output_path) + .with_context(|| format!("Could not create output file {:?}", output_path))?; + renderer + .render(&output_file) + .context("Could not render deps")?; + + if opt.update_lockfile { + if let Some(lockfile) = lockfile.as_ref() { + std::fs::copy(&output_path, lockfile).with_context(|| { + format!( + "Error updating lockfile at {:?} from {:?}", + lockfile, output_path + ) + })?; + } + } + + Ok(()) +} diff --git a/cargo/crate_universe_resolver/src/parser.rs b/cargo/crate_universe_resolver/src/parser.rs new file mode 100644 index 0000000000..6da290e5eb --- /dev/null +++ b/cargo/crate_universe_resolver/src/parser.rs @@ -0,0 +1,388 @@ +use crate::config::Package as AdditionalPackage; +use anyhow::{anyhow, Context}; +use indoc::indoc; +use log::*; +use semver::{Version, VersionReq}; +use serde::{Deserialize, Deserializer}; +use std::collections::{BTreeMap, BTreeSet}; +use std::convert::{TryFrom, TryInto}; +use std::fs::read_to_string; +use std::path::PathBuf; +use toml::Value; + +#[derive(Debug, Deserialize)] +// We deny unknown fields so that when new fields are encountered, we need to explicitly decide +// whether they affect dependency resolution or not. +// For our first few users, this will be annoying, but it's hopefully worth it for the correctness. +#[serde(deny_unknown_fields)] +pub struct CargoToml { + pub package: Package, + pub dependencies: BTreeMap, + #[serde(rename = "build-dependencies", default = "BTreeMap::new")] + pub build_dependencies: BTreeMap, + #[serde(rename = "dev-dependencies", default = "BTreeMap::new")] + pub dev_dependencies: BTreeMap, + + #[serde(default = "BTreeMap::new")] + pub patch: BTreeMap>, + + #[serde(flatten)] + _ignored: Option, +} + +#[derive(Debug, Deserialize)] +// Allows unknown fields - we assume everything in Package doesn't affect dependency resolution. +pub struct Package { + pub name: String, + pub version: Version, +} + +#[derive(Debug, PartialEq, Eq)] +pub struct DepSpec { + pub default_features: bool, + pub features: BTreeSet, + pub version: VersionSpec, +} + +#[derive(Debug, PartialEq, Eq)] +pub enum VersionSpec { + Semver(VersionReq), + Git { + url: String, + rev: Option, + tag: Option, + }, + Local(PathBuf), +} + +/// Fields in the top-level CargoToml which are ignored. +/// Only add new fields here if you are certain they cannot affect dependency resolution. +/// Cargo.toml docs: https://doc.rust-lang.org/cargo/reference/manifest.html +#[derive(Debug, Deserialize)] +struct Ignored { + // Target tables + lib: serde::de::IgnoredAny, + bin: serde::de::IgnoredAny, + example: serde::de::IgnoredAny, + test: serde::de::IgnoredAny, + bench: serde::de::IgnoredAny, + profile: serde::de::IgnoredAny, + + // Other + features: serde::de::IgnoredAny, + badges: serde::de::IgnoredAny, + // Not ignored: + // replace: deprecated alternative to patch, use patch instead. + // cargo-features: unstable nightly features, evaluate on a case-by-case basis. + // workspace: TODO: support cargo workspaces. + // target: TODO: support platform-specific dependencies. +} + +pub fn merge_cargo_tomls( + label_to_path: BTreeMap, + packages: Vec, +) -> anyhow::Result<(CargoToml, BTreeMap>)> { + let mut merged_cargo_toml: CargoToml = indoc! { r#" + [package] + name = "dummy_package_for_crate_universe_resolver" + version = "0.1.0" + + [lib] + path = "doesnotexist.rs" + + [dependencies] + "# } + .try_into()?; + + let mut labels_to_deps = BTreeMap::new(); + + for (label, path) in label_to_path { + let mut all_dep_names = BTreeSet::new(); + + trace!("Parsing {:?}", path); + let content = + read_to_string(&path).with_context(|| format!("Failed to read {:?}", path))?; + let cargo_toml = CargoToml::try_from(content.as_str()) + .with_context(|| format!("Error parsing {:?}", path))?; + let CargoToml { + dependencies, + build_dependencies, + dev_dependencies, + patch, + package: _, + _ignored, + } = cargo_toml; + for (dep, dep_spec) in dependencies.into_iter() { + if let VersionSpec::Local(_) = dep_spec.version { + // We ignore local deps. + debug!("Ignoring local path dependency on {:?}", path); + continue; + } + all_dep_names.insert(dep.clone()); + if let Some(dep_spec_to_merge) = merged_cargo_toml.dependencies.get_mut(&dep) { + dep_spec_to_merge + .merge(dep_spec) + .context(format!("Failed to merge multiple dependencies on {}", dep))?; + } else { + merged_cargo_toml.dependencies.insert(dep, dep_spec); + } + } + + for (dep, dep_spec) in build_dependencies.into_iter() { + if let VersionSpec::Local(_) = dep_spec.version { + // We ignore local deps. + debug!("Ignoring local path dependency on {:?}", path); + continue; + } + all_dep_names.insert(dep.clone()); + if let Some(dep_spec_to_merge) = merged_cargo_toml.build_dependencies.get_mut(&dep) { + dep_spec_to_merge + .merge(dep_spec) + .context(format!("Failed to merge multiple dependencies on {}", dep))?; + } else { + merged_cargo_toml.build_dependencies.insert(dep, dep_spec); + } + } + + for (dep, dep_spec) in dev_dependencies.into_iter() { + if let VersionSpec::Local(_) = dep_spec.version { + // We ignore local deps. + debug!("Ignoring local path dependency on {:?}", path); + continue; + } + all_dep_names.insert(dep.clone()); + if let Some(dep_spec_to_merge) = merged_cargo_toml.dev_dependencies.get_mut(&dep) { + dep_spec_to_merge + .merge(dep_spec) + .context(format!("Failed to merge multiple dependencies on {}", dep))?; + } else { + merged_cargo_toml.dev_dependencies.insert(dep, dep_spec); + } + } + + for (repo, deps) in patch { + if let Some(repo_map) = merged_cargo_toml.patch.get_mut(&repo) { + for (dep, dep_spec) in deps { + if let Some(existing_dep_spec) = repo_map.get_mut(&dep) { + existing_dep_spec.merge(dep_spec).context(format!( + "Failed to merge multiple patches of {} in {}", + dep, repo + ))?; + } else { + repo_map.insert(dep, dep_spec); + } + } + } else { + merged_cargo_toml.patch.insert(repo, deps); + } + } + + labels_to_deps.insert(label.clone(), all_dep_names); + } + + // Check for conflicts between packages in Cargo.toml and packages in crate_universe(). + // TODO: only mark packages as conflicting if names are the same but versions are incompatible. + let cargo_toml_package_set: BTreeSet<_> = + merged_cargo_toml.dependencies.keys().cloned().collect(); + let repo_rule_package_set: BTreeSet<_> = packages.iter().map(|p| p.name.clone()).collect(); + + let conflicting_pkgs: BTreeSet<_> = cargo_toml_package_set + .intersection(&repo_rule_package_set) + .collect(); + if !conflicting_pkgs.is_empty() { + let conflicting_pkgs: Vec<_> = conflicting_pkgs.into_iter().cloned().collect(); + // TODO: Mention which one, from labels_to_deps. + return Err(anyhow!("The following package{} provided both in a Cargo.toml and in the crate_universe repository rule: {}.", if conflicting_pkgs.len() == 1 { " was" } else { "s were" }, conflicting_pkgs.join(", "))); + } + + for package in packages { + merged_cargo_toml.dependencies.insert( + package.name, + DepSpec { + default_features: true, + features: package.features.into_iter().collect(), + version: VersionSpec::Semver(package.semver), + }, + ); + } + + Ok((merged_cargo_toml, labels_to_deps)) +} + +impl TryFrom<&str> for CargoToml { + type Error = anyhow::Error; + + fn try_from(value: &str) -> Result { + Ok(toml::from_str(value)?) + } +} + +impl From for toml::Value { + fn from(cargo_toml: CargoToml) -> Value { + let CargoToml { + package, + dependencies, + build_dependencies, + dev_dependencies, + patch, + _ignored, + } = cargo_toml; + + let mut v = toml::value::Table::new(); + + v.insert(String::from("package"), package.into()); + + v.insert( + String::from("lib"), + toml::Value::Table({ + let mut table = toml::value::Table::new(); + // cargo-metadata fails without this key. + table.insert( + String::from("path"), + toml::Value::String(String::from("doesnotexist.rs")), + ); + table + }), + ); + + if !dependencies.is_empty() { + v.insert( + String::from("dependencies"), + table_of_dep_specs_to_toml(dependencies), + ); + } + if !build_dependencies.is_empty() { + v.insert( + String::from("build-dependencies"), + table_of_dep_specs_to_toml(build_dependencies), + ); + } + if !dev_dependencies.is_empty() { + v.insert( + String::from("dev-dependencies"), + table_of_dep_specs_to_toml(dev_dependencies), + ); + } + + if !patch.is_empty() { + v.insert( + String::from("patch"), + toml::Value::Table({ + let mut table = toml::value::Table::new(); + for (repo, patches) in patch { + table.insert(repo, table_of_dep_specs_to_toml(patches)); + } + table + }), + ); + } + + toml::Value::Table(v) + } +} + +fn table_of_dep_specs_to_toml(table: BTreeMap) -> toml::Value { + toml::Value::Table( + table + .into_iter() + .filter_map(|(dep_name, dep_spec)| { + dep_spec.to_cargo_toml_dep().map(|dep| (dep_name, dep)) + }) + .collect(), + ) +} + +impl From for toml::Value { + fn from(package: Package) -> Self { + let Package { name, version } = package; + + let mut v = toml::value::Table::new(); + v.insert(String::from("name"), toml::Value::String(name)); + v.insert( + String::from("version"), + toml::Value::String(format!("{}", version)), + ); + + toml::Value::Table(v) + } +} + +impl<'de> Deserialize<'de> for DepSpec { + fn deserialize(deserializer: D) -> Result>::Error> + where + D: Deserializer<'de>, + { + deserializer.deserialize_any(crate::serde_utils::DepSpecDeserializer) + } +} + +impl DepSpec { + fn merge(&mut self, other: DepSpec) -> Result<(), anyhow::Error> { + self.default_features |= other.default_features; + + self.features.extend(other.features.clone()); + + match (&mut self.version, &other.version) { + (v1, v2) if v1 == v2 => {} + (VersionSpec::Semver(v1), VersionSpec::Semver(v2)) => { + self.version = VersionSpec::Semver(VersionReq::parse(&format!("{}, {}", v1, v2))?) + } + (v1 @ VersionSpec::Git { .. }, v2 @ VersionSpec::Git { .. }) => { + return Err(anyhow!( + "Can't merge different git versions of the same dependency (saw {:?} and {:?})", + v1, + v2 + )) + } + (v1, v2) => { + return Err(anyhow!( + "Can't merge semver and git versions of the same dependency (saw: {:?} and {:?})", + v1, + v2 + )) + } + } + Ok(()) + } + + fn to_cargo_toml_dep(self) -> Option { + let Self { + default_features, + features, + version, + } = self; + + let mut v = toml::value::Table::new(); + v.insert( + String::from("default-features"), + toml::Value::Boolean(default_features), + ); + v.insert( + String::from("features"), + toml::Value::Array(features.into_iter().map(toml::Value::String).collect()), + ); + match version { + VersionSpec::Semver(version) => { + v.insert( + String::from("version"), + toml::Value::String(format!("{}", version)), + ); + } + VersionSpec::Git { url, rev, tag } => { + v.insert(String::from("git"), toml::Value::String(url)); + if let Some(rev) = rev { + v.insert(String::from("rev"), toml::Value::String(rev)); + } + if let Some(tag) = tag { + v.insert(String::from("tag"), toml::Value::String(tag)); + } + } + VersionSpec::Local(path) => { + eprintln!("Ignoring local path dependency on {:?}", path); + return None; + } + } + + Some(toml::Value::Table(v)) + } +} diff --git a/cargo/crate_universe_resolver/src/renderer.rs b/cargo/crate_universe_resolver/src/renderer.rs new file mode 100644 index 0000000000..9f13555dcf --- /dev/null +++ b/cargo/crate_universe_resolver/src/renderer.rs @@ -0,0 +1,476 @@ +use cargo_raze::context::{CrateContext, CrateDependencyContext, CrateTargetedDepContext}; +use semver::Version; +use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; +use std::fs::File; +use std::io::Write; +use tera::{self, Context, Tera}; + +use crate::config; +use crate::resolver::Dependencies; +use std::path::Path; + +pub struct RenderConfig { + pub repo_rule_name: String, + pub repository_template: String, + pub rules_rust_workspace_name: String, +} + +pub struct Renderer { + config: RenderConfig, + hash: String, + internal_renderer: Tera, + transitive_packages: Vec, + member_packages_version_mapping: Dependencies, + label_to_crates: BTreeMap>, +} + +// Get default and targeted metadata, collated per Bazel condition (which corresponds to a triple). +// The default metadata is included in every triple. +fn get_per_triple_metadata(package: &CrateContext) -> BTreeMap { + let mut per_triple_metadata: BTreeMap = BTreeMap::new(); + + // Always add a catch-all to cover the non-targeted dep case. + // We merge in the default_deps after the next loop. + per_triple_metadata.insert( + String::from("//conditions:default"), + CrateTargetedDepContext { + target: "Default".to_owned(), + deps: empty_deps_context(), + conditions: vec!["//conditions:default".to_owned()], + }, + ); + + for dep_context in &package.targeted_deps { + dep_context.conditions.iter().for_each(|condition| { + let targeted_dep_ctx = per_triple_metadata.entry(condition.to_owned()).or_insert( + CrateTargetedDepContext { + target: "".to_owned(), + deps: empty_deps_context(), + conditions: vec![condition.clone()], + }, + ); + + // Mention all the targets that translated into the current condition (ie. current triplet). + targeted_dep_ctx + .target + .push_str(&format!(" {}", &dep_context.target)); + + targeted_dep_ctx + .deps + .dependencies + .extend(dep_context.deps.dependencies.iter().cloned()); + targeted_dep_ctx + .deps + .proc_macro_dependencies + .extend(dep_context.deps.proc_macro_dependencies.iter().cloned()); + targeted_dep_ctx + .deps + .data_dependencies + .extend(dep_context.deps.data_dependencies.iter().cloned()); + targeted_dep_ctx + .deps + .build_dependencies + .extend(dep_context.deps.build_dependencies.iter().cloned()); + targeted_dep_ctx.deps.build_proc_macro_dependencies.extend( + dep_context + .deps + .build_proc_macro_dependencies + .iter() + .cloned(), + ); + targeted_dep_ctx + .deps + .build_data_dependencies + .extend(dep_context.deps.build_data_dependencies.iter().cloned()); + targeted_dep_ctx + .deps + .dev_dependencies + .extend(dep_context.deps.dev_dependencies.iter().cloned()); + targeted_dep_ctx + .deps + .aliased_dependencies + .extend(dep_context.deps.aliased_dependencies.iter().cloned()); + }); + } + + // Now also add the non-targeted deps to each target. + for ctx in per_triple_metadata.values_mut() { + ctx.deps + .dependencies + .extend(package.default_deps.dependencies.iter().cloned()); + ctx.deps + .proc_macro_dependencies + .extend(package.default_deps.proc_macro_dependencies.iter().cloned()); + ctx.deps + .data_dependencies + .extend(package.default_deps.data_dependencies.iter().cloned()); + ctx.deps + .build_dependencies + .extend(package.default_deps.build_dependencies.iter().cloned()); + ctx.deps.build_proc_macro_dependencies.extend( + package + .default_deps + .build_proc_macro_dependencies + .iter() + .cloned(), + ); + ctx.deps + .build_data_dependencies + .extend(package.default_deps.build_data_dependencies.iter().cloned()); + ctx.deps + .dev_dependencies + .extend(package.default_deps.dev_dependencies.iter().cloned()); + ctx.deps + .aliased_dependencies + .extend(package.default_deps.aliased_dependencies.iter().cloned()); + } + + per_triple_metadata +} + +fn empty_deps_context() -> CrateDependencyContext { + CrateDependencyContext { + dependencies: vec![], + proc_macro_dependencies: vec![], + data_dependencies: vec![], + build_dependencies: vec![], + build_proc_macro_dependencies: vec![], + build_data_dependencies: vec![], + dev_dependencies: vec![], + aliased_dependencies: vec![], + } +} + +impl Renderer { + pub fn new( + config: RenderConfig, + hash: String, + transitive_packages: Vec, + member_packages_version_mapping: Dependencies, + label_to_crates: BTreeMap>, + ) -> Renderer { + let mut internal_renderer = Tera::new("src/not/a/dir/*").unwrap(); + internal_renderer + .add_raw_templates(vec![ + ( + "templates/partials/build_script.template", + include_str!("templates/partials/build_script.template"), + ), + ( + "templates/partials/rust_binary.template", + include_str!("templates/partials/rust_binary.template"), + ), + ( + "templates/partials/rust_library.template", + include_str!("templates/partials/rust_library.template"), + ), + ( + "templates/partials/common_attrs.template", + include_str!("templates/partials/common_attrs.template"), + ), + ( + "templates/crate.BUILD.template", + include_str!("templates/crate.BUILD.template"), + ), + ( + "templates/partials/targeted_aliases.template", + include_str!("templates/partials/targeted_aliases.template"), + ), + ( + "templates/partials/targeted_dependencies.template", + include_str!("templates/partials/targeted_dependencies.template"), + ), + ( + "templates/partials/targeted_data_dependencies.template", + include_str!("templates/partials/targeted_data_dependencies.template"), + ), + ( + "templates/partials/targeted_build_script_dependencies.template", + include_str!("templates/partials/targeted_build_script_dependencies.template"), + ), + ( + "templates/partials/targeted_build_script_data_dependencies.template", + include_str!( + "templates/partials/targeted_build_script_data_dependencies.template" + ), + ), + ( + "templates/partials/default_data_dependencies.template", + include_str!("templates/partials/default_data_dependencies.template"), + ), + ]) + .unwrap(); + + Self { + config, + hash, + internal_renderer, + transitive_packages, + member_packages_version_mapping, + label_to_crates, + } + } + + pub fn render(&self, mut output_file: &File) -> anyhow::Result<()> { + let build_files = self + .transitive_packages + .iter() + .map(|package| { + let mut package = package; + let per_triple_metadata = get_per_triple_metadata(&package); + + let mut backing_package; + if let Some(git_repo) = &package.source_details.git_data { + if let Some(prefix_to_strip) = &git_repo.path_to_crate_root { + backing_package = package.clone(); + for mut target in backing_package + .targets + .iter_mut() + .chain(backing_package.build_script_target.iter_mut()) + { + let path = Path::new(&target.path); + let prefix_to_strip_path = Path::new(prefix_to_strip); + target.path = path + .strip_prefix(prefix_to_strip_path) + .unwrap() + .to_str() + .unwrap() + .to_owned(); + } + + package = &backing_package; + } + } + + let mut context = Context::new(); + context.insert("crate", &package); + context.insert("targeted_metadata", &per_triple_metadata); + let rendered_crate_build_file = self + .internal_renderer + .render("templates/crate.BUILD.template", &context)?; + // TODO: Write test which has transitive deps on two proc-macro2 0.1.10 and 1.0.21 which differ in build-script-having-ness. + Ok(( + (package.pkg_name.clone(), package.pkg_version.clone()), + rendered_crate_build_file, + )) + }) + .collect::, tera::Error>>()?; + + write!( + output_file, + r#"# rules_rust crate_universe file format 1 +# config hash {hash} + +load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository") + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def pinned_rust_install(): +"#, + hash = self.hash, + )?; + for package in &self.transitive_packages { + let package_version = format!("{}", package.pkg_version); + if let Some(git_repo) = &package.source_details.git_data { + write!( + output_file, + r#" new_git_repository( + name = "{repository_name}", + strip_prefix = "{strip_prefix}", + build_file_content = """{build_file_content}""", + remote = "{git_remote}", + # TODO: tag? + commit = "{git_commit}", + ) + +"#, + // TODO: Don't copy this implementation from workspace_path_and_default_target + repository_name = + config::crate_to_repo_rule_name(&self.config.repo_rule_name, &package.pkg_name, &package_version), + build_file_content = build_files + .get(&(package.pkg_name.clone(), package.pkg_version.clone())) + .unwrap(), + git_remote = git_repo.remote, + git_commit = git_repo.commit, + strip_prefix = git_repo.path_to_crate_root.clone().unwrap_or_default(), + )?; + } else { + write!( + output_file, + r#" http_archive( + name = "{repository_name}", + # TODO: Allow configuring where rust_library comes from + build_file_content = """{build_file_content}""",{maybe_crate_sha256} + strip_prefix = "{name}-{version}", + type = "tar.gz", + url = "{url}", + ) + +"#, + // TODO: Don't copy this implementation from workspace_path_and_default_target + repository_name = + config::crate_to_repo_rule_name(&self.config.repo_rule_name, &package.pkg_name, &package_version), + name = package.pkg_name, + version = package.pkg_version, + maybe_crate_sha256 = if let Some(crate_sha256) = &package.sha256 { + format!("\n sha256 = \"{}\",", crate_sha256) + } else { + String::new() + }, + url = self + .config + .repository_template + .replace("{crate}", &package.pkg_name) + .replace("{version}", &package.pkg_version.to_string()), + build_file_content = build_files + .get(&(package.pkg_name.clone(), package.pkg_version.clone())) + .unwrap(), + )?; + } + } + + let (proc_macro_crates, default_crates): (Vec<_>, Vec<_>) = self + .member_packages_version_mapping + .normal + .iter() + .partition(|(name, version)| { + self.transitive_packages + .iter() + .find(|package| *package.pkg_name == **name && package.pkg_version == **version) + // UNWRAP: cargo-metadata should ensure any package we're looking up is in the transitive packages. + .unwrap() + .targets + .iter() + .any(|target| target.kind == "proc-macro") + }); + + let mut crate_repo_names_inner = BTreeMap::new(); + crate_repo_names_inner.extend(&self.member_packages_version_mapping.normal); + crate_repo_names_inner.extend(&self.member_packages_version_mapping.build); + crate_repo_names_inner.extend(&self.member_packages_version_mapping.dev); + + // Now, create the crate() macro for the user. + write!( + output_file, + r##" +CRATE_TARGET_NAMES = {{ +{crate_repo_names_inner}}} + +def crate(crate_name): + """Return the name of the target for the given crate. + """ + target_name = CRATE_TARGET_NAMES.get(crate_name) + if target_name == None: + fail("Unknown crate name: {{}}".format(crate_name)) + return target_name + +def all_deps(): + """Return all standard dependencies explicitly listed in the Cargo.toml or packages list.""" + return [ + crate(crate_name) for crate_name in [{crate_names} + ] + ] + +def all_proc_macro_deps(): + """Return all proc-macro dependencies explicitly listed in the Cargo.toml or packages list.""" + return [ + crate(crate_name) for crate_name in [{proc_macro_crate_names} + ] + ] + +def crates_from(label): + mapping = {{ + {label_to_crates} + }} + return mapping[_absolutify(label)] + +def dev_crates_from(label): + mapping = {{ + {label_to_dev_crates} + }} + return mapping[_absolutify(label)] + +def build_crates_from(label): + mapping = {{ + {label_to_build_crates} + }} + return mapping[_absolutify(label)] + +def proc_macro_crates_from(label): + mapping = {{ + {label_to_proc_macro_crates} + }} + return mapping[_absolutify(label)] + +def _absolutify(label): + if label.startswith("//") or label.startswith("@"): + return label + if label.startswith(":"): + return "//" + native.package_name() + label + return "//" + native.package_name() + ":" + label +"##, + crate_repo_names_inner = crate_repo_names_inner + .iter() + .map(|(crate_name, crate_version)| format!( + r#" "{}": "{}",{newline}"#, + crate_name, + config::crate_to_label(&self.config.repo_rule_name, &crate_name, &crate_version.to_string()), + newline = '\n', + )) + .collect::>() + .join(""), + crate_names = default_crates + .iter() + .map(|(crate_name, _crate_version)| format!( + r#"{newline} "{}","#, + crate_name, + newline = '\n' + )) + .collect::>() + .join(""), + proc_macro_crate_names = proc_macro_crates + .iter() + .map(|(crate_name, _crate_version)| format!( + r#"{newline} "{}","#, + crate_name, + newline = '\n' + )) + .collect::>() + .join(""), + label_to_crates = + label_to_crates(&default_crates, &self.label_to_crates).join("\n "), + label_to_dev_crates = label_to_crates( + &self.member_packages_version_mapping.dev.iter().collect(), + &self.label_to_crates, + ) + .join("\n "), + label_to_build_crates = label_to_crates( + &self.member_packages_version_mapping.build.iter().collect(), + &self.label_to_crates + ) + .join("\n "), + label_to_proc_macro_crates = + label_to_crates(&proc_macro_crates, &self.label_to_crates).join("\n "), + )?; + Ok(()) + } +} + +fn label_to_crates( + crates: &Vec<(&String, &Version)>, + label_to_crates: &BTreeMap>, +) -> Vec { + let crate_names: HashSet<&String> = crates.iter().map(|(name, _)| *name).collect(); + label_to_crates + .iter() + .map(|(label, all_crates)| { + let values = all_crates + .iter() + .filter(|crate_name| crate_names.contains(crate_name)) + .map(|crate_name| format!(r#"crate("{}")"#, crate_name)) + .collect::>() + .join(", "); + format!(r#""{label}": [{values}],"#, label = label, values = values) + }) + .collect::>() +} diff --git a/cargo/crate_universe_resolver/src/resolver.rs b/cargo/crate_universe_resolver/src/resolver.rs new file mode 100644 index 0000000000..27c292ddd5 --- /dev/null +++ b/cargo/crate_universe_resolver/src/resolver.rs @@ -0,0 +1,370 @@ +use std::borrow::Cow; +use std::collections::{BTreeMap, BTreeSet, HashMap}; +use std::path::{Path, PathBuf}; +use std::process::Stdio; + +use cargo_metadata::{DependencyKind, Metadata, MetadataCommand}; +use cargo_raze::context::CrateContext; +use cargo_raze::metadata::RazeMetadataFetcher; +use cargo_raze::planning::{BuildPlanner, BuildPlannerImpl}; +use cargo_raze::settings::{GenMode, RazeSettings}; +use log::trace; +use semver::{Version, VersionReq}; +use sha2::{Digest, Sha256}; + +use crate::consolidator::{Consolidator, ConsolidatorConfig, ConsolidatorOverride}; +use crate::renderer::RenderConfig; +use crate::NamedTempFile; +use anyhow::Context; +use url::Url; + +pub struct ResolverConfig { + pub cargo: PathBuf, + pub index_url: Url, +} + +pub struct Resolver { + pub toml: toml::Value, + pub resolver_config: ResolverConfig, + pub consolidator_config: ConsolidatorConfig, + pub render_config: RenderConfig, + pub target_triples: Vec, + pub label_to_crates: BTreeMap>, + digest: Option, +} + +// TODO: Interesting edge cases +// - you can pass deps using: version number path on fs, git repo. +// - you can rename crates you depend on. +pub struct ResolvedArtifactsWithMetadata { + pub resolved_packages: Vec, + pub member_packages_version_mapping: HashMap, +} + +#[derive(Debug)] +pub struct Dependencies { + pub normal: BTreeMap, + pub build: BTreeMap, + pub dev: BTreeMap, +} + +impl Resolver { + pub fn new( + toml: toml::Value, + resolver_config: ResolverConfig, + consolidator_config: ConsolidatorConfig, + render_config: RenderConfig, + target_triples: Vec, + label_to_crates: BTreeMap>, + ) -> Resolver { + Resolver { + toml, + resolver_config, + consolidator_config, + render_config, + target_triples, + label_to_crates, + digest: None, + } + } + + pub fn digest(&mut self) -> anyhow::Result { + // TODO: Ignore * .cargo config files outside of the workspace + + if self.digest.is_none() { + // TODO: Combine values better + let mut hasher = Sha256::new(); + // Mix in the version of this crate, which encompasses all logic and templates. + // This is probably a wild over-estimate of what should go in the cache key. + // NOTE: In debug mode, this mixes the digest of the executable, rather than the version number. + hasher.update(version_for_hashing()?); + hasher.update(b"\0"); + + // If new fields are added, you should decide whether they need hashing. + // Hint: They probably do. If not, please add a comment justifying why not. + let Self { + toml, + render_config: + RenderConfig { + repo_rule_name, + repository_template, + rules_rust_workspace_name, + }, + consolidator_config: ConsolidatorConfig { overrides }, + resolver_config: ResolverConfig { cargo, index_url }, + + // This is what we're computing. + digest: _ignored, + target_triples, + label_to_crates, + } = &self; + + hasher.update(repo_rule_name.as_str().as_bytes()); + hasher.update(b"\0"); + hasher.update(repository_template.as_str().as_bytes()); + hasher.update(b"\0"); + hasher.update(rules_rust_workspace_name.as_bytes()); + hasher.update(b"\0"); + + hasher.update(get_cargo_version(&cargo)?); + hasher.update(b"\0"); + hasher.update(index_url.as_str().as_bytes()); + hasher.update(b"\0"); + for target_triple in target_triples { + hasher.update(target_triple); + hasher.update(b"\0"); + } + hasher.update(b"\0"); + for (label, crates) in label_to_crates.iter() { + hasher.update(label.as_bytes()); + hasher.update(b"\0"); + for krate in crates.iter() { + hasher.update(krate.as_bytes()); + hasher.update(b"\0"); + } + } + + // TODO: improve the caching by generating a lockfile over the resolve rather than over + // the render. If the digest contains only input for the cargo dependency resolution + // then we don't need to re-pin when making changes to things that only affect the + // generated bazel file. + for ( + crate_name, + ConsolidatorOverride { + extra_rust_env_vars, + extra_build_script_env_vars, + extra_bazel_deps, + extra_bazel_data_deps, + extra_build_script_bazel_deps, + extra_build_script_bazel_data_deps, + features_to_remove, + }, + ) in overrides + { + hasher.update(crate_name); + hasher.update(b"\0"); + for (env_key, env_val) in extra_rust_env_vars { + hasher.update(env_key); + hasher.update(b"\0"); + hasher.update(env_val); + hasher.update(b"\0"); + } + for (env_key, env_val) in extra_build_script_env_vars { + hasher.update(env_key); + hasher.update(b"\0"); + hasher.update(env_val); + hasher.update(b"\0"); + } + for dep_map in &[ + extra_bazel_deps, + extra_bazel_data_deps, + extra_build_script_bazel_deps, + extra_build_script_bazel_data_deps, + ] { + for (target, deps) in *dep_map { + hasher.update(target); + hasher.update(b"\0"); + for dep in deps { + hasher.update(dep); + hasher.update(b"\0"); + } + } + } + for feature in features_to_remove { + hasher.update(feature); + hasher.update(b"\n"); + } + } + + for (env_name, env_value) in std::env::vars() { + // The CARGO_HOME variable changes where cargo writes and reads config, and caches. + // We currently use the user's Cargo home (by not overwriting it) so we should + // allow users to use a custom path to one. + if env_name == "CARGO_HOME" { + continue; + } + // We hope that other env vars don't cause problems... + if env_name.starts_with("CARGO") && env_name != "CARGO_NET_GIT_FETCH_WITH_CLI" { + eprintln!("Warning: You have the {} environment variable set - this may affect your crate_universe output", env_name); + hasher.update(env_name); + hasher.update(b"\0"); + hasher.update(env_value); + hasher.update(b"\0"); + } + } + + hasher.update(toml.to_string().as_bytes()); + hasher.update(b"\0"); + + // TODO: Include all files referenced by the toml. + self.digest = Some(hex::encode(hasher.finalize())); + } + // UNWRAP: Guaranteed by above code. + Ok(self.digest.clone().unwrap()) + } + + pub fn resolve(mut self) -> anyhow::Result { + let toml_str = self.toml.to_string(); + trace!("Resolving for generated Cargo.toml:\n{}", toml_str); + let merged_cargo_toml = NamedTempFile::with_str_content("Cargo.toml", &toml_str) + .context("Writing intermediate Cargo.toml")?; + + // RazeMetadataFetcher only uses the scheme+host+port of this URL. + // If it used the path, we'd run into issues escaping the {s and }s from the template, + // but the scheme+host+port should be fine. + let repository_template_url = Url::parse(&self.render_config.repository_template) + .context("Parsing repository template URL")?; + let md_fetcher = RazeMetadataFetcher::new( + &self.resolver_config.cargo, + repository_template_url, + self.resolver_config.index_url.clone(), + ); + let metadata = md_fetcher + .fetch_metadata(merged_cargo_toml.path().parent().unwrap(), None, None) + .context("Failed fetching metadata")?; + + let raze_settings = RazeSettings { + gen_workspace_prefix: self.render_config.repo_rule_name.clone(), + genmode: GenMode::Remote, + + // TODO: These are ?all ignored + workspace_path: "".to_string(), + package_aliases_dir: "".to_string(), + render_package_aliases: false, + target: None, + targets: Some(self.target_triples.clone()), + crates: HashMap::default(), + output_buildfile_suffix: "".to_string(), + default_gen_buildrs: true, + registry: self.render_config.repository_template.clone(), + binary_deps: HashMap::default(), + index_url: self.resolver_config.index_url.as_str().to_owned(), + rust_rules_workspace_name: self.render_config.rules_rust_workspace_name.clone(), + vendor_dir: "".to_string(), + experimental_api: false, + }; + + let planner = BuildPlannerImpl::new(metadata, raze_settings); + + let planned_build = planner.plan_build(None).context("Failed planning build")?; + + let mut resolved_packages = planned_build.crate_contexts; + resolved_packages + .sort_by(|l, r| (&l.pkg_name, &l.pkg_version).cmp(&(&r.pkg_name, &r.pkg_version))); + + let member_packages_version_mapping = + self.get_member_packages_version_mapping(merged_cargo_toml.path(), &resolved_packages); + + // TODO: generate a cargo toml from metadata in the bazel rule, when no cargo toml is present. + + let digest = self.digest().context("Digesting Resolver inputs")?; + Ok(Consolidator::new( + self.consolidator_config, + self.render_config, + digest, + self.target_triples, + resolved_packages, + member_packages_version_mapping?, + self.label_to_crates, + )) + } + + fn get_member_packages_version_mapping( + &self, + merged_cargo_toml: &Path, + resolved_artifacts: &[CrateContext], + ) -> anyhow::Result { + let merged_cargo_metadata = MetadataCommand::new() + .cargo_path(&self.resolver_config.cargo) + .manifest_path(merged_cargo_toml) + .no_deps() + .exec() + .context("Failed to run cargo metadata")?; + + Ok(Dependencies { + normal: Self::build_version_mapping_for_kind( + DependencyKind::Normal, + &merged_cargo_metadata, + resolved_artifacts, + ), + build: Self::build_version_mapping_for_kind( + DependencyKind::Build, + &merged_cargo_metadata, + resolved_artifacts, + ), + dev: Self::build_version_mapping_for_kind( + DependencyKind::Development, + &merged_cargo_metadata, + resolved_artifacts, + ), + }) + } + + fn build_version_mapping_for_kind( + kind: DependencyKind, + merged_cargo_metadata: &Metadata, + resolved_artifacts: &[CrateContext], + ) -> BTreeMap { + // Build the intersection of version requirements for all the member (i.e. toplevel) packages + // of our workspace. + let mut member_package_version_reqs: HashMap> = Default::default(); + for package in &merged_cargo_metadata.packages { + for dep in &package.dependencies { + if dep.kind == kind { + member_package_version_reqs + .entry(dep.name.clone()) + .or_default() + .push(dep.req.clone()); + } + } + } + + let mut member_package_version_mapping = BTreeMap::new(); + for package in resolved_artifacts { + // If the package name matches one of the member packages' direct dependencies, consider it + // for the final version: insert it into the map if we didn't have one yet, take the highest + // version so far if there was already one. + if let Some(version_req) = member_package_version_reqs.get(&package.pkg_name) { + if version_req + .iter() + .all(|req| req.matches(&package.pkg_version)) + { + let current_pkg_version = member_package_version_mapping + .entry(package.pkg_name.clone()) + .or_insert_with(|| Version::new(0, 0, 0)); + if *current_pkg_version < package.pkg_version { + *current_pkg_version = package.pkg_version.clone(); + } + } + } + } + member_package_version_mapping + } +} + +fn get_cargo_version(cargo_path: &Path) -> anyhow::Result> { + let output = std::process::Command::new(cargo_path) + .arg("--version") + .stderr(Stdio::inherit()) + .output() + .context("Invoking cargo --version")?; + if !output.status.success() { + panic!( + "TODO: cargo --version failed with exit code {:?}", + output.status.code() + ); + } + Ok(output.stdout) +} + +fn version_for_hashing() -> anyhow::Result> { + if cfg!(debug_assertions) { + let current_exe = + std::env::current_exe().context("Couldn't get current executable path")?; + Ok(Cow::Owned( + std::fs::read(current_exe).context("Couldn't read current executable path")?, + )) + } else { + Ok(Cow::Borrowed(env!("CARGO_PKG_VERSION").as_bytes())) + } +} diff --git a/cargo/crate_universe_resolver/src/serde_utils.rs b/cargo/crate_universe_resolver/src/serde_utils.rs new file mode 100644 index 0000000000..ceac87f3ed --- /dev/null +++ b/cargo/crate_universe_resolver/src/serde_utils.rs @@ -0,0 +1,96 @@ +use crate::parser::{DepSpec, VersionSpec}; +use serde::de::{Error, MapAccess, Visitor}; +use serde::{de, Deserialize}; +use std::collections::BTreeSet; +use std::fmt; +use std::path::PathBuf; +use std::str::FromStr; + +// Work around https://github.com/serde-rs/serde/issues/368 +const fn always_true() -> bool { + true +} + +// See https://stackoverflow.com/questions/54761790/how-to-deserialize-with-for-a-container-using-serde-in-rust +pub struct DepSpecDeserializer; + +#[derive(Debug, Default, Deserialize)] +#[serde(deny_unknown_fields)] +struct RawDepSpec { + #[serde(rename = "default-features", default = "always_true")] + default_features: bool, + #[serde(default = "BTreeSet::new")] + features: BTreeSet, + version: Option, + git: Option, + rev: Option, + tag: Option, + path: Option, + + #[serde(skip_serializing)] + optional: Option, +} + +impl FromStr for DepSpec { + type Err = semver::ReqParseError; + + fn from_str(s: &str) -> Result { + let version = VersionSpec::Semver(semver::VersionReq::parse(s)?); + Ok(DepSpec { + version, + default_features: true, + features: BTreeSet::new(), + }) + } +} + +impl<'de> Visitor<'de> for DepSpecDeserializer { + type Value = DepSpec; + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("string or map") + } + + fn visit_str(self, value: &str) -> Result + where + E: de::Error, + { + FromStr::from_str(value) + .map_err(|err| E::custom(format!("Error parsing string in Cargo.toml: {:?}", err))) + } + + fn visit_map(self, visitor: M) -> Result + where + M: MapAccess<'de>, + { + let copy: RawDepSpec = + Deserialize::deserialize(de::value::MapAccessDeserializer::new(visitor))?; + + let RawDepSpec { + default_features, + features, + version, + git, + rev, + tag, + path, + // We always generate deps for optional deps. + optional: _, + } = copy; + + let version = match (version, git, path, rev, tag) { + (Some(version), None, None, None, None) => { + VersionSpec::Semver(version.parse().map_err(M::Error::custom)?) + } + (None, Some(url), None, rev, tag) => VersionSpec::Git { url, rev, tag }, + (None, None, Some(path), None, None) => VersionSpec::Local(path), + _ => return Err(M::Error::custom("Must set exactly one of version, git, or path, and may not specify git specifiers for non-git deps.")), + }; + + Ok(DepSpec { + default_features, + features, + version, + }) + } +} diff --git a/cargo/crate_universe_resolver/src/templates/crate.BUILD.template b/cargo/crate_universe_resolver/src/templates/crate.BUILD.template new file mode 100644 index 0000000000..c92b1f0859 --- /dev/null +++ b/cargo/crate_universe_resolver/src/templates/crate.BUILD.template @@ -0,0 +1,40 @@ +# buildifier: disable=load +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", + "rust_library", + "rust_test", +) + +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + +package(default_visibility = [ + "//visibility:public", +]) + +licenses([ + "{{crate.license.rating}}", # {{crate.license.name}} +]) + +# Generated targets +{%- set crate_name_sanitized = crate.pkg_name | replace(from="-", to="_") %} +{%- if crate.build_script_target %} +{% include "templates/partials/build_script.template" %} +{%- endif %} +{%- for target in crate.targets %} +{%- set target_name_sanitized = target.name | replace(from="-", to="_") %} +{%- if target.kind == "lib" %} +{% include "templates/partials/rust_library.template" %} +{%- elif target.kind == "bin" %} +{% include "templates/partials/rust_binary.template" %} +{%- elif target.kind == "proc-macro" %} +{% include "templates/partials/rust_library.template" %} +{%- elif target.kind == "dylib" %} +{% include "templates/partials/rust_library.template" %} +{%- elif target.kind == "rlib" %} +{% include "templates/partials/rust_library.template" %} +{%- else %} +# Unsupported target "{{ target.name }}" with type "{{ target.kind }}" omitted +{%- endif %} +{%- endfor %} diff --git a/cargo/crate_universe_resolver/src/templates/partials/build_script.template b/cargo/crate_universe_resolver/src/templates/partials/build_script.template new file mode 100644 index 0000000000..f3dc28ca10 --- /dev/null +++ b/cargo/crate_universe_resolver/src/templates/partials/build_script.template @@ -0,0 +1,60 @@ +# buildifier: disable=load-on-top +load( + "@rules_rust//cargo:cargo_build_script.bzl", + "cargo_build_script", +) + +# buildifier: leave-alone +cargo_build_script( + name = "{{ crate_name_sanitized }}_build_script", + srcs = glob(["**/*.rs"]), + {%- if crate.build_script_target.path %} + crate_root = "{{ crate.build_script_target.path }}", + {%- else %} + crate_root = "build.rs", + {%- endif %} + edition = "{{ crate.edition }}", + deps = [ + {%- for dependency in crate.default_deps.build_dependencies %} + "{{dependency.buildable_target}}", + {%- endfor %} + ] + {%- if crate.targeted_deps %} + {%- include "templates/partials/targeted_build_script_dependencies.template" -%}, + {%- else -%}, + {%- endif %} + {%- if crate.default_deps.build_proc_macro_dependencies %} + proc_macro_deps = [ + {%- for dependency in crate.default_deps.build_proc_macro_dependencies %} + "{{dependency.buildable_target}}", + {%- endfor %} + ], + {%- endif %} + rustc_flags = [ + "--cap-lints=allow", + ], + crate_features = [ + {%- for feature in crate.features %} + "{{feature}}", + {%- endfor %} + ], + build_script_env = { + {%- for key, value in crate.raze_settings.buildrs_additional_environment_variables %} + "{{key}}": "{{value}}", + {%- endfor %} + }, + {%- if crate.links %} + links = "{{ crate.links }}", + {%- endif %} + data = {% include "templates/partials/default_data_dependencies.template" -%} + {%- if crate.targeted_deps %} + {%- include "templates/partials/targeted_build_script_data_dependencies.template" -%}, + {%- else -%}, + {%- endif %} + tags = [ + "cargo-raze", + "manual", + ], + version = "{{ crate.pkg_version }}", + visibility = ["//visibility:private"], +) diff --git a/cargo/crate_universe_resolver/src/templates/partials/common_attrs.template b/cargo/crate_universe_resolver/src/templates/partials/common_attrs.template new file mode 100644 index 0000000000..d170599f50 --- /dev/null +++ b/cargo/crate_universe_resolver/src/templates/partials/common_attrs.template @@ -0,0 +1,41 @@ + srcs = glob(["**/*.rs"]), + crate_root = "{{ target.path }}", + edition = "{{ target.edition }}", + {%- if crate.default_deps.proc_macro_dependencies %} + proc_macro_deps = [ + {%- for dependency in crate.default_deps.proc_macro_dependencies %} + "{{dependency.buildable_target}}", + {%- endfor %} + ], + {%- endif %} + rustc_flags = [ + "--cap-lints=allow", + {%- for flag in crate.raze_settings.additional_flags %} + "{{flag}}", + {%- endfor %} + ], + {%- if crate.raze_settings.additional_env %} + rustc_env = { + {%- for key, value in crate.raze_settings.additional_env %} + "{{key}}": "{{value}}", + {%- endfor %} + }, + {%- endif %} + data = {% include "templates/partials/default_data_dependencies.template" -%} + {%- if crate.raze_settings.data_attr -%} + {{crate.raze_settings.data_attr}} + {%- endif %} + {%- if crate.targeted_deps %} + {%- include "templates/partials/targeted_data_dependencies.template" %}, + {%- else %}, + {%- endif %} + version = "{{ crate.pkg_version }}", + tags = [ + "cargo-raze", + "manual", + ], + crate_features = [ + {%- for feature in crate.features %} + "{{feature}}", + {%- endfor %} + ], + aliases = {%- include "templates/partials/targeted_aliases.template" %}, \ No newline at end of file diff --git a/cargo/crate_universe_resolver/src/templates/partials/default_data_dependencies.template b/cargo/crate_universe_resolver/src/templates/partials/default_data_dependencies.template new file mode 100644 index 0000000000..5f75b893fe --- /dev/null +++ b/cargo/crate_universe_resolver/src/templates/partials/default_data_dependencies.template @@ -0,0 +1,12 @@ +glob(["**"], exclude=[ + # These can be manually added with overrides if needed. + + # If you run `cargo build` in this dir, the target dir can get very big very quick. + "target/**", + + # These are not vendored from the crate - we exclude them to avoid busting caches + # when we change how we generate BUILD files and such. + "BUILD.bazel", + "WORKSPACE.bazel", + "WORKSPACE", + ]) \ No newline at end of file diff --git a/cargo/crate_universe_resolver/src/templates/partials/rust_binary.template b/cargo/crate_universe_resolver/src/templates/partials/rust_binary.template new file mode 100644 index 0000000000..2a0a4009c3 --- /dev/null +++ b/cargo/crate_universe_resolver/src/templates/partials/rust_binary.template @@ -0,0 +1,27 @@ + +# buildifier: leave-alone +rust_binary( + # Prefix bin name to disambiguate from (probable) collision with lib name + # N.B.: The exact form of this is subject to change. + name = "cargo_bin_{{ target_name_sanitized }}", + deps = [ + {%- if crate.lib_target_name %} + # Binaries get an implicit dependency on their crate's lib + ":{{crate.lib_target_name | replace(from="-", to="_") }}", + {%- endif %} + {%- if crate.build_script_target %} + ":{{ crate_name_sanitized }}_build_script", + {%- endif %} + {%- for dependency in crate.default_deps.dependencies %} + "{{dependency.buildable_target}}", + {%- endfor %} + {%- for dependency in crate.raze_settings.additional_deps %} + "{{dependency}}", + {%- endfor %} + ] + {%- if crate.targeted_deps %} + {%- include "templates/partials/targeted_dependencies.template" -%}, + {%- else -%}, + {%- endif %} +{% include "templates/partials/common_attrs.template" %} +) \ No newline at end of file diff --git a/cargo/crate_universe_resolver/src/templates/partials/rust_library.template b/cargo/crate_universe_resolver/src/templates/partials/rust_library.template new file mode 100644 index 0000000000..0e06764222 --- /dev/null +++ b/cargo/crate_universe_resolver/src/templates/partials/rust_library.template @@ -0,0 +1,33 @@ + +{% if target_name_sanitized != crate_name_sanitized -%} +alias( + name = "{{ crate_name_sanitized }}", + actual = ":{{ target_name_sanitized }}", + tags = [ + "cargo-raze", + "manual", + ], +) + +{% endif -%} +# buildifier: leave-alone +rust_library( + name = "{{ target_name_sanitized }}", + crate_type = "{{ target.kind }}", + deps = [ + {%- if crate.build_script_target %} + ":{{ crate_name_sanitized }}_build_script", + {%- endif %} + {%- for dependency in crate.default_deps.dependencies %} + "{{dependency.buildable_target}}", + {%- endfor %} + {%- for dependency in crate.raze_settings.additional_deps %} + "{{dependency}}", + {%- endfor %} + ] + {%- if crate.targeted_deps %} + {%- include "templates/partials/targeted_dependencies.template" -%}, + {%- else -%}, + {%- endif %} +{% include "templates/partials/common_attrs.template" %} +) \ No newline at end of file diff --git a/cargo/crate_universe_resolver/src/templates/partials/targeted_aliases.template b/cargo/crate_universe_resolver/src/templates/partials/targeted_aliases.template new file mode 100644 index 0000000000..99b4487f33 --- /dev/null +++ b/cargo/crate_universe_resolver/src/templates/partials/targeted_aliases.template @@ -0,0 +1,10 @@ + select({ +{%- for condition, targeted_dep in targeted_metadata %} + # {{ targeted_dep.target }} + "{{ condition }}": { + {%- for alias in targeted_dep.deps.aliased_dependencies %} + "{{alias.target}}": "{{alias.alias}}", + {%- endfor %} + }, +{%- endfor %} + }) \ No newline at end of file diff --git a/cargo/crate_universe_resolver/src/templates/partials/targeted_build_script_data_dependencies.template b/cargo/crate_universe_resolver/src/templates/partials/targeted_build_script_data_dependencies.template new file mode 100644 index 0000000000..a73b7d004c --- /dev/null +++ b/cargo/crate_universe_resolver/src/templates/partials/targeted_build_script_data_dependencies.template @@ -0,0 +1,17 @@ +{%- for targeted_dep in crate.targeted_deps %} +{%- if targeted_dep.deps.build_data_dependencies | length == 0 %} +{%- continue %} +{%- endif %} + selects.with_or({ + # {{ targeted_dep.target }} + ( +{%- for condition in targeted_dep.conditions %} + "{{ condition }}", +{%- endfor %} + ): [ +{%- for dependency in targeted_dep.deps.build_data_dependencies %} + "{{ dependency.buildable_target }}", +{%- endfor %} + ], + "//conditions:default": [], + }) +{%- endfor -%} \ No newline at end of file diff --git a/cargo/crate_universe_resolver/src/templates/partials/targeted_build_script_dependencies.template b/cargo/crate_universe_resolver/src/templates/partials/targeted_build_script_dependencies.template new file mode 100644 index 0000000000..c248d5ce22 --- /dev/null +++ b/cargo/crate_universe_resolver/src/templates/partials/targeted_build_script_dependencies.template @@ -0,0 +1,17 @@ +{%- for targeted_dep in crate.targeted_deps %} +{%- if targeted_dep.deps.build_dependencies | length == 0 %} +{%- continue %} +{%- endif %} + selects.with_or({ + # {{ targeted_dep.target }} + ( +{%- for condition in targeted_dep.conditions %} + "{{ condition }}", +{%- endfor %} + ): [ +{%- for dependency in targeted_dep.deps.build_dependencies %} + "{{ dependency.buildable_target }}", +{%- endfor %} + ], + "//conditions:default": [], + }) +{%- endfor -%} \ No newline at end of file diff --git a/cargo/crate_universe_resolver/src/templates/partials/targeted_data_dependencies.template b/cargo/crate_universe_resolver/src/templates/partials/targeted_data_dependencies.template new file mode 100644 index 0000000000..8b06d00fc7 --- /dev/null +++ b/cargo/crate_universe_resolver/src/templates/partials/targeted_data_dependencies.template @@ -0,0 +1,17 @@ +{%- for targeted_dep in crate.targeted_deps %} +{%- if targeted_dep.deps.data_dependencies | length == 0 %} +{%- continue %} +{%- endif %} + selects.with_or({ + # {{ targeted_dep.target }} + ( +{%- for condition in targeted_dep.conditions %} + "{{ condition }}", +{%- endfor %} + ): [ +{%- for dependency in targeted_dep.deps.data_dependencies %} + "{{ dependency.buildable_target }}", +{%- endfor %} + ], + "//conditions:default": [], + }) +{%- endfor -%} \ No newline at end of file diff --git a/cargo/crate_universe_resolver/src/templates/partials/targeted_dependencies.template b/cargo/crate_universe_resolver/src/templates/partials/targeted_dependencies.template new file mode 100644 index 0000000000..aae7226eff --- /dev/null +++ b/cargo/crate_universe_resolver/src/templates/partials/targeted_dependencies.template @@ -0,0 +1,17 @@ +{%- for targeted_dep in crate.targeted_deps %} +{%- if targeted_dep.deps.dependencies | length == 0 %} +{%- continue %} +{%- endif %} + selects.with_or({ + # {{ targeted_dep.target }} + ( +{%- for condition in targeted_dep.conditions %} + "{{ condition }}", +{%- endfor %} + ): [ +{%- for dependency in targeted_dep.deps.dependencies %} + "{{ dependency.buildable_target }}", +{%- endfor %} + ], + "//conditions:default": [], + }) +{%- endfor -%} \ No newline at end of file diff --git a/cargo/crate_universe_resolver/tests/integration.rs b/cargo/crate_universe_resolver/tests/integration.rs new file mode 100644 index 0000000000..a80636285b --- /dev/null +++ b/cargo/crate_universe_resolver/tests/integration.rs @@ -0,0 +1,2048 @@ +use std::collections::{BTreeMap, BTreeSet, HashMap}; +use std::fs::create_dir_all; +use std::path::PathBuf; + +use assert_cmd::assert::Assert; +use assert_cmd::Command; +use maplit::btreemap; +use predicates::boolean::PredicateBooleanExt; +use predicates::ord::eq; +use semver::VersionReq; + +use crate_universe_resolver::config::{Config, Override, Package}; +use crate_universe_resolver::NamedTempFile; + +#[test] +fn basic() { + let cargo_toml_file = NamedTempFile::with_str_content( + "Cargo.toml", + r#"[package] +name = "basic" +version = "0.1.0" +edition = "2018" + +[dependencies] +lazy_static = "=1.4.0" +"#, + ) + .expect("Error making temporary file"); + + let config = Config { + repository_name: "beep".to_owned(), + cargo_toml_files: btreemap! { String::from("//some:Cargo.toml") => cargo_toml_file.path().to_path_buf() }, + overrides: Default::default(), + repository_template: "https://crates-io.s3-us-west-1.amazonaws.com/crates/crates/{crate}/{crate}-{version}.crate".to_owned(), + target_triples: vec!["x86_64-apple-darwin".to_owned()], + packages: vec![], + cargo: PathBuf::from(env!("CARGO")), + rust_rules_workspace_name: crate_universe_resolver::config::default_rules_rust_workspace_name(), + index_url: crate_universe_resolver::config::default_index_url(), + }; + + let want_output = r##" +load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository") + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def pinned_rust_install(): + http_archive( + name = "beep__lazy_static__1_4_0", + # TODO: Allow configuring where rust_library comes from + build_file_content = """# buildifier: disable=load +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", + "rust_library", + "rust_test", +) + +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + +package(default_visibility = [ + "//visibility:public", +]) + +licenses([ + "notice", # MIT from expression "MIT OR Apache-2.0" +]) + +# Generated targets + +# buildifier: leave-alone +rust_library( + name = "lazy_static", + crate_type = "lib", + deps = [ + ], + srcs = glob(["**/*.rs"]), + crate_root = "src/lib.rs", + edition = "2015", + rustc_flags = [ + "--cap-lints=allow", + ], + data = glob(["**"], exclude=[ + # These can be manually added with overrides if needed. + + # If you run `cargo build` in this dir, the target dir can get very big very quick. + "target/**", + + # These are not vendored from the crate - we exclude them to avoid busting caches + # when we change how we generate BUILD files and such. + "BUILD.bazel", + "WORKSPACE.bazel", + "WORKSPACE", + ]), + version = "1.4.0", + tags = [ + "cargo-raze", + "manual", + ], + crate_features = [ + ], + aliases = select({ + # Default + "//conditions:default": { + }, + }), +) +# Unsupported target "no_std" with type "test" omitted +# Unsupported target "test" with type "test" omitted +""", + sha256 = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646", + strip_prefix = "lazy_static-1.4.0", + type = "tar.gz", + url = "https://crates-io.s3-us-west-1.amazonaws.com/crates/crates/lazy_static/lazy_static-1.4.0.crate", + ) + + +CRATE_TARGET_NAMES = { + "lazy_static": "@beep__lazy_static__1_4_0//:lazy_static", +} + +def crate(crate_name): + """Return the name of the target for the given crate. + """ + target_name = CRATE_TARGET_NAMES.get(crate_name) + if target_name == None: + fail("Unknown crate name: {}".format(crate_name)) + return target_name + +def all_deps(): + """Return all standard dependencies explicitly listed in the Cargo.toml or packages list.""" + return [ + crate(crate_name) for crate_name in [ + "lazy_static", + ] + ] + +def all_proc_macro_deps(): + """Return all proc-macro dependencies explicitly listed in the Cargo.toml or packages list.""" + return [ + crate(crate_name) for crate_name in [ + ] + ] + +def crates_from(label): + mapping = { + "//some:Cargo.toml": [crate("lazy_static")], + } + return mapping[_absolutify(label)] + +def dev_crates_from(label): + mapping = { + "//some:Cargo.toml": [], + } + return mapping[_absolutify(label)] + +def build_crates_from(label): + mapping = { + "//some:Cargo.toml": [], + } + return mapping[_absolutify(label)] + +def proc_macro_crates_from(label): + mapping = { + "//some:Cargo.toml": [], + } + return mapping[_absolutify(label)] + +def _absolutify(label): + if label.startswith("//") or label.startswith("@"): + return label + if label.startswith(":"): + return "//" + native.package_name() + label + return "//" + native.package_name() + ":" + label +"##; + + // Ignore header which contains a hash + test(&config) + .success() + .stdout(predicates::str::ends_with(want_output)); +} + +#[test] +fn intermediate() { + let cargo_toml_file = NamedTempFile::with_str_content( + "Cargo.toml", + r#"[package] +name = "intermediate" +version = "0.1.0" +edition = "2018" + +# TODO: support lockfile instead of passing the transitive pinned list as "packages" directly. +[dependencies] +lazy_static = "=1.4.0" +bytes = "=0.5.6" +pin-project-lite = "=0.1.7" +bitflags = "=1.2.1" + +# System dependency (libz-sys) and its transitive deps. +libz-sys = "=1.1.2" +cc = "=1.0.62" +libc = "=0.2.80" +pkg-config = "=0.3.19" +vcpkg = "=0.2.10" + +# TODO: do not depend on this section to be present rules_rust_external. +[[bin]] +name = "basic" +path = "src/main.rs" +"#, + ) + .expect("Error making temporary file"); + + let mut tokio_extra_rust_env_vars = BTreeMap::::new(); + tokio_extra_rust_env_vars.insert("ENV_VAR_1".to_owned(), "value1".to_owned()); + tokio_extra_rust_env_vars.insert("ENV_VAR_2".to_owned(), "value2".to_owned()); + + let mut tokio_extra_bazel_deps = BTreeMap::>::new(); + tokio_extra_bazel_deps.insert( + "x86_64-apple-darwin".to_owned(), + vec!["@some//:dep".to_owned(), "@other//:dep".to_owned()], + ); + tokio_extra_bazel_deps.insert("cfg(unix)".to_owned(), vec!["@yetanother//:dep".to_owned()]); + + let mut bitflags_extra_build_script_env_vars = BTreeMap::::new(); + bitflags_extra_build_script_env_vars + .insert("BUILD_SCRIPT_ENV_VAR".to_owned(), "value".to_owned()); + + let mut bitflags_extra_bazel_builds_script_deps = BTreeMap::>::new(); + bitflags_extra_bazel_builds_script_deps.insert( + "x86_64-unknown-linux-gnu".to_owned(), + vec!["@buildscriptdep//:dep".to_owned()], + ); + + let mut bitflags_extra_bazel_builds_script_data_deps = BTreeMap::>::new(); + bitflags_extra_bazel_builds_script_data_deps.insert( + "x86_64-unknown-linux-gnu".to_owned(), + vec!["@buildscriptdep//:somedata".to_owned()], + ); + + let mut lazy_static_extra_bazel_deps = BTreeMap::>::new(); + lazy_static_extra_bazel_deps.insert("cfg(all())".to_owned(), vec!["@such//:dep".to_owned()]); + + let mut lazy_static_extra_bazel_data_deps = BTreeMap::>::new(); + lazy_static_extra_bazel_data_deps.insert( + "x86_64-unknown-linux-gnu".to_owned(), + vec!["@such//:somedata".to_owned()], + ); + + let mut overrides = HashMap::new(); + overrides.insert( + "tokio".into(), + Override { + extra_rust_env_vars: tokio_extra_rust_env_vars, + extra_build_script_env_vars: Default::default(), + extra_bazel_deps: tokio_extra_bazel_deps, + extra_build_script_bazel_deps: Default::default(), + extra_bazel_data_deps: Default::default(), + extra_build_script_bazel_data_deps: Default::default(), + features_to_remove: BTreeSet::new(), + }, + ); + overrides.insert( + "lazy_static".into(), + Override { + extra_rust_env_vars: Default::default(), + extra_build_script_env_vars: Default::default(), + extra_bazel_deps: lazy_static_extra_bazel_deps, + extra_build_script_bazel_deps: Default::default(), + extra_bazel_data_deps: lazy_static_extra_bazel_data_deps, + extra_build_script_bazel_data_deps: Default::default(), + features_to_remove: BTreeSet::new(), + }, + ); + overrides.insert( + "bitflags".into(), + Override { + extra_rust_env_vars: Default::default(), + extra_build_script_env_vars: bitflags_extra_build_script_env_vars, + extra_bazel_deps: Default::default(), + extra_build_script_bazel_deps: bitflags_extra_bazel_builds_script_deps, + extra_bazel_data_deps: Default::default(), + extra_build_script_bazel_data_deps: bitflags_extra_bazel_builds_script_data_deps, + features_to_remove: BTreeSet::new(), + }, + ); + + let config = Config { + repository_name: "beep".to_owned(), + cargo_toml_files: btreemap! { String::from("//some:Cargo.toml") => cargo_toml_file.path().to_path_buf() }, + overrides, + repository_template: "https://crates-io.s3-us-west-1.amazonaws.com/crates/crates/{crate}/{crate}-{version}.crate".to_owned(), + target_triples: vec![ + "x86_64-apple-darwin".to_owned(), + "x86_64-unknown-linux-gnu".to_owned(), + "x86_64-pc-windows-gnu".to_owned(), + ], + packages: vec![Package { + name: "tokio".to_string(), + semver: VersionReq::parse("=0.2.22").unwrap(), + features: vec![], + }], + cargo: PathBuf::from(env!("CARGO")), + rust_rules_workspace_name:crate_universe_resolver::config::default_rules_rust_workspace_name(), + index_url:crate_universe_resolver::config::default_index_url(), + }; + + let want_output = r##" +load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository") + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def pinned_rust_install(): + http_archive( + name = "beep__bitflags__1_2_1", + # TODO: Allow configuring where rust_library comes from + build_file_content = """# buildifier: disable=load +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", + "rust_library", + "rust_test", +) + +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + +package(default_visibility = [ + "//visibility:public", +]) + +licenses([ + "notice", # MIT from expression "MIT OR Apache-2.0" +]) + +# Generated targets +# buildifier: disable=load-on-top +load( + "@rules_rust//cargo:cargo_build_script.bzl", + "cargo_build_script", +) + +# buildifier: leave-alone +cargo_build_script( + name = "bitflags_build_script", + srcs = glob(["**/*.rs"]), + crate_root = "build.rs", + edition = "2015", + deps = [ + ] + selects.with_or({ + # x86_64-unknown-linux-gnu + ( + "@rules_rust//rust/platform:x86_64-unknown-linux-gnu", + ): [ + "@buildscriptdep//:dep", + ], + "//conditions:default": [], + }), + rustc_flags = [ + "--cap-lints=allow", + ], + crate_features = [ + "default", + ], + build_script_env = { + "BUILD_SCRIPT_ENV_VAR": "value", + }, + data = glob(["**"], exclude=[ + # These can be manually added with overrides if needed. + + # If you run `cargo build` in this dir, the target dir can get very big very quick. + "target/**", + + # These are not vendored from the crate - we exclude them to avoid busting caches + # when we change how we generate BUILD files and such. + "BUILD.bazel", + "WORKSPACE.bazel", + "WORKSPACE", + ]) + selects.with_or({ + # x86_64-unknown-linux-gnu + ( + "@rules_rust//rust/platform:x86_64-unknown-linux-gnu", + ): [ + "@buildscriptdep//:somedata", + ], + "//conditions:default": [], + }), + tags = [ + "cargo-raze", + "manual", + ], + version = "1.2.1", + visibility = ["//visibility:private"], +) + + +# buildifier: leave-alone +rust_library( + name = "bitflags", + crate_type = "lib", + deps = [ + ":bitflags_build_script", + ], + srcs = glob(["**/*.rs"]), + crate_root = "src/lib.rs", + edition = "2015", + rustc_flags = [ + "--cap-lints=allow", + ], + data = glob(["**"], exclude=[ + # These can be manually added with overrides if needed. + + # If you run `cargo build` in this dir, the target dir can get very big very quick. + "target/**", + + # These are not vendored from the crate - we exclude them to avoid busting caches + # when we change how we generate BUILD files and such. + "BUILD.bazel", + "WORKSPACE.bazel", + "WORKSPACE", + ]), + version = "1.2.1", + tags = [ + "cargo-raze", + "manual", + ], + crate_features = [ + "default", + ], + aliases = select({ + # Default + "//conditions:default": { + }, + # x86_64-unknown-linux-gnu + "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": { + }, + }), +) +""", + sha256 = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693", + strip_prefix = "bitflags-1.2.1", + type = "tar.gz", + url = "https://crates-io.s3-us-west-1.amazonaws.com/crates/crates/bitflags/bitflags-1.2.1.crate", + ) + + http_archive( + name = "beep__bytes__0_5_6", + # TODO: Allow configuring where rust_library comes from + build_file_content = """# buildifier: disable=load +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", + "rust_library", + "rust_test", +) + +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + +package(default_visibility = [ + "//visibility:public", +]) + +licenses([ + "notice", # MIT from expression "MIT" +]) + +# Generated targets +# Unsupported target "buf" with type "bench" omitted +# Unsupported target "bytes" with type "bench" omitted +# Unsupported target "bytes_mut" with type "bench" omitted + +# buildifier: leave-alone +rust_library( + name = "bytes", + crate_type = "lib", + deps = [ + ], + srcs = glob(["**/*.rs"]), + crate_root = "src/lib.rs", + edition = "2018", + rustc_flags = [ + "--cap-lints=allow", + ], + data = glob(["**"], exclude=[ + # These can be manually added with overrides if needed. + + # If you run `cargo build` in this dir, the target dir can get very big very quick. + "target/**", + + # These are not vendored from the crate - we exclude them to avoid busting caches + # when we change how we generate BUILD files and such. + "BUILD.bazel", + "WORKSPACE.bazel", + "WORKSPACE", + ]), + version = "0.5.6", + tags = [ + "cargo-raze", + "manual", + ], + crate_features = [ + "default", + "std", + ], + aliases = select({ + # Default + "//conditions:default": { + }, + }), +) +# Unsupported target "test_buf" with type "test" omitted +# Unsupported target "test_buf_mut" with type "test" omitted +# Unsupported target "test_bytes" with type "test" omitted +# Unsupported target "test_bytes_odd_alloc" with type "test" omitted +# Unsupported target "test_bytes_vec_alloc" with type "test" omitted +# Unsupported target "test_chain" with type "test" omitted +# Unsupported target "test_debug" with type "test" omitted +# Unsupported target "test_iter" with type "test" omitted +# Unsupported target "test_reader" with type "test" omitted +# Unsupported target "test_serde" with type "test" omitted +# Unsupported target "test_take" with type "test" omitted +""", + sha256 = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38", + strip_prefix = "bytes-0.5.6", + type = "tar.gz", + url = "https://crates-io.s3-us-west-1.amazonaws.com/crates/crates/bytes/bytes-0.5.6.crate", + ) + + http_archive( + name = "beep__cc__1_0_62", + # TODO: Allow configuring where rust_library comes from + build_file_content = """# buildifier: disable=load +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", + "rust_library", + "rust_test", +) + +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + +package(default_visibility = [ + "//visibility:public", +]) + +licenses([ + "notice", # MIT from expression "MIT OR Apache-2.0" +]) + +# Generated targets + +# buildifier: leave-alone +rust_binary( + # Prefix bin name to disambiguate from (probable) collision with lib name + # N.B.: The exact form of this is subject to change. + name = "cargo_bin_gcc_shim", + deps = [ + # Binaries get an implicit dependency on their crate's lib + ":cc", + ], + srcs = glob(["**/*.rs"]), + crate_root = "src/bin/gcc-shim.rs", + edition = "2018", + rustc_flags = [ + "--cap-lints=allow", + ], + data = glob(["**"], exclude=[ + # These can be manually added with overrides if needed. + + # If you run `cargo build` in this dir, the target dir can get very big very quick. + "target/**", + + # These are not vendored from the crate - we exclude them to avoid busting caches + # when we change how we generate BUILD files and such. + "BUILD.bazel", + "WORKSPACE.bazel", + "WORKSPACE", + ]), + version = "1.0.62", + tags = [ + "cargo-raze", + "manual", + ], + crate_features = [ + ], + aliases = select({ + # Default + "//conditions:default": { + }, + }), +) + +# buildifier: leave-alone +rust_library( + name = "cc", + crate_type = "lib", + deps = [ + ], + srcs = glob(["**/*.rs"]), + crate_root = "src/lib.rs", + edition = "2018", + rustc_flags = [ + "--cap-lints=allow", + ], + data = glob(["**"], exclude=[ + # These can be manually added with overrides if needed. + + # If you run `cargo build` in this dir, the target dir can get very big very quick. + "target/**", + + # These are not vendored from the crate - we exclude them to avoid busting caches + # when we change how we generate BUILD files and such. + "BUILD.bazel", + "WORKSPACE.bazel", + "WORKSPACE", + ]), + version = "1.0.62", + tags = [ + "cargo-raze", + "manual", + ], + crate_features = [ + ], + aliases = select({ + # Default + "//conditions:default": { + }, + }), +) +# Unsupported target "cc_env" with type "test" omitted +# Unsupported target "cflags" with type "test" omitted +# Unsupported target "cxxflags" with type "test" omitted +# Unsupported target "test" with type "test" omitted +""", + sha256 = "f1770ced377336a88a67c473594ccc14eca6f4559217c34f64aac8f83d641b40", + strip_prefix = "cc-1.0.62", + type = "tar.gz", + url = "https://crates-io.s3-us-west-1.amazonaws.com/crates/crates/cc/cc-1.0.62.crate", + ) + + http_archive( + name = "beep__lazy_static__1_4_0", + # TODO: Allow configuring where rust_library comes from + build_file_content = """# buildifier: disable=load +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", + "rust_library", + "rust_test", +) + +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + +package(default_visibility = [ + "//visibility:public", +]) + +licenses([ + "notice", # MIT from expression "MIT OR Apache-2.0" +]) + +# Generated targets + +# buildifier: leave-alone +rust_library( + name = "lazy_static", + crate_type = "lib", + deps = [ + ] + selects.with_or({ + # cfg(all()) + ( + "@rules_rust//rust/platform:x86_64-apple-darwin", + "@rules_rust//rust/platform:x86_64-unknown-linux-gnu", + ): [ + "@such//:dep", + ], + "//conditions:default": [], + }), + srcs = glob(["**/*.rs"]), + crate_root = "src/lib.rs", + edition = "2015", + rustc_flags = [ + "--cap-lints=allow", + ], + data = glob(["**"], exclude=[ + # These can be manually added with overrides if needed. + + # If you run `cargo build` in this dir, the target dir can get very big very quick. + "target/**", + + # These are not vendored from the crate - we exclude them to avoid busting caches + # when we change how we generate BUILD files and such. + "BUILD.bazel", + "WORKSPACE.bazel", + "WORKSPACE", + ]) + selects.with_or({ + # x86_64-unknown-linux-gnu + ( + "@rules_rust//rust/platform:x86_64-unknown-linux-gnu", + ): [ + "@such//:somedata", + ], + "//conditions:default": [], + }), + version = "1.4.0", + tags = [ + "cargo-raze", + "manual", + ], + crate_features = [ + ], + aliases = select({ + # Default + "//conditions:default": { + }, + # cfg(all()) + "@rules_rust//rust/platform:x86_64-apple-darwin": { + }, + # cfg(all()) x86_64-unknown-linux-gnu + "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": { + }, + }), +) +# Unsupported target "no_std" with type "test" omitted +# Unsupported target "test" with type "test" omitted +""", + sha256 = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646", + strip_prefix = "lazy_static-1.4.0", + type = "tar.gz", + url = "https://crates-io.s3-us-west-1.amazonaws.com/crates/crates/lazy_static/lazy_static-1.4.0.crate", + ) + + http_archive( + name = "beep__libc__0_2_80", + # TODO: Allow configuring where rust_library comes from + build_file_content = """# buildifier: disable=load +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", + "rust_library", + "rust_test", +) + +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + +package(default_visibility = [ + "//visibility:public", +]) + +licenses([ + "notice", # MIT from expression "MIT OR Apache-2.0" +]) + +# Generated targets +# buildifier: disable=load-on-top +load( + "@rules_rust//cargo:cargo_build_script.bzl", + "cargo_build_script", +) + +# buildifier: leave-alone +cargo_build_script( + name = "libc_build_script", + srcs = glob(["**/*.rs"]), + crate_root = "build.rs", + edition = "2015", + deps = [ + ], + rustc_flags = [ + "--cap-lints=allow", + ], + crate_features = [ + "default", + "std", + ], + build_script_env = { + }, + data = glob(["**"], exclude=[ + # These can be manually added with overrides if needed. + + # If you run `cargo build` in this dir, the target dir can get very big very quick. + "target/**", + + # These are not vendored from the crate - we exclude them to avoid busting caches + # when we change how we generate BUILD files and such. + "BUILD.bazel", + "WORKSPACE.bazel", + "WORKSPACE", + ]), + tags = [ + "cargo-raze", + "manual", + ], + version = "0.2.80", + visibility = ["//visibility:private"], +) + + +# buildifier: leave-alone +rust_library( + name = "libc", + crate_type = "lib", + deps = [ + ":libc_build_script", + ], + srcs = glob(["**/*.rs"]), + crate_root = "src/lib.rs", + edition = "2015", + rustc_flags = [ + "--cap-lints=allow", + ], + data = glob(["**"], exclude=[ + # These can be manually added with overrides if needed. + + # If you run `cargo build` in this dir, the target dir can get very big very quick. + "target/**", + + # These are not vendored from the crate - we exclude them to avoid busting caches + # when we change how we generate BUILD files and such. + "BUILD.bazel", + "WORKSPACE.bazel", + "WORKSPACE", + ]), + version = "0.2.80", + tags = [ + "cargo-raze", + "manual", + ], + crate_features = [ + "default", + "std", + ], + aliases = select({ + # Default + "//conditions:default": { + }, + }), +) +# Unsupported target "const_fn" with type "test" omitted +""", + sha256 = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614", + strip_prefix = "libc-0.2.80", + type = "tar.gz", + url = "https://crates-io.s3-us-west-1.amazonaws.com/crates/crates/libc/libc-0.2.80.crate", + ) + + http_archive( + name = "beep__libz_sys__1_1_2", + # TODO: Allow configuring where rust_library comes from + build_file_content = """# buildifier: disable=load +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", + "rust_library", + "rust_test", +) + +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + +package(default_visibility = [ + "//visibility:public", +]) + +licenses([ + "notice", # MIT from expression "MIT OR Apache-2.0" +]) + +# Generated targets +# buildifier: disable=load-on-top +load( + "@rules_rust//cargo:cargo_build_script.bzl", + "cargo_build_script", +) + +# buildifier: leave-alone +cargo_build_script( + name = "libz_sys_build_script", + srcs = glob(["**/*.rs"]), + crate_root = "build.rs", + edition = "2015", + deps = [ + "@beep__cc__1_0_62//:cc", + "@beep__pkg_config__0_3_19//:pkg_config", + ], + rustc_flags = [ + "--cap-lints=allow", + ], + crate_features = [ + "default", + "libc", + "stock-zlib", + ], + build_script_env = { + }, + links = "z", + data = glob(["**"], exclude=[ + # These can be manually added with overrides if needed. + + # If you run `cargo build` in this dir, the target dir can get very big very quick. + "target/**", + + # These are not vendored from the crate - we exclude them to avoid busting caches + # when we change how we generate BUILD files and such. + "BUILD.bazel", + "WORKSPACE.bazel", + "WORKSPACE", + ]), + tags = [ + "cargo-raze", + "manual", + ], + version = "1.1.2", + visibility = ["//visibility:private"], +) + + +# buildifier: leave-alone +rust_library( + name = "libz_sys", + crate_type = "lib", + deps = [ + ":libz_sys_build_script", + "@beep__libc__0_2_80//:libc", + ], + srcs = glob(["**/*.rs"]), + crate_root = "src/lib.rs", + edition = "2015", + rustc_flags = [ + "--cap-lints=allow", + ], + data = glob(["**"], exclude=[ + # These can be manually added with overrides if needed. + + # If you run `cargo build` in this dir, the target dir can get very big very quick. + "target/**", + + # These are not vendored from the crate - we exclude them to avoid busting caches + # when we change how we generate BUILD files and such. + "BUILD.bazel", + "WORKSPACE.bazel", + "WORKSPACE", + ]), + version = "1.1.2", + tags = [ + "cargo-raze", + "manual", + ], + crate_features = [ + "default", + "libc", + "stock-zlib", + ], + aliases = select({ + # Default + "//conditions:default": { + }, + }), +) +""", + sha256 = "602113192b08db8f38796c4e85c39e960c145965140e918018bcde1952429655", + strip_prefix = "libz-sys-1.1.2", + type = "tar.gz", + url = "https://crates-io.s3-us-west-1.amazonaws.com/crates/crates/libz-sys/libz-sys-1.1.2.crate", + ) + + http_archive( + name = "beep__pin_project_lite__0_1_7", + # TODO: Allow configuring where rust_library comes from + build_file_content = """# buildifier: disable=load +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", + "rust_library", + "rust_test", +) + +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + +package(default_visibility = [ + "//visibility:public", +]) + +licenses([ + "notice", # Apache-2.0 from expression "Apache-2.0 OR MIT" +]) + +# Generated targets + +# buildifier: leave-alone +rust_library( + name = "pin_project_lite", + crate_type = "lib", + deps = [ + ], + srcs = glob(["**/*.rs"]), + crate_root = "src/lib.rs", + edition = "2018", + rustc_flags = [ + "--cap-lints=allow", + ], + data = glob(["**"], exclude=[ + # These can be manually added with overrides if needed. + + # If you run `cargo build` in this dir, the target dir can get very big very quick. + "target/**", + + # These are not vendored from the crate - we exclude them to avoid busting caches + # when we change how we generate BUILD files and such. + "BUILD.bazel", + "WORKSPACE.bazel", + "WORKSPACE", + ]), + version = "0.1.7", + tags = [ + "cargo-raze", + "manual", + ], + crate_features = [ + ], + aliases = select({ + # Default + "//conditions:default": { + }, + }), +) +# Unsupported target "compiletest" with type "test" omitted +# Unsupported target "lint" with type "test" omitted +# Unsupported target "test" with type "test" omitted +""", + sha256 = "282adbf10f2698a7a77f8e983a74b2d18176c19a7fd32a45446139ae7b02b715", + strip_prefix = "pin-project-lite-0.1.7", + type = "tar.gz", + url = "https://crates-io.s3-us-west-1.amazonaws.com/crates/crates/pin-project-lite/pin-project-lite-0.1.7.crate", + ) + + http_archive( + name = "beep__pkg_config__0_3_19", + # TODO: Allow configuring where rust_library comes from + build_file_content = """# buildifier: disable=load +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", + "rust_library", + "rust_test", +) + +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + +package(default_visibility = [ + "//visibility:public", +]) + +licenses([ + "notice", # MIT from expression "MIT OR Apache-2.0" +]) + +# Generated targets + +# buildifier: leave-alone +rust_library( + name = "pkg_config", + crate_type = "lib", + deps = [ + ], + srcs = glob(["**/*.rs"]), + crate_root = "src/lib.rs", + edition = "2015", + rustc_flags = [ + "--cap-lints=allow", + ], + data = glob(["**"], exclude=[ + # These can be manually added with overrides if needed. + + # If you run `cargo build` in this dir, the target dir can get very big very quick. + "target/**", + + # These are not vendored from the crate - we exclude them to avoid busting caches + # when we change how we generate BUILD files and such. + "BUILD.bazel", + "WORKSPACE.bazel", + "WORKSPACE", + ]), + version = "0.3.19", + tags = [ + "cargo-raze", + "manual", + ], + crate_features = [ + ], + aliases = select({ + # Default + "//conditions:default": { + }, + }), +) +# Unsupported target "test" with type "test" omitted +""", + sha256 = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c", + strip_prefix = "pkg-config-0.3.19", + type = "tar.gz", + url = "https://crates-io.s3-us-west-1.amazonaws.com/crates/crates/pkg-config/pkg-config-0.3.19.crate", + ) + + http_archive( + name = "beep__tokio__0_2_22", + # TODO: Allow configuring where rust_library comes from + build_file_content = """# buildifier: disable=load +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", + "rust_library", + "rust_test", +) + +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + +package(default_visibility = [ + "//visibility:public", +]) + +licenses([ + "notice", # MIT from expression "MIT" +]) + +# Generated targets + +# buildifier: leave-alone +rust_library( + name = "tokio", + crate_type = "lib", + deps = [ + "@beep__bytes__0_5_6//:bytes", + "@beep__pin_project_lite__0_1_7//:pin_project_lite", + ] + selects.with_or({ + # cfg(unix) + ( + "@rules_rust//rust/platform:x86_64-apple-darwin", + "@rules_rust//rust/platform:x86_64-unknown-linux-gnu", + ): [ + "@yetanother//:dep", + ], + "//conditions:default": [], + }) + selects.with_or({ + # x86_64-apple-darwin + ( + "@rules_rust//rust/platform:x86_64-apple-darwin", + ): [ + "@some//:dep", + "@other//:dep", + ], + "//conditions:default": [], + }), + srcs = glob(["**/*.rs"]), + crate_root = "src/lib.rs", + edition = "2018", + rustc_flags = [ + "--cap-lints=allow", + ], + rustc_env = { + "ENV_VAR_1": "value1", + "ENV_VAR_2": "value2", + }, + data = glob(["**"], exclude=[ + # These can be manually added with overrides if needed. + + # If you run `cargo build` in this dir, the target dir can get very big very quick. + "target/**", + + # These are not vendored from the crate - we exclude them to avoid busting caches + # when we change how we generate BUILD files and such. + "BUILD.bazel", + "WORKSPACE.bazel", + "WORKSPACE", + ]), + version = "0.2.22", + tags = [ + "cargo-raze", + "manual", + ], + crate_features = [ + "default", + ], + aliases = select({ + # Default + "//conditions:default": { + }, + # cfg(unix) cfg(unix) x86_64-apple-darwin + "@rules_rust//rust/platform:x86_64-apple-darwin": { + }, + # cfg(unix) cfg(unix) + "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": { + }, + }), +) +# Unsupported target "_require_full" with type "test" omitted +# Unsupported target "async_send_sync" with type "test" omitted +# Unsupported target "buffered" with type "test" omitted +# Unsupported target "fs" with type "test" omitted +# Unsupported target "fs_copy" with type "test" omitted +# Unsupported target "fs_dir" with type "test" omitted +# Unsupported target "fs_file" with type "test" omitted +# Unsupported target "fs_file_mocked" with type "test" omitted +# Unsupported target "fs_link" with type "test" omitted +# Unsupported target "io_async_read" with type "test" omitted +# Unsupported target "io_chain" with type "test" omitted +# Unsupported target "io_copy" with type "test" omitted +# Unsupported target "io_driver" with type "test" omitted +# Unsupported target "io_driver_drop" with type "test" omitted +# Unsupported target "io_lines" with type "test" omitted +# Unsupported target "io_read" with type "test" omitted +# Unsupported target "io_read_exact" with type "test" omitted +# Unsupported target "io_read_line" with type "test" omitted +# Unsupported target "io_read_to_end" with type "test" omitted +# Unsupported target "io_read_to_string" with type "test" omitted +# Unsupported target "io_read_until" with type "test" omitted +# Unsupported target "io_split" with type "test" omitted +# Unsupported target "io_take" with type "test" omitted +# Unsupported target "io_write" with type "test" omitted +# Unsupported target "io_write_all" with type "test" omitted +# Unsupported target "io_write_int" with type "test" omitted +# Unsupported target "macros_join" with type "test" omitted +# Unsupported target "macros_pin" with type "test" omitted +# Unsupported target "macros_select" with type "test" omitted +# Unsupported target "macros_test" with type "test" omitted +# Unsupported target "macros_try_join" with type "test" omitted +# Unsupported target "net_bind_resource" with type "test" omitted +# Unsupported target "net_lookup_host" with type "test" omitted +# Unsupported target "no_rt" with type "test" omitted +# Unsupported target "process_issue_2174" with type "test" omitted +# Unsupported target "process_issue_42" with type "test" omitted +# Unsupported target "process_kill_on_drop" with type "test" omitted +# Unsupported target "process_smoke" with type "test" omitted +# Unsupported target "read_to_string" with type "test" omitted +# Unsupported target "rt_basic" with type "test" omitted +# Unsupported target "rt_common" with type "test" omitted +# Unsupported target "rt_threaded" with type "test" omitted +# Unsupported target "signal_ctrl_c" with type "test" omitted +# Unsupported target "signal_drop_recv" with type "test" omitted +# Unsupported target "signal_drop_rt" with type "test" omitted +# Unsupported target "signal_drop_signal" with type "test" omitted +# Unsupported target "signal_multi_rt" with type "test" omitted +# Unsupported target "signal_no_rt" with type "test" omitted +# Unsupported target "signal_notify_both" with type "test" omitted +# Unsupported target "signal_twice" with type "test" omitted +# Unsupported target "signal_usr1" with type "test" omitted +# Unsupported target "stream_chain" with type "test" omitted +# Unsupported target "stream_collect" with type "test" omitted +# Unsupported target "stream_empty" with type "test" omitted +# Unsupported target "stream_fuse" with type "test" omitted +# Unsupported target "stream_iter" with type "test" omitted +# Unsupported target "stream_merge" with type "test" omitted +# Unsupported target "stream_once" with type "test" omitted +# Unsupported target "stream_pending" with type "test" omitted +# Unsupported target "stream_reader" with type "test" omitted +# Unsupported target "stream_stream_map" with type "test" omitted +# Unsupported target "stream_timeout" with type "test" omitted +# Unsupported target "sync_barrier" with type "test" omitted +# Unsupported target "sync_broadcast" with type "test" omitted +# Unsupported target "sync_cancellation_token" with type "test" omitted +# Unsupported target "sync_errors" with type "test" omitted +# Unsupported target "sync_mpsc" with type "test" omitted +# Unsupported target "sync_mutex" with type "test" omitted +# Unsupported target "sync_mutex_owned" with type "test" omitted +# Unsupported target "sync_notify" with type "test" omitted +# Unsupported target "sync_oneshot" with type "test" omitted +# Unsupported target "sync_rwlock" with type "test" omitted +# Unsupported target "sync_semaphore" with type "test" omitted +# Unsupported target "sync_semaphore_owned" with type "test" omitted +# Unsupported target "sync_watch" with type "test" omitted +# Unsupported target "task_blocking" with type "test" omitted +# Unsupported target "task_local" with type "test" omitted +# Unsupported target "task_local_set" with type "test" omitted +# Unsupported target "tcp_accept" with type "test" omitted +# Unsupported target "tcp_connect" with type "test" omitted +# Unsupported target "tcp_echo" with type "test" omitted +# Unsupported target "tcp_into_split" with type "test" omitted +# Unsupported target "tcp_peek" with type "test" omitted +# Unsupported target "tcp_shutdown" with type "test" omitted +# Unsupported target "tcp_split" with type "test" omitted +# Unsupported target "test_clock" with type "test" omitted +# Unsupported target "time_delay" with type "test" omitted +# Unsupported target "time_delay_queue" with type "test" omitted +# Unsupported target "time_interval" with type "test" omitted +# Unsupported target "time_rt" with type "test" omitted +# Unsupported target "time_throttle" with type "test" omitted +# Unsupported target "time_timeout" with type "test" omitted +# Unsupported target "udp" with type "test" omitted +# Unsupported target "uds_cred" with type "test" omitted +# Unsupported target "uds_datagram" with type "test" omitted +# Unsupported target "uds_split" with type "test" omitted +# Unsupported target "uds_stream" with type "test" omitted +""", + sha256 = "5d34ca54d84bf2b5b4d7d31e901a8464f7b60ac145a284fba25ceb801f2ddccd", + strip_prefix = "tokio-0.2.22", + type = "tar.gz", + url = "https://crates-io.s3-us-west-1.amazonaws.com/crates/crates/tokio/tokio-0.2.22.crate", + ) + + http_archive( + name = "beep__vcpkg__0_2_10", + # TODO: Allow configuring where rust_library comes from + build_file_content = """# buildifier: disable=load +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", + "rust_library", + "rust_test", +) + +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + +package(default_visibility = [ + "//visibility:public", +]) + +licenses([ + "notice", # MIT from expression "MIT OR Apache-2.0" +]) + +# Generated targets + +# buildifier: leave-alone +rust_library( + name = "vcpkg", + crate_type = "lib", + deps = [ + ], + srcs = glob(["**/*.rs"]), + crate_root = "src/lib.rs", + edition = "2015", + rustc_flags = [ + "--cap-lints=allow", + ], + data = glob(["**"], exclude=[ + # These can be manually added with overrides if needed. + + # If you run `cargo build` in this dir, the target dir can get very big very quick. + "target/**", + + # These are not vendored from the crate - we exclude them to avoid busting caches + # when we change how we generate BUILD files and such. + "BUILD.bazel", + "WORKSPACE.bazel", + "WORKSPACE", + ]), + version = "0.2.10", + tags = [ + "cargo-raze", + "manual", + ], + crate_features = [ + ], + aliases = select({ + # Default + "//conditions:default": { + }, + }), +) +""", + sha256 = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c", + strip_prefix = "vcpkg-0.2.10", + type = "tar.gz", + url = "https://crates-io.s3-us-west-1.amazonaws.com/crates/crates/vcpkg/vcpkg-0.2.10.crate", + ) + + +CRATE_TARGET_NAMES = { + "bitflags": "@beep__bitflags__1_2_1//:bitflags", + "bytes": "@beep__bytes__0_5_6//:bytes", + "cc": "@beep__cc__1_0_62//:cc", + "lazy_static": "@beep__lazy_static__1_4_0//:lazy_static", + "libc": "@beep__libc__0_2_80//:libc", + "libz-sys": "@beep__libz_sys__1_1_2//:libz_sys", + "pin-project-lite": "@beep__pin_project_lite__0_1_7//:pin_project_lite", + "pkg-config": "@beep__pkg_config__0_3_19//:pkg_config", + "tokio": "@beep__tokio__0_2_22//:tokio", + "vcpkg": "@beep__vcpkg__0_2_10//:vcpkg", +} + +def crate(crate_name): + """Return the name of the target for the given crate. + """ + target_name = CRATE_TARGET_NAMES.get(crate_name) + if target_name == None: + fail("Unknown crate name: {}".format(crate_name)) + return target_name + +def all_deps(): + """Return all standard dependencies explicitly listed in the Cargo.toml or packages list.""" + return [ + crate(crate_name) for crate_name in [ + "bitflags", + "bytes", + "cc", + "lazy_static", + "libc", + "libz-sys", + "pin-project-lite", + "pkg-config", + "tokio", + "vcpkg", + ] + ] + +def all_proc_macro_deps(): + """Return all proc-macro dependencies explicitly listed in the Cargo.toml or packages list.""" + return [ + crate(crate_name) for crate_name in [ + ] + ] + +def crates_from(label): + mapping = { + "//some:Cargo.toml": [crate("bitflags"), crate("bytes"), crate("cc"), crate("lazy_static"), crate("libc"), crate("libz-sys"), crate("pin-project-lite"), crate("pkg-config"), crate("vcpkg")], + } + return mapping[_absolutify(label)] + +def dev_crates_from(label): + mapping = { + "//some:Cargo.toml": [], + } + return mapping[_absolutify(label)] + +def build_crates_from(label): + mapping = { + "//some:Cargo.toml": [], + } + return mapping[_absolutify(label)] + +def proc_macro_crates_from(label): + mapping = { + "//some:Cargo.toml": [], + } + return mapping[_absolutify(label)] + +def _absolutify(label): + if label.startswith("//") or label.startswith("@"): + return label + if label.startswith(":"): + return "//" + native.package_name() + label + return "//" + native.package_name() + ":" + label +"##; + + // Ignore header which contains a hash + test(&config) + .success() + .stdout(predicates::str::ends_with(want_output)); +} + +#[test] +fn aliased_deps() { + let cargo_toml_file = NamedTempFile::with_str_content( + "Cargo.toml", + r#"[package] +name = "basic" +version = "0.1.0" +edition = "2018" + +[dependencies] +plist = "=1.0.0" +"#, + ) + .expect("Error making temporary file"); + + let config = Config { + repository_name: "hurrah".to_owned(), + cargo_toml_files: btreemap! { String::from("//some:Cargo.toml") => cargo_toml_file.path().to_path_buf() }, + overrides: Default::default(), + repository_template: "https://crates-io.s3-us-west-1.amazonaws.com/crates/crates/{crate}/{crate}-{version}.crate".to_owned(), + target_triples: vec!["x86_64-apple-darwin".to_owned()], + packages: vec![], + cargo: PathBuf::from(env!("CARGO")), + rust_rules_workspace_name:crate_universe_resolver::config::default_rules_rust_workspace_name(), + index_url:crate_universe_resolver::config::default_index_url(), + }; + + let want_output = r#"aliases = select({ + # Default + "//conditions:default": { + "@hurrah__xml_rs__0_8_3//:xml_rs": "xml_rs", + }, + })"#; + + // Ignore header which contains a hash + test(&config) + .success() + .stdout(predicates::str::contains(want_output)); +} + +#[test] +fn git_deps() { + let cargo_toml_file = NamedTempFile::with_str_content( + "Cargo.toml", + r#"[package] +name = "has_git_deps" +version = "0.1.0" +edition = "2018" + +[dependencies] +tonic-build = "=0.3.1" +anyhow = "=1.0.33" +itertools = "=0.9.0" +proc-macro2 = "=1.0.24" +quote = "=1.0.7" +syn = "=1.0.45" + +[patch.crates-io] +prost = { git = "https://github.com/danburkert/prost.git", rev = "4ded4a98ef339da0b7babd4efee3fbe8adaf746b" } +prost-build = { git = "https://github.com/danburkert/prost.git", rev = "4ded4a98ef339da0b7babd4efee3fbe8adaf746b" } +prost-derive = { git = "https://github.com/danburkert/prost.git", rev = "4ded4a98ef339da0b7babd4efee3fbe8adaf746b" } +prost-types = { git = "https://github.com/danburkert/prost.git", rev = "4ded4a98ef339da0b7babd4efee3fbe8adaf746b" } +"#, + ) + .expect("Error making temporary file"); + + let config = Config { + repository_name: "yep".to_owned(), + cargo_toml_files: btreemap! { String::from("//some:Cargo.toml") => cargo_toml_file.path().to_path_buf() }, + overrides: Default::default(), + repository_template: "https://crates-io.s3-us-west-1.amazonaws.com/crates/crates/{crate}/{crate}-{version}.crate".to_owned(), + target_triples: vec!["x86_64-apple-darwin".to_owned()], + packages: vec![], + cargo: PathBuf::from(env!("CARGO")), + rust_rules_workspace_name:crate_universe_resolver::config::default_rules_rust_workspace_name(), + index_url:crate_universe_resolver::config::default_index_url(), + }; + + let wanted_prost = r###" new_git_repository( + name = "yep__prost__0_6_1", + strip_prefix = "", + build_file_content = """# buildifier: disable=load +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", + "rust_library", + "rust_test", +) + +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + +package(default_visibility = [ + "//visibility:public", +]) + +licenses([ + "notice", # Apache-2.0 from expression "Apache-2.0" +]) + +# Generated targets +# Unsupported target "varint" with type "bench" omitted + +# buildifier: leave-alone +rust_library( + name = "prost", + crate_type = "lib", + deps = [ + "@yep__bytes__0_5_6//:bytes", + ], + srcs = glob(["**/*.rs"]), + crate_root = "src/lib.rs", + edition = "2018", + proc_macro_deps = [ + "@yep__prost_derive__0_6_1//:prost_derive", + ], + rustc_flags = [ + "--cap-lints=allow", + ], + data = glob(["**"], exclude=[ + # These can be manually added with overrides if needed. + + # If you run `cargo build` in this dir, the target dir can get very big very quick. + "target/**", + + # These are not vendored from the crate - we exclude them to avoid busting caches + # when we change how we generate BUILD files and such. + "BUILD.bazel", + "WORKSPACE.bazel", + "WORKSPACE", + ]), + version = "0.6.1", + tags = [ + "cargo-raze", + "manual", + ], + crate_features = [ + "prost-derive", + ], + aliases = select({ + # Default + "//conditions:default": { + }, + }), +) +""", + remote = "https://github.com/danburkert/prost.git", + # TODO: tag? + commit = "4ded4a98ef339da0b7babd4efee3fbe8adaf746b", + )"###; + + let unwanted_prost = r###"http_archive( + name = "yep__prost__0_6_1","###; + + let wanted_prost_build = r###" new_git_repository( + name = "yep__prost_build__0_6_1", + strip_prefix = "prost-build", + build_file_content = """# buildifier: disable=load +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", + "rust_library", + "rust_test", +) + +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + +package(default_visibility = [ + "//visibility:public", +]) + +licenses([ + "notice", # Apache-2.0 from expression "Apache-2.0" +]) + +# Generated targets +# buildifier: disable=load-on-top +load( + "@rules_rust//cargo:cargo_build_script.bzl", + "cargo_build_script", +) + +# buildifier: leave-alone +cargo_build_script( + name = "prost_build_build_script", + srcs = glob(["**/*.rs"]), + crate_root = "build.rs", + edition = "2018", + deps = [ + "@yep__which__4_0_2//:which", + ], + rustc_flags = [ + "--cap-lints=allow", + ], + crate_features = [ + ], + build_script_env = { + }, + data = glob(["**"], exclude=[ + # These can be manually added with overrides if needed. + + # If you run `cargo build` in this dir, the target dir can get very big very quick. + "target/**", + + # These are not vendored from the crate - we exclude them to avoid busting caches + # when we change how we generate BUILD files and such. + "BUILD.bazel", + "WORKSPACE.bazel", + "WORKSPACE", + ]), + tags = [ + "cargo-raze", + "manual", + ], + version = "0.6.1", + visibility = ["//visibility:private"], +) + + +# buildifier: leave-alone +rust_library( + name = "prost_build", + crate_type = "lib", + deps = [ + ":prost_build_build_script", + "@yep__bytes__0_5_6//:bytes", + "@yep__heck__0_3_2//:heck", + "@yep__itertools__0_9_0//:itertools", + "@yep__log__0_4_14//:log", + "@yep__multimap__0_8_2//:multimap", + "@yep__petgraph__0_5_1//:petgraph", + "@yep__prost__0_6_1//:prost", + "@yep__prost_types__0_6_1//:prost_types", + "@yep__tempfile__3_2_0//:tempfile", + ], + srcs = glob(["**/*.rs"]), + crate_root = "src/lib.rs", + edition = "2018", + rustc_flags = [ + "--cap-lints=allow", + ], + data = glob(["**"], exclude=[ + # These can be manually added with overrides if needed. + + # If you run `cargo build` in this dir, the target dir can get very big very quick. + "target/**", + + # These are not vendored from the crate - we exclude them to avoid busting caches + # when we change how we generate BUILD files and such. + "BUILD.bazel", + "WORKSPACE.bazel", + "WORKSPACE", + ]), + version = "0.6.1", + tags = [ + "cargo-raze", + "manual", + ], + crate_features = [ + ], + aliases = select({ + # Default + "//conditions:default": { + }, + }), +) +""", + remote = "https://github.com/danburkert/prost.git", + # TODO: tag? + commit = "4ded4a98ef339da0b7babd4efee3fbe8adaf746b", + )"###; + + let unwanted_prost_build = r###"http_archive( + name = "yep__prost_build__0_6_1","###; + + let wanted_prost_derive = r###" new_git_repository( + name = "yep__prost_derive__0_6_1", + strip_prefix = "prost-derive", + build_file_content = """# buildifier: disable=load +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", + "rust_library", + "rust_test", +) + +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + +package(default_visibility = [ + "//visibility:public", +]) + +licenses([ + "notice", # Apache-2.0 from expression "Apache-2.0" +]) + +# Generated targets + +# buildifier: leave-alone +rust_library( + name = "prost_derive", + crate_type = "proc-macro", + deps = [ + "@yep__anyhow__1_0_33//:anyhow", + "@yep__itertools__0_9_0//:itertools", + "@yep__proc_macro2__1_0_24//:proc_macro2", + "@yep__quote__1_0_7//:quote", + "@yep__syn__1_0_45//:syn", + ], + srcs = glob(["**/*.rs"]), + crate_root = "src/lib.rs", + edition = "2018", + rustc_flags = [ + "--cap-lints=allow", + ], + data = glob(["**"], exclude=[ + # These can be manually added with overrides if needed. + + # If you run `cargo build` in this dir, the target dir can get very big very quick. + "target/**", + + # These are not vendored from the crate - we exclude them to avoid busting caches + # when we change how we generate BUILD files and such. + "BUILD.bazel", + "WORKSPACE.bazel", + "WORKSPACE", + ]), + version = "0.6.1", + tags = [ + "cargo-raze", + "manual", + ], + crate_features = [ + ], + aliases = select({ + # Default + "//conditions:default": { + }, + }), +) +""", + remote = "https://github.com/danburkert/prost.git", + # TODO: tag? + commit = "4ded4a98ef339da0b7babd4efee3fbe8adaf746b", + )"###; + + let unwanted_prost_derive = r###"http_archive( + name = "yep__prost_derive__0_6_1","###; + + let wanted_prost_types = r###" new_git_repository( + name = "yep__prost_types__0_6_1", + strip_prefix = "prost-types", + build_file_content = """# buildifier: disable=load +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", + "rust_library", + "rust_test", +) + +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + +package(default_visibility = [ + "//visibility:public", +]) + +licenses([ + "notice", # Apache-2.0 from expression "Apache-2.0" +]) + +# Generated targets + +# buildifier: leave-alone +rust_library( + name = "prost_types", + crate_type = "lib", + deps = [ + "@yep__bytes__0_5_6//:bytes", + "@yep__prost__0_6_1//:prost", + ], + srcs = glob(["**/*.rs"]), + crate_root = "src/lib.rs", + edition = "2018", + rustc_flags = [ + "--cap-lints=allow", + ], + data = glob(["**"], exclude=[ + # These can be manually added with overrides if needed. + + # If you run `cargo build` in this dir, the target dir can get very big very quick. + "target/**", + + # These are not vendored from the crate - we exclude them to avoid busting caches + # when we change how we generate BUILD files and such. + "BUILD.bazel", + "WORKSPACE.bazel", + "WORKSPACE", + ]), + version = "0.6.1", + tags = [ + "cargo-raze", + "manual", + ], + crate_features = [ + ], + aliases = select({ + # Default + "//conditions:default": { + }, + }), +) +""", + remote = "https://github.com/danburkert/prost.git", + # TODO: tag? + commit = "4ded4a98ef339da0b7babd4efee3fbe8adaf746b", + )"###; + + let unwanted_prost_types = r###"http_archive( + name = "yep__prost_types__0_6_1","###; + + let result = test(&config).success(); + result + .stdout(predicates::str::contains(wanted_prost)) + .stdout(predicates::str::contains(wanted_prost_build)) + .stdout(predicates::str::contains(wanted_prost_derive)) + .stdout(predicates::str::contains(wanted_prost_types)) + .stdout(predicates::str::contains(unwanted_prost).not()) + .stdout(predicates::str::contains(unwanted_prost_build).not()) + .stdout(predicates::str::contains(unwanted_prost_derive).not()) + .stdout(predicates::str::contains(unwanted_prost_types).not()); +} + +#[test] +#[ignore] // TODO: Unignore when we fix workspace support - currently broken by the fact that we generate our Cargo.toml somewhere standalone but don't strip out the workspace information +fn workspace_root() { + let dir = tempfile::tempdir().expect("Could not make tempdir"); + let subdir = dir.path().join("subcrate"); + create_dir_all(&subdir).expect("Could not make subcrate dir"); + let workspace_cargo_toml = dir.path().join("Cargo.toml"); + std::fs::write( + &workspace_cargo_toml, + r#"[workspace] +members = ["subcrate"] + +[package] +name = "ws" +version = "0.1.0" +edition = "2018" + +[dependencies] +lazy_static = "=1.4.0" + +# TODO: do not depend on this section to be present rules_rust_external. +[lib] +path = "lib.rs" +"# + .as_bytes(), + ) + .expect("Failed to write Cargo.toml"); + + std::fs::write( + subdir.join("Cargo.toml"), + r#"[package] +name = "subcrate" +version = "0.1.0" +edition = "2018" + +[dependencies] +bitflags = "=1.2.1" + +# TODO: do not depend on this section to be present rules_rust_external. +[lib] +path = "lib.rs" +"# + .as_bytes(), + ) + .expect("Failed to write Cargo.toml"); + + let config = Config { + repository_name: "another".to_owned(), + cargo_toml_files: btreemap! { String::from("//some/other:Cargo.toml") => workspace_cargo_toml }, + overrides: Default::default(), + repository_template: "https://crates-io.s3-us-west-1.amazonaws.com/crates/crates/{crate}/{crate}-{version}.crate".to_owned(), + target_triples: vec!["x86_64-apple-darwin".to_owned()], + packages: vec![], + cargo: PathBuf::from(env!("CARGO")), + rust_rules_workspace_name:crate_universe_resolver::config::default_rules_rust_workspace_name(), + index_url:crate_universe_resolver::config::default_index_url(), + }; + + test(&config).success().stdout(eq(r#"load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def pinned_rust_install(): + http_archive( + name = "bitflags", + # TODO: Allow configuring where rust_library comes from + build_file_content = """load("@rules_rust//rust:rust.bzl", "rust_library") +load("@rules_rust//cargo:cargo_build_script.bzl", "cargo_build_script") + +cargo_build_script( + name = "bitflags_build_script", + srcs = glob(["**/*.rs"]), + crate_root = "build.rs", + deps = [], + proc_macro_deps = [], + data = glob(["**"]), + edition = "2015", + rustc_flags = [ + "--cap-lints=allow", + ], + crate_features = [ + "default" + ], + version = "1.2.1", +) + + +rust_library( + name = "bitflags", + srcs = glob(["**/*.rs"]), + crate_features = [ + "default" + ], + crate_root = "src/lib.rs", + crate_type = "lib", + edition = "2015", + proc_macro_deps = [], + rustc_flags = [ + "--cap-lints=allow", + ], + version = "1.2.1", + visibility = ["//visibility:public"], + deps = [ + ":bitflags_build_script" + ], +) +""", + strip_prefix = "bitflags-1.2.1", + type = "tar.gz", + url = "https://crates-io.s3-us-west-1.amazonaws.com/crates/crates/bitflags/bitflags-1.2.1.crate", +) + http_archive( + name = "lazy_static", + # TODO: Allow configuring where rust_library comes from + build_file_content = """load("@rules_rust//rust:rust.bzl", "rust_library") + +rust_library( + name = "lazy_static", + srcs = glob(["**/*.rs"]), + crate_features = [], + crate_root = "src/lib.rs", + crate_type = "lib", + edition = "2015", + proc_macro_deps = [], + rustc_flags = [ + "--cap-lints=allow", + ], + version = "1.4.0", + visibility = ["//visibility:public"], + deps = [], +) +""", + strip_prefix = "lazy_static-1.4.0", + type = "tar.gz", + url = "https://crates-io.s3-us-west-1.amazonaws.com/crates/crates/lazy_static/lazy_static-1.4.0.crate", +) +"# + )); +} + +fn test(config: &Config) -> Assert { + Command::cargo_bin(env!("CARGO_PKG_NAME")) + .unwrap() + .arg("--input_path") + .arg("/dev/stdin") + .arg("--output_path") + .arg("/dev/stdout") + .arg("--repo-name") + .arg("whatever") + .write_stdin(serde_json::to_string(&config).unwrap()) + .assert() +} + +// Tests still to add: +// Transitive deps +// Lib and bin in the same crate diff --git a/cargo/crate_universe_resolver/tests/parser.rs b/cargo/crate_universe_resolver/tests/parser.rs new file mode 100644 index 0000000000..fe10b3bc70 --- /dev/null +++ b/cargo/crate_universe_resolver/tests/parser.rs @@ -0,0 +1,355 @@ +use indoc::indoc; +use maplit::{btreemap, btreeset}; +use crate_universe_resolver::config::Package; +use crate_universe_resolver::parser::merge_cargo_tomls; +use crate_universe_resolver::NamedTempFile; +use semver::VersionReq; +use spectral::prelude::*; +use std::collections::{BTreeMap, BTreeSet}; + +#[test] +fn parses_one_cargo_toml() { + let cargo_toml = indoc! { r#" + [package] + name = "frobber" + version = "0.1.0" + + [dependencies] + # Normalises string or map values + lazy_static = { version = "1" } + maplit = "1.0.1" + serde = { version = "1", default-features = false, features = ["derive"] } + structopt = { version = "0.3", optional = true } + + [patch.crates-io] + syn = { git = "https://github.com/forked/syn.git" } + + [features] + cmd = ["structopt"] + + [dev-dependencies] + futures = "0.1" + + [build-dependencies] + syn = "1" + "# }; + + let cargo_tomls = btreemap! { "//some:Cargo.toml" => cargo_toml }; + + let want_deps = indoc! {r#" + lazy_static = { version = ">=1.0.0, <2.0.0", default-features = true, features = [] } + maplit = { version = ">=1.0.1, <2.0.0", default-features = true, features = [] } + serde = { version = ">=1.0.0, <2.0.0", default-features = false, features = ["derive"] } + structopt = { version = ">=0.3.0, <0.4.0", default-features = true, features = [] } + "#}; + + let want_labels_to_deps = btreemap! { + "//some:Cargo.toml" => btreeset!{ + "futures", + "lazy_static", + "maplit", + "serde", + "structopt", + "syn", + }, + }; + + let value = test(cargo_tomls, vec![], want_deps, want_labels_to_deps); + + let patch_syn_git = value + .as_table() + .unwrap() + .get("patch") + .unwrap() + .as_table() + .unwrap() + .get("crates-io") + .unwrap() + .as_table() + .unwrap() + .get("syn") + .unwrap() + .as_table() + .unwrap() + .get("git") + .unwrap() + .as_str() + .unwrap(); + assert_eq!("https://github.com/forked/syn.git", patch_syn_git); + + assert_eq!( + value.as_table().unwrap().get("build-dependencies").unwrap(), + &r#"syn = { version = ">=1.0.0, <2.0.0", default-features = true, features = [] }"# + .parse::() + .unwrap(), + ); + + assert_eq!( + value.as_table().unwrap().get("dev-dependencies").unwrap(), + &r#"futures = { version = ">=0.1.0, <0.2.0", default-features = true, features = [] }"# + .parse::() + .unwrap(), + ); +} + +#[test] +fn merges_two_cargo_tomls() { + let cargo_toml1 = indoc! { r#" + [package] + name = "blepper" + version = "1.0.0" + + [dependencies] + lazy_static = { version = "1" } + num_enum = { version = "0.5", features = ["complex-expressions"] } + serde = { version = "1", default-features = false, features = ["derive"] } + "# }; + + let cargo_toml2 = indoc! { r#" + [package] + name = "mlemer" + version = "2.0.0" + + [dependencies] + lazy_static = { version = "1.1" } + maplit = "1.0.1" + serde = { version = "1.0.57", features = ["rc"] } + "# }; + + let cargo_tomls = btreemap! { + "//a:Cargo.toml" => cargo_toml1, + "//b:Cargo.toml" => cargo_toml2, + }; + + let want_deps = indoc! {r#" + lazy_static = { version = ">=1.0.0, <2.0.0, >=1.1.0, <1.2.0", default-features = true, features = [] } + maplit = { version = ">=1.0.1, <2.0.0", default-features = true, features = [] } + num_enum = { version = ">=0.5.0, <0.6.0", default-features = true, features = ["complex-expressions"] } + serde = { version = ">=1.0.0, <2.0.0, >=1.0.57, <2.0.0", default-features = true, features = ["derive", "rc"] } + "#}; + + let want_labels_to_deps = btreemap! { + "//a:Cargo.toml" => btreeset!{ + "lazy_static", + "num_enum", + "serde", + }, + "//b:Cargo.toml" => btreeset!{ + "lazy_static", + "maplit", + "serde", + } + }; + + test(cargo_tomls, vec![], want_deps, want_labels_to_deps); +} + +#[test] +fn fails_to_merge_semver_and_git() { + let cargo_toml1 = indoc! { r#" + [package] + name = "blepper" + version = "1.0.0" + + [dependencies] + lazy_static = { version = "42" } + "# }; + + let cargo_toml2 = indoc! { r#" + [package] + name = "mlemer" + version = "2.0.0" + + [dependencies] + lazy_static = { git = "https://github.com/rust-lang-nursery/lazy-static.rs.git" } + "# }; + + let cargo_tomls = btreemap! { + "//a:Cargo.toml" => cargo_toml1, + "//b:Cargo.toml" => cargo_toml2, + }; + + let err = format!("{:?}", expect_err(cargo_tomls, vec![])); + + assert_that(&err).starts_with("Failed to merge multiple dependencies on lazy_static"); + assert_that(&err).contains("Can't merge semver and git versions of the same dependency"); + assert_that(&err).contains("42"); + assert_that(&err).contains("https://github.com/rust-lang-nursery/lazy-static.rs.git"); +} + +#[test] +fn fails_to_merge_different_git() { + let cargo_toml1 = indoc! { r#" + [package] + name = "blepper" + version = "1.0.0" + + [dependencies] + lazy_static = { git = "https://github.com/some-fork/lazy-static.rs.git" } + "# }; + + let cargo_toml2 = indoc! { r#" + [package] + name = "mlemer" + version = "2.0.0" + + [dependencies] + lazy_static = { git = "https://github.com/rust-lang-nursery/lazy-static.rs.git" } + "# }; + + let cargo_tomls = btreemap! { + "//a:Cargo.toml" => cargo_toml1, + "//b:Cargo.toml" => cargo_toml2, + }; + + let err = format!("{:?}", expect_err(cargo_tomls, vec![])); + + assert_that(&err).starts_with("Failed to merge multiple dependencies on lazy_static"); + assert_that(&err).contains("Can't merge different git versions of the same dependency"); + assert_that(&err).contains("https://github.com/some-fork/lazy-static.rs.git"); + assert_that(&err).contains("https://github.com/rust-lang-nursery/lazy-static.rs.git"); +} + +#[test] +fn can_have_just_packages() { + let packages = vec![Package { + name: String::from("serde"), + semver: VersionReq::parse("^1").unwrap(), + features: vec![String::from("derive")], + }]; + + let want_deps = indoc! {r#" + serde = { version = ">=1.0.0, <2.0.0", default-features = true, features = ["derive"] } + "#}; + + let want_labels_to_deps = BTreeMap::new(); + + test(BTreeMap::new(), packages, want_deps, want_labels_to_deps); +} + +#[test] +fn can_add_packages() { + let cargo_toml = indoc! { r#" + [package] + name = "frobber" + version = "0.1.0" + + [dependencies] + # Normalises string or map values + lazy_static = { version = "1" } + "# }; + + let cargo_tomls = btreemap! { "//some:Cargo.toml" => cargo_toml }; + + let packages = vec![Package { + name: String::from("serde"), + semver: VersionReq::parse("^1.0.57").unwrap(), + features: vec![String::from("derive")], + }]; + + let want_deps = indoc! {r#" + lazy_static = { version = ">=1.0.0, <2.0.0", default-features = true, features = [] } + serde = { version = ">=1.0.57, <2.0.0", default-features = true, features = ["derive"] } + "#}; + + let want_labels_to_deps = btreemap! { + "//some:Cargo.toml" => btreeset!{ + "lazy_static", + }, + }; + + test(cargo_tomls, packages, want_deps, want_labels_to_deps); +} + +#[test] +fn package_conflicts_are_errors() { + let cargo_toml = indoc! { r#" + [package] + name = "frobber" + version = "0.1.0" + + [dependencies] + # Normalises string or map values + lazy_static = { version = "1" } + "# }; + + let cargo_tomls = btreemap! { "//some:Cargo.toml" => cargo_toml }; + + let packages = vec![Package { + name: String::from("lazy_static"), + semver: VersionReq::parse("^1").unwrap(), + features: vec![], + }]; + + let err = expect_err(cargo_tomls, packages); + + assert_eq!( + String::from("The following package was provided both in a Cargo.toml and in the crate_universe repository rule: lazy_static."), + format!("{}", err) + ); +} + +#[test] +fn applies_overrides() {} + +fn test( + input: BTreeMap<&str, &str>, + additional_packages: Vec, + want_deps: &str, + want_labels_to_deps: BTreeMap<&str, BTreeSet<&str>>, +) -> toml::Value { + let labels_to_cargo_tomls = write_cargo_tomls_to_disk(input); + + let (merged_cargo_toml, labels_to_deps) = merge_cargo_tomls( + labels_to_cargo_tomls + .iter() + .map(|(label, file)| (label.clone(), file.path().to_owned())) + .collect(), + additional_packages, + ) + .unwrap(); + + let value = toml::Value::from(merged_cargo_toml); + assert_eq!( + value.as_table().unwrap().get("dependencies").unwrap(), + &want_deps.parse::().unwrap(), + ); + + assert_eq!( + labels_to_deps, + want_labels_to_deps + .into_iter() + .map(|(k, vs)| (k.to_owned(), vs.into_iter().map(|v| v.to_owned()).collect())) + .collect() + ); + + value +} + +fn expect_err( + cargo_tomls: BTreeMap<&str, &str>, + additional_packages: Vec, +) -> anyhow::Error { + let labels_to_cargo_tomls = write_cargo_tomls_to_disk(cargo_tomls); + + merge_cargo_tomls( + labels_to_cargo_tomls + .iter() + .map(|(label, file)| (label.clone(), file.path().to_owned())) + .collect(), + additional_packages, + ) + .expect_err("Want error") +} + +fn write_cargo_tomls_to_disk(input: BTreeMap<&str, &str>) -> BTreeMap { + input + .into_iter() + .map(|(label, cargo_toml)| { + ( + label.to_owned(), + NamedTempFile::with_str_content("Cargo.toml", cargo_toml).unwrap(), + ) + }) + .collect::>() +} diff --git a/cargo/repositories.bzl b/cargo/repositories.bzl new file mode 100644 index 0000000000..db8ee93add --- /dev/null +++ b/cargo/repositories.bzl @@ -0,0 +1,4 @@ +load("@rules_rust//cargo:repositories_bin.bzl", "crate_universe_bin_deps") + +def crate_universe_deps(): + crate_universe_bin_deps() diff --git a/cargo/repositories_bin.bzl b/cargo/repositories_bin.bzl new file mode 100644 index 0000000000..7d9dc659ef --- /dev/null +++ b/cargo/repositories_bin.bzl @@ -0,0 +1,23 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file") +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") + +# These could perhaps be populated with pre-built versions as part of a release pipeline. Details to be discussed :) + +def crate_universe_bin_deps(): + maybe( + http_file, + name = "crate_universe_resolver_linux", + urls = [ + "file:///dev/null", + ], + executable = True, + ) + + maybe( + http_file, + name = "crate_universe_resolver_darwin", + urls = [ + "file:///dev/null", + ], + executable = True, + ) diff --git a/cargo/workspace.bzl b/cargo/workspace.bzl new file mode 100644 index 0000000000..97ccbad57a --- /dev/null +++ b/cargo/workspace.bzl @@ -0,0 +1,251 @@ +DEFAULT_REPOSITORY_TEMPLATE = "https://crates.io/api/v1/crates/{crate}/{version}/download" + +def _crate_universe_resolve_impl(repository_ctx): + """Entry-point repository to manage rust dependencies. + + General flow is: + - Serialize user-provided rule attributes into JSON + - Call the Rust resolver script. It writes a `defs.bzl` file in this repo containing the + transitive dependencies as repo rules in a `pinned_rust_install()` macro. + - The user then calls defs.bzl%pinned_rust_install(). + + Environment Variables: + RULES_RUST_UPDATE_CRATE_UNIVERSE_LOCKFILE: Re-pin the lockfile if `true`. + RULES_RUST_CRATE_UNIVERSE_RESOLVER_URL_OVERRIDE: Override URL to use to download resolver binary - for local paths use a file:// URL. + """ + + if repository_ctx.os.name == "linux": + toolchain_repo = "@rust_linux_x86_64" + elif repository_ctx.os.name == "mac os x": + toolchain_repo = "@rust_darwin_x86_64" + cargo_label = Label(toolchain_repo + "//:bin/cargo") + rustc_label = Label(toolchain_repo + "//:bin/rustc") + + lockfile_path = None + if repository_ctx.attr.lockfile: + lockfile_path = repository_ctx.path(repository_ctx.attr.lockfile) + + # Yay hand-crafted JSON serialisation... + input_content = """{{ + "repository_name": {name}, + "packages": [ + {packages} + ], + "cargo_toml_files": {{ + {cargo_toml_files} + }}, + "overrides": {{ + {overrides} + }}, + "repository_template": "{repository_template}", + "target_triples": [ + {targets} + ], + "cargo": "{cargo}" +}}""".format( + name = "\"{}\"".format(repository_ctx.attr.name), + packages = ",\n".join([artifact for artifact in repository_ctx.attr.packages]), + cargo_toml_files = ",\n".join(['"{}": "{}"'.format(ct, repository_ctx.path(ct)) for ct in repository_ctx.attr.cargo_toml_files]), + overrides = ",\n".join(["\"{}\": {}".format(oname, ovalue) for (oname, ovalue) in repository_ctx.attr.overrides.items()]), + repository_template = repository_ctx.attr.repository_template, + targets = ",\n".join(['"{}"'.format(target) for target in repository_ctx.attr.supported_targets]), + cargo = repository_ctx.path(cargo_label), + ) + + input_path = "_{name}.json".format(name = repository_ctx.attr.name) + + # For debugging or working on changes to the resolver, you can set something like: + # export RULES_RUST_RESOLVER_URL_OVERRIDE=file:///path/to/rules_rust/cargo/crate_universe_resolver/target/release/resolver + resolver_url = repository_ctx.os.environ.get("RULES_RUST_CRATE_UNIVERSE_RESOLVER_URL_OVERRIDE", None) + if resolver_url and resolver_url.startswith("file://"): + sha256_result = repository_ctx.execute(["sha256sum", resolver_url[7:]]) + resolver_sha = sha256_result.stdout[:64] + + resolver_path = repository_ctx.path("resolver") + repository_ctx.download( + url = resolver_url, + sha256 = resolver_sha, + output = resolver_path, + executable = True, + ) + else: + # TODO: Avoid downloading both the linux and darwin one each time. + if repository_ctx.os.name == "linux": + resolver_path = repository_ctx.path(repository_ctx.attr._resolver_script_linux) + elif repository_ctx.os.name == "mac os x": + resolver_path = repository_ctx.path(repository_ctx.attr._resolver_script_darwin) + + repository_ctx.file(input_path, content = input_content) + + args = [ + resolver_path, + "--input_path", + input_path, + "--output_path", + repository_ctx.path("defs.bzl"), + "--repo-name", + repository_ctx.attr.name, + ] + if lockfile_path != None: + args.append("--lockfile") + str(args.append(lockfile_path)) + if repository_ctx.os.environ.get("RULES_RUST_UPDATE_CRATE_UNIVERSE_LOCKFILE", "false") == "true": + args.append("--update-lockfile") + + path_binaries = [ + repository_ctx.path(rustc_label), + ] + + result = repository_ctx.execute( + args, + environment = { + "RUST_LOG": "info", + + # The resolver invokes `cargo metadata` which relies on `rustc` being on the $PATH + "PATH": ":".join([str(b.dirname) for b in path_binaries]), + }, + ) + repository_ctx.delete(input_path) + if result.stderr: + print("Output from resolver: " + result.stderr) + if result.return_code != 0: + fail("Error resolving deps:\n" + result.stdout + "\n" + result.stderr) + + repository_ctx.file("BUILD.bazel") + +_crate_universe_resolve = repository_rule( + implementation = _crate_universe_resolve_impl, + attrs = { + "packages": attr.string_list(allow_empty = True), + "cargo_toml_files": attr.label_list(), + "overrides": attr.string_dict(doc = """Mapping of crate name to crate.override(...) entries) + +Example: + + load("@rules_rust//cargo:workspace.bzl", "rust_library", "crate") + + rust_library( + name = "mylib", + # [...] + overrides = { + "tokio": crate.override( + extra_rust_env_vars = { + "MY_ENV_VAR": "MY_ENV_VALUE", + }, + extra_build_script_env_vars = { + "MY_BUILD_SCRIPT_ENV_VAR": "MY_ENV_VALUE", + }, + extra_bazel_deps = { + # Extra dependencies are per target. They are additive. + "cfg(unix)": ["@somerepo//:foo"], # cfg() predicate. + "x86_64-apple-darwin": ["@somerepo//:bar"], # Specific triple. + "cfg(all())": ["@somerepo//:baz"], # Applies to all targets ("regular dependency"). + }, + extra_build_script_bazel_deps = { + # Extra dependencies are per target. They are additive. + "cfg(unix)": ["@buildscriptdep//:foo"], + "x86_64-apple-darwin": ["@buildscriptdep//:bar"], + "cfg(all())": ["@buildscriptdep//:baz"], + }, + extra_bazel_data_deps = { + # ... + }, + extra_build_script_bazel_data_deps = { + # ... + }, + ), + }, + ) + +"""), + "repository_template": attr.string(), + "supported_targets": attr.string_list(allow_empty = False), + "lockfile": attr.label( + allow_single_file = True, + mandatory = False, + ), + "_resolver_script_linux": attr.label( + default = "@crate_universe_resolver_linux//file:downloaded", + executable = True, + cfg = "host", + ), + "_resolver_script_darwin": attr.label( + default = "@crate_universe_resolver_darwin//file:downloaded", + executable = True, + cfg = "host", + ), + }, + local = True, +) + +def crate_universe( + name, + packages = [], + cargo_toml_files = [], + overrides = {}, + repository_template = None, + supported_targets = [], + lockfile = None): + _crate_universe_resolve( + name = name, + packages = [package.to_json() for package in packages], + cargo_toml_files = [_absolutify(label) for label in cargo_toml_files], + overrides = dict([(k, v.to_json()) for (k, v) in overrides.items()]), + repository_template = repository_template if repository_template else DEFAULT_REPOSITORY_TEMPLATE, + supported_targets = supported_targets, + lockfile = lockfile, + ) + +def _absolutify(label): + if label.startswith("//") or label.startswith("@"): + return label + if label.startswith(":"): + return "//" + native.package_name() + label + return "//" + native.package_name() + ":" + label + +def _spec( + name, + semver, + features = None): + return struct( + name = name, + semver = semver, + features = features if features else [], + ) + +def _override( + extra_rust_env_vars = None, + extra_build_script_env_vars = None, + extra_bazel_deps = None, + extra_build_script_bazel_deps = None, + extra_bazel_data_deps = None, + extra_build_script_bazel_data_deps = None, + features_to_remove = []): + for (dep_key, dep_val) in [ + (extra_bazel_deps, extra_bazel_deps), + (extra_build_script_bazel_deps, extra_build_script_bazel_deps), + (extra_bazel_data_deps, extra_bazel_data_deps), + (extra_build_script_bazel_data_deps, extra_build_script_bazel_data_deps), + ]: + if dep_val != None: + if not type(dep_val) == "dict": + fail("The {} attribute should be a dictionary".format(dep_key)) + + for target, deps in dep_val.items(): + if not type(deps) == "list" or any([type(x) != "string" for x in deps]): + fail("The {} values should be lists of strings".format(dep_key)) + + return struct( + extra_rust_env_vars = extra_rust_env_vars if extra_rust_env_vars else {}, + extra_build_script_env_vars = extra_build_script_env_vars if extra_build_script_env_vars else {}, + extra_bazel_deps = extra_bazel_deps if extra_bazel_deps else {}, + extra_build_script_bazel_deps = extra_build_script_bazel_deps if extra_build_script_bazel_deps else {}, + extra_bazel_data_deps = extra_bazel_data_deps if extra_bazel_data_deps else {}, + extra_build_script_bazel_data_deps = extra_build_script_bazel_data_deps if extra_build_script_bazel_data_deps else {}, + features_to_remove = features_to_remove, + ) + +crate = struct( + spec = _spec, + override = _override, +) diff --git a/examples/crate_universe/basic/BUILD.bazel b/examples/crate_universe/basic/BUILD.bazel new file mode 100644 index 0000000000..09ec6c8223 --- /dev/null +++ b/examples/crate_universe/basic/BUILD.bazel @@ -0,0 +1,21 @@ +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", +) +load("@crate_universe_basic_rust_deps//:defs.bzl", "crate") + +rust_binary( + name = "basic", + srcs = ["src/main.rs"], + edition = "2018", + deps = [ + crate("lazy_static"), + ], +) + +sh_test( + name = "test", + srcs = ["test.sh"], + data = [":basic"], + args = ["$(location :basic)"], +) diff --git a/examples/crate_universe/basic/src/main.rs b/examples/crate_universe/basic/src/main.rs new file mode 100644 index 0000000000..4a5afd44b5 --- /dev/null +++ b/examples/crate_universe/basic/src/main.rs @@ -0,0 +1,17 @@ +use lazy_static::lazy_static; +use std::collections::HashMap; + +lazy_static! { + static ref HASHMAP: HashMap<&'static str, &'static str> = { + let mut m = HashMap::new(); + m.insert("Gibson", "Fahnestock"); + m.insert("Romain", "Chossart"); + m.insert("Daniel", "Wagner-Hall"); + m + }; +} + +fn main() { + assert_eq!(HASHMAP["Daniel"], "Wagner-Hall"); + println!("It worked!"); +} diff --git a/examples/crate_universe/basic/test.sh b/examples/crate_universe/basic/test.sh new file mode 100755 index 0000000000..b2e2b6de4b --- /dev/null +++ b/examples/crate_universe/basic/test.sh @@ -0,0 +1,4 @@ +#!/bin/bash -eu + +out="$("$1")" +[[ "${out}" == "It worked!" ]] || { echo "Unexpected output: ${out}"; exit 1; } diff --git a/examples/crate_universe/has_aliased_deps/BUILD.bazel b/examples/crate_universe/has_aliased_deps/BUILD.bazel new file mode 100644 index 0000000000..65817354fe --- /dev/null +++ b/examples/crate_universe/has_aliased_deps/BUILD.bazel @@ -0,0 +1,21 @@ +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", +) +load("@crate_universe_has_aliased_deps_rust_deps//:defs.bzl", "crate") + +rust_binary( + name = "has_aliased_deps", + srcs = ["src/bin.rs"], + crate_type = "bin", + edition = "2018", + deps = [ + crate("reqwest"), + ], +) + +sh_test( + name = "test", + srcs = ["test.sh"], + data = [":has_aliased_deps"], +) diff --git a/examples/crate_universe/has_aliased_deps/Cargo.lock b/examples/crate_universe/has_aliased_deps/Cargo.lock new file mode 100644 index 0000000000..4f1e18c507 --- /dev/null +++ b/examples/crate_universe/has_aliased_deps/Cargo.lock @@ -0,0 +1,1068 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "base64" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" + +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" + +[[package]] +name = "bumpalo" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" + +[[package]] +name = "bytes" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" + +[[package]] +name = "cc" +version = "1.0.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef611cc68ff783f18535d77ddd080185275713d852c4f5cbb6122c462a7a825c" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "core-foundation" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" + +[[package]] +name = "dtoa" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b" + +[[package]] +name = "encoding_rs" +version = "0.8.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a51b8cf747471cb9499b6d59e59b0444f4c90eba8968c4e44874e92b5b64ace2" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "fuchsia-zircon" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" +dependencies = [ + "bitflags", + "fuchsia-zircon-sys", +] + +[[package]] +name = "fuchsia-zircon-sys" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" + +[[package]] +name = "futures-channel" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f366ad74c28cca6ba456d95e6422883cfb4b252a83bed929c83abfdbbf2967d5" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59f5fff90fd5d971f936ad674802482ba441b6f09ba5e15fd8b39145582ca399" + +[[package]] +name = "futures-io" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de27142b013a8e869c14957e6d2edeef89e97c289e69d042ee3a49acd8b51789" + +[[package]] +name = "futures-sink" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f2032893cb734c7a05d85ce0cc8b8c4075278e93b24b66f9de99d6eb0fa8acc" + +[[package]] +name = "futures-task" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdb66b5f09e22019b1ab0830f7785bcea8e7a42148683f99214f73f8ec21a626" +dependencies = [ + "once_cell", +] + +[[package]] +name = "futures-util" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8764574ff08b701a084482c3c7031349104b07ac897393010494beaa18ce32c6" +dependencies = [ + "futures-core", + "futures-io", + "futures-task", + "memchr", + "pin-project", + "pin-utils", + "slab", +] + +[[package]] +name = "getrandom" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", +] + +[[package]] +name = "h2" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "993f9e0baeed60001cf565546b0d3dbe6a6ad23f2bd31644a133c641eccf6d53" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "has_aliased_deps" +version = "0.1.0" +dependencies = [ + "reqwest", +] + +[[package]] +name = "hashbrown" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00d63df3d41950fb462ed38308eea019113ad1508da725bbedcd0fa5a85ef5f7" + +[[package]] +name = "hermit-abi" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9" +dependencies = [ + "libc", +] + +[[package]] +name = "http" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d569972648b2c512421b5f2a405ad6ac9666547189d0c5477a3f200f3e02f9" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "httparse" +version = "1.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" + +[[package]] +name = "hyper" +version = "0.13.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e68a8dd9716185d9e64ea473ea6ef63529252e3e27623295a0378a19665d5eb" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project", + "socket2", + "time", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-tls" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d979acc56dcb5b8dddba3917601745e877576475aa046df3226eabdecef78eed" +dependencies = [ + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-tls", +] + +[[package]] +name = "idna" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55e2e4c765aa53a0424761bf9f41aa7a6ac1efa87238f59560640e27fca028f2" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "iovec" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" +dependencies = [ + "libc", +] + +[[package]] +name = "ipnet" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47be2f14c678be2fdcab04ab1171db51b2762ce6f0a8ee87c8dd4a04ed216135" + +[[package]] +name = "itoa" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" + +[[package]] +name = "js-sys" +version = "0.3.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca059e81d9486668f12d455a4ea6daa600bd408134cd17e3d3fb5a32d1f016f8" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "kernel32-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +dependencies = [ + "winapi 0.2.8", + "winapi-build", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f96b10ec2560088a8e76961b00d47107b3a625fecb76dedb29ee7ccbf98235" + +[[package]] +name = "log" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "matches" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" + +[[package]] +name = "memchr" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" + +[[package]] +name = "mime" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" + +[[package]] +name = "mime_guess" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "mio" +version = "0.6.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fce347092656428bc8eaf6201042cb551b8d67855af7374542a92a0fbfcac430" +dependencies = [ + "cfg-if", + "fuchsia-zircon", + "fuchsia-zircon-sys", + "iovec", + "kernel32-sys", + "libc", + "log", + "miow", + "net2", + "slab", + "winapi 0.2.8", +] + +[[package]] +name = "miow" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" +dependencies = [ + "kernel32-sys", + "net2", + "winapi 0.2.8", + "ws2_32-sys", +] + +[[package]] +name = "native-tls" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b0d88c06fe90d5ee94048ba40409ef1d9315d86f6f38c2efdaad4fb50c58b2d" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "net2" +version = "0.2.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ebc3ec692ed7c9a255596c67808dee269f64655d8baf7b4f0638e51ba1d6853" +dependencies = [ + "cfg-if", + "libc", + "winapi 0.3.9", +] + +[[package]] +name = "num_cpus" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "260e51e7efe62b592207e9e13a68e43692a7a279171d6ba57abd208bf23645ad" + +[[package]] +name = "openssl" +version = "0.10.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d575eff3665419f9b83678ff2815858ad9d11567e082f5ac1814baba4e2bcb4" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "lazy_static", + "libc", + "openssl-sys", +] + +[[package]] +name = "openssl-probe" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" + +[[package]] +name = "openssl-sys" +version = "0.9.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a842db4709b604f0fe5d1170ae3565899be2ad3d9cbc72dedc789ac0511f78de" +dependencies = [ + "autocfg", + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" + +[[package]] +name = "pin-project" +version = "0.4.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca4433fff2ae79342e497d9f8ee990d174071408f28f726d6d83af93e58e48aa" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "0.4.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c0e815c3ee9a031fdf5af21c10aa17c573c9c6a566328d99e3936c34e36461f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282adbf10f2698a7a77f8e983a74b2d18176c19a7fd32a45446139ae7b02b715" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33" + +[[package]] +name = "ppv-lite86" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20" + +[[package]] +name = "proc-macro2" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36e28516df94f3dd551a587da5357459d9b36d945a7c37c3557928c1c2ff2a2c" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom", + "libc", + "rand_chacha", + "rand_core", + "rand_hc", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core", +] + +[[package]] +name = "redox_syscall" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" + +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi 0.3.9", +] + +[[package]] +name = "reqwest" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9eaa17ac5d7b838b7503d118fa16ad88f440498bf9ffe5424e621f93190d61e" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "http", + "http-body", + "hyper", + "hyper-tls", + "ipnet", + "js-sys", + "lazy_static", + "log", + "mime", + "mime_guess", + "native-tls", + "percent-encoding", + "pin-project-lite", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-tls", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + +[[package]] +name = "ryu" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" + +[[package]] +name = "schannel" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" +dependencies = [ + "lazy_static", + "winapi 0.3.9", +] + +[[package]] +name = "security-framework" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64808902d7d99f78eaddd2b4e2509713babc3dc3c85ad6f4c447680f3c01e535" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17bf11d99252f512695eb468de5516e5cf75455521e69dfe343f3b74e4748405" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "serde" +version = "1.0.116" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96fe57af81d28386a513cbc6858332abc6117cfdb5999647c6444b8f43a370a5" + +[[package]] +name = "serde_json" +version = "1.0.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "164eacbdb13512ec2745fb09d51fd5b22b0d65ed294a1dcf7285a360c80a675c" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ec5d77e2d4c73717816afac02670d5c4f534ea95ed430442cad02e7a6e32c97" +dependencies = [ + "dtoa", + "itoa", + "serde", + "url", +] + +[[package]] +name = "slab" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" + +[[package]] +name = "socket2" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1fa70dc5c8104ec096f4fe7ede7a221d35ae13dcd19ba1ad9a81d2cab9a1c44" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "winapi 0.3.9", +] + +[[package]] +name = "syn" +version = "1.0.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6690e3e9f692504b941dc6c3b188fd28df054f7fb8469ab40680df52fdcc842b" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "tempfile" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" +dependencies = [ + "cfg-if", + "libc", + "rand", + "redox_syscall", + "remove_dir_all", + "winapi 0.3.9", +] + +[[package]] +name = "time" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +dependencies = [ + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", + "winapi 0.3.9", +] + +[[package]] +name = "tinyvec" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "238ce071d267c5710f9d31451efec16c5ee22de34df17cc05e56cbc92e967117" + +[[package]] +name = "tokio" +version = "0.2.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d34ca54d84bf2b5b4d7d31e901a8464f7b60ac145a284fba25ceb801f2ddccd" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "iovec", + "lazy_static", + "memchr", + "mio", + "num_cpus", + "pin-project-lite", + "slab", +] + +[[package]] +name = "tokio-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a70f4fcd7b3b24fb194f837560168208f669ca8cb70d0c4b862944452396343" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "log", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" + +[[package]] +name = "tracing" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d79ca061b032d6ce30c660fded31189ca0b9922bf483cd70759f13a2d86786c" +dependencies = [ + "cfg-if", + "log", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bcf46c1f1f06aeea2d6b81f3c863d0930a596c86ad1920d4e5bad6dd1d7119a" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "try-lock" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" + +[[package]] +name = "unicase" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +dependencies = [ + "version_check", +] + +[[package]] +name = "unicode-bidi" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" +dependencies = [ + "matches", +] + +[[package]] +name = "unicode-normalization" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fb19cf769fa8c6a80a162df694621ebeb4dafb606470b2b2fce0be40a98a977" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-xid" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" + +[[package]] +name = "url" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb" +dependencies = [ + "idna", + "matches", + "percent-encoding", +] + +[[package]] +name = "vcpkg" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c" + +[[package]] +name = "version_check" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" + +[[package]] +name = "want" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +dependencies = [ + "log", + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + +[[package]] +name = "wasm-bindgen" +version = "0.2.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ac64ead5ea5f05873d7c12b545865ca2b8d28adfc50a49b84770a3a97265d42" +dependencies = [ + "cfg-if", + "serde", + "serde_json", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f22b422e2a757c35a73774860af8e112bff612ce6cb604224e8e47641a9e4f68" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7866cab0aa01de1edf8b5d7936938a7e397ee50ce24119aef3e1eaa3b6171da" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b13312a745c08c469f0b292dd2fcd6411dba5f7160f593da6ef69b64e407038" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f249f06ef7ee334cc3b8ff031bfc11ec99d00f34d86da7498396dc1e3b1498fe" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d649a3145108d7d3fbcde896a468d1bd636791823c9921135218ad89be08307" + +[[package]] +name = "web-sys" +version = "0.3.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bf6ef87ad7ae8008e15a355ce696bed26012b7caa21605188cfd8214ab51e2d" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "winapi" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-build" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "winreg" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" +dependencies = [ + "winapi 0.3.9", +] + +[[package]] +name = "ws2_32-sys" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" +dependencies = [ + "winapi 0.2.8", + "winapi-build", +] diff --git a/examples/crate_universe/has_aliased_deps/Cargo.toml b/examples/crate_universe/has_aliased_deps/Cargo.toml new file mode 100644 index 0000000000..d867d884c5 --- /dev/null +++ b/examples/crate_universe/has_aliased_deps/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "has_aliased_deps" +version = "0.1.0" +authors = ["Daniel Wagner-Hall "] +edition = "2018" + +[dependencies] +reqwest = { version = "0.10.7", features = ["blocking", "json"] } diff --git a/examples/crate_universe/has_aliased_deps/openssl.BUILD b/examples/crate_universe/has_aliased_deps/openssl.BUILD new file mode 100644 index 0000000000..de4b3e29ff --- /dev/null +++ b/examples/crate_universe/has_aliased_deps/openssl.BUILD @@ -0,0 +1,51 @@ +load("@rules_foreign_cc//tools/build_defs:configure.bzl", "configure_make") + +config_setting( + name = "darwin", + values = {"cpu": "darwin"}, + visibility = ["//visibility:public"], +) + +config_setting( + name = "linux", + values = {"cpu": "k8"}, + visibility = ["//visibility:public"], +) + +filegroup( + name = "srcs", + srcs = glob( + ["**"], + exclude = ["BUILD.bazel"], + ), +) + +configure_make( + name = "openssl", + configure_command = "config", + configure_env_vars = select({ + # On Darwin, the cc_toolchain uses libtool instead of ar, but these do not take compatible arguments. + # By default it will set AR to point at libtool. + # So set AR to an empty value so that Darwin falls back to the system-default ar instead. + ":darwin": { + "AR": "", + }, + ":linux": {}, + }), + lib_source = ":srcs", + shared_libraries = select({ + ":darwin": [ + "libcrypto.dylib", + "libssl.dylib", + ], + ":linux": [ + "libcrypto.so", + "libssl.so", + ], + }), + static_libraries = [ + "libcrypto.a", + "libssl.a", + ], + visibility = ["//visibility:public"], +) diff --git a/examples/crate_universe/has_aliased_deps/src/bin.rs b/examples/crate_universe/has_aliased_deps/src/bin.rs new file mode 100644 index 0000000000..f328e4d9d0 --- /dev/null +++ b/examples/crate_universe/has_aliased_deps/src/bin.rs @@ -0,0 +1 @@ +fn main() {} diff --git a/examples/crate_universe/has_aliased_deps/test.sh b/examples/crate_universe/has_aliased_deps/test.sh new file mode 100755 index 0000000000..593ab27984 --- /dev/null +++ b/examples/crate_universe/has_aliased_deps/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash -eux + +true diff --git a/examples/crate_universe/uses_proc_macro/BUILD.bazel b/examples/crate_universe/uses_proc_macro/BUILD.bazel new file mode 100644 index 0000000000..ffd022877d --- /dev/null +++ b/examples/crate_universe/uses_proc_macro/BUILD.bazel @@ -0,0 +1,22 @@ +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", +) + +load("@crate_universe_uses_proc_macro_rust_deps//:defs.bzl", "crate") + +rust_binary( + name = "uses_proc_macro", + srcs = ["src/main.rs"], + edition = "2018", + deps = [ + crate("structopt"), + ], +) + +sh_test( + name = "test", + srcs = ["test.sh"], + args = ["$(location :uses_proc_macro)"], + data = [":uses_proc_macro"], +) diff --git a/examples/crate_universe/uses_proc_macro/Cargo.lock b/examples/crate_universe/uses_proc_macro/Cargo.lock new file mode 100644 index 0000000000..2234641acc --- /dev/null +++ b/examples/crate_universe/uses_proc_macro/Cargo.lock @@ -0,0 +1,223 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "ansi_term" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +dependencies = [ + "winapi", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" + +[[package]] +name = "clap" +version = "2.33.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" +dependencies = [ + "ansi_term", + "atty", + "bitflags", + "strsim", + "textwrap", + "unicode-width", + "vec_map", +] + +[[package]] +name = "heck" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "hermit-abi" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9" +dependencies = [ + "libc", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f96b10ec2560088a8e76961b00d47107b3a625fecb76dedb29ee7ccbf98235" + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36e28516df94f3dd551a587da5357459d9b36d945a7c37c3557928c1c2ff2a2c" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + +[[package]] +name = "structopt" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6cc388d94ffabf39b5ed5fadddc40147cb21e605f53db6f8f36a625d27489ac5" +dependencies = [ + "clap", + "lazy_static", + "structopt-derive", +] + +[[package]] +name = "structopt-derive" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e2513111825077552a6751dfad9e11ce0fba07d7276a3943a037d7e93e64c5f" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "syn" +version = "1.0.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6690e3e9f692504b941dc6c3b188fd28df054f7fb8469ab40680df52fdcc842b" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "unicode-segmentation" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0" + +[[package]] +name = "unicode-width" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" + +[[package]] +name = "unicode-xid" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" + +[[package]] +name = "uses_proc_macro" +version = "0.1.0" +dependencies = [ + "structopt", +] + +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + +[[package]] +name = "version_check" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/examples/crate_universe/uses_proc_macro/Cargo.toml b/examples/crate_universe/uses_proc_macro/Cargo.toml new file mode 100644 index 0000000000..4ef2d186ea --- /dev/null +++ b/examples/crate_universe/uses_proc_macro/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "uses_proc_macro" +version = "0.1.0" +authors = ["Daniel Wagner-Hall "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +structopt = "=0.3.17" diff --git a/examples/crate_universe/uses_proc_macro/src/main.rs b/examples/crate_universe/uses_proc_macro/src/main.rs new file mode 100644 index 0000000000..90ab63cd60 --- /dev/null +++ b/examples/crate_universe/uses_proc_macro/src/main.rs @@ -0,0 +1,12 @@ +use structopt::StructOpt; + +#[derive(StructOpt)] +struct Opt { + #[structopt(long)] + name: String +} + +fn main() { + let opt = Opt::from_args(); + println!("Greetings, {}", opt.name); +} diff --git a/examples/crate_universe/uses_proc_macro/test.sh b/examples/crate_universe/uses_proc_macro/test.sh new file mode 100755 index 0000000000..a25c039dca --- /dev/null +++ b/examples/crate_universe/uses_proc_macro/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash -eux + +[[ "$("${1}" --name Gibson)" == "Greetings, Gibson" ]] || exit 1 diff --git a/examples/crate_universe/uses_sys_crate/BUILD.bazel b/examples/crate_universe/uses_sys_crate/BUILD.bazel new file mode 100644 index 0000000000..5c7a0c11e2 --- /dev/null +++ b/examples/crate_universe/uses_sys_crate/BUILD.bazel @@ -0,0 +1,22 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", +) +load("@crate_universe_uses_sys_crate_rust_deps//:defs.bzl", "crate") + +rust_binary( + name = "uses_sys_crate", + srcs = ["src/main.rs"], + edition = "2018", + deps = [crate("bzip2")], +) + +sh_test( + name = "test", + size = "small", + srcs = ["test.sh"], + args = ["$(location :uses_sys_crate)"], + data = [":uses_sys_crate"], +) diff --git a/examples/crate_universe/uses_sys_crate/Cargo.lock b/examples/crate_universe/uses_sys_crate/Cargo.lock new file mode 100644 index 0000000000..2885782129 --- /dev/null +++ b/examples/crate_universe/uses_sys_crate/Cargo.lock @@ -0,0 +1,47 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "bzip2" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42b7c3cbf0fa9c1b82308d57191728ca0256cb821220f4e2fd410a72ade26e3b" +dependencies = [ + "bzip2-sys", + "libc", +] + +[[package]] +name = "bzip2-sys" +version = "0.1.9+1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad3b39a260062fca31f7b0b12f207e8f2590a67d32ec7d59c20484b07ea7285e" +dependencies = [ + "cc", + "libc", + "pkg-config", +] + +[[package]] +name = "cc" +version = "1.0.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66120af515773fb005778dc07c261bd201ec8ce50bd6e7144c927753fe013381" + +[[package]] +name = "libc" +version = "0.2.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f96b10ec2560088a8e76961b00d47107b3a625fecb76dedb29ee7ccbf98235" + +[[package]] +name = "pkg-config" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33" + +[[package]] +name = "uses_sys_crate" +version = "0.1.0" +dependencies = [ + "bzip2", +] diff --git a/examples/crate_universe/uses_sys_crate/Cargo.toml b/examples/crate_universe/uses_sys_crate/Cargo.toml new file mode 100644 index 0000000000..a9068d34ff --- /dev/null +++ b/examples/crate_universe/uses_sys_crate/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "uses_sys_crate" +version = "0.1.0" +authors = ["Daniel Wagner-Hall "] +edition = "2018" + +[dependencies] +bzip2 = "0.3.3" diff --git a/examples/crate_universe/uses_sys_crate/lockfile.lock b/examples/crate_universe/uses_sys_crate/lockfile.lock new file mode 100644 index 0000000000..f6d25611c6 --- /dev/null +++ b/examples/crate_universe/uses_sys_crate/lockfile.lock @@ -0,0 +1,550 @@ +# rules_rust crate_universe file format 1 +# config hash d555ad6fce4572c24cb874f784ca32c0b4c5c6b6655c759f6b1381c0ef72667a + +load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository") + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def pinned_rust_install(): + http_archive( + name = "crate_universe_uses_sys_crate_rust_deps__bzip2__0_3_3", + # TODO: Allow configuring where rust_library comes from + build_file_content = """# buildifier: disable=load +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", + "rust_library", + "rust_test", +) + +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + +package(default_visibility = [ + "//visibility:public", +]) + +licenses([ + "notice", # MIT from expression "MIT OR Apache-2.0" +]) + +# Generated targets + +# buildifier: leave-alone +rust_library( + name = "bzip2", + crate_type = "lib", + deps = [ + "@crate_universe_uses_sys_crate_rust_deps__bzip2_sys__0_1_10_1_0_8//:bzip2_sys", + "@crate_universe_uses_sys_crate_rust_deps__libc__0_2_76//:libc", + ], + srcs = glob(["**/*.rs"]), + crate_root = "src/lib.rs", + edition = "2015", + rustc_flags = [ + "--cap-lints=allow", + ], + data = glob(["**"], exclude=[ + # These can be manually added with overrides if needed. + + # If you run `cargo build` in this dir, the target dir can get very big very quick. + "target/**", + + # These are not vendored from the crate - we exclude them to avoid busting caches + # when we change how we generate BUILD files and such. + "BUILD.bazel", + "WORKSPACE.bazel", + "WORKSPACE", + ]), + version = "0.3.3", + tags = [ + "cargo-raze", + "manual", + ], + crate_features = [ + ], + aliases = select({ + # Default + "//conditions:default": { + }, + }), +) +# Unsupported target "tokio" with type "test" omitted +""", + sha256 = "42b7c3cbf0fa9c1b82308d57191728ca0256cb821220f4e2fd410a72ade26e3b", + strip_prefix = "bzip2-0.3.3", + type = "tar.gz", + url = "https://crates.io/api/v1/crates/bzip2/0.3.3/download", + ) + + http_archive( + name = "crate_universe_uses_sys_crate_rust_deps__bzip2_sys__0_1_10_1_0_8", + # TODO: Allow configuring where rust_library comes from + build_file_content = """# buildifier: disable=load +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", + "rust_library", + "rust_test", +) + +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + +package(default_visibility = [ + "//visibility:public", +]) + +licenses([ + "notice", # MIT from expression "MIT OR Apache-2.0" +]) + +# Generated targets +# buildifier: disable=load-on-top +load( + "@rules_rust//cargo:cargo_build_script.bzl", + "cargo_build_script", +) + +# buildifier: leave-alone +cargo_build_script( + name = "bzip2_sys_build_script", + srcs = glob(["**/*.rs"]), + crate_root = "build.rs", + edition = "2015", + deps = [ + "@crate_universe_uses_sys_crate_rust_deps__cc__1_0_66//:cc", + "@crate_universe_uses_sys_crate_rust_deps__pkg_config__0_3_19//:pkg_config", + ], + rustc_flags = [ + "--cap-lints=allow", + ], + crate_features = [ + ], + build_script_env = { + }, + links = "bzip2", + data = glob(["**"], exclude=[ + # These can be manually added with overrides if needed. + + # If you run `cargo build` in this dir, the target dir can get very big very quick. + "target/**", + + # These are not vendored from the crate - we exclude them to avoid busting caches + # when we change how we generate BUILD files and such. + "BUILD.bazel", + "WORKSPACE.bazel", + "WORKSPACE", + ]), + tags = [ + "cargo-raze", + "manual", + ], + version = "0.1.10+1.0.8", + visibility = ["//visibility:private"], +) + + +# buildifier: leave-alone +rust_library( + name = "bzip2_sys", + crate_type = "lib", + deps = [ + ":bzip2_sys_build_script", + "@crate_universe_uses_sys_crate_rust_deps__libc__0_2_76//:libc", + ], + srcs = glob(["**/*.rs"]), + crate_root = "lib.rs", + edition = "2015", + rustc_flags = [ + "--cap-lints=allow", + ], + data = glob(["**"], exclude=[ + # These can be manually added with overrides if needed. + + # If you run `cargo build` in this dir, the target dir can get very big very quick. + "target/**", + + # These are not vendored from the crate - we exclude them to avoid busting caches + # when we change how we generate BUILD files and such. + "BUILD.bazel", + "WORKSPACE.bazel", + "WORKSPACE", + ]), + version = "0.1.10+1.0.8", + tags = [ + "cargo-raze", + "manual", + ], + crate_features = [ + ], + aliases = select({ + # Default + "//conditions:default": { + }, + }), +) +""", + sha256 = "17fa3d1ac1ca21c5c4e36a97f3c3eb25084576f6fc47bf0139c1123434216c6c", + strip_prefix = "bzip2-sys-0.1.10+1.0.8", + type = "tar.gz", + url = "https://crates.io/api/v1/crates/bzip2-sys/0.1.10+1.0.8/download", + ) + + http_archive( + name = "crate_universe_uses_sys_crate_rust_deps__cc__1_0_66", + # TODO: Allow configuring where rust_library comes from + build_file_content = """# buildifier: disable=load +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", + "rust_library", + "rust_test", +) + +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + +package(default_visibility = [ + "//visibility:public", +]) + +licenses([ + "notice", # MIT from expression "MIT OR Apache-2.0" +]) + +# Generated targets + +# buildifier: leave-alone +rust_binary( + # Prefix bin name to disambiguate from (probable) collision with lib name + # N.B.: The exact form of this is subject to change. + name = "cargo_bin_gcc_shim", + deps = [ + # Binaries get an implicit dependency on their crate's lib + ":cc", + ], + srcs = glob(["**/*.rs"]), + crate_root = "src/bin/gcc-shim.rs", + edition = "2018", + rustc_flags = [ + "--cap-lints=allow", + ], + data = glob(["**"], exclude=[ + # These can be manually added with overrides if needed. + + # If you run `cargo build` in this dir, the target dir can get very big very quick. + "target/**", + + # These are not vendored from the crate - we exclude them to avoid busting caches + # when we change how we generate BUILD files and such. + "BUILD.bazel", + "WORKSPACE.bazel", + "WORKSPACE", + ]), + version = "1.0.66", + tags = [ + "cargo-raze", + "manual", + ], + crate_features = [ + ], + aliases = select({ + # Default + "//conditions:default": { + }, + }), +) + +# buildifier: leave-alone +rust_library( + name = "cc", + crate_type = "lib", + deps = [ + ], + srcs = glob(["**/*.rs"]), + crate_root = "src/lib.rs", + edition = "2018", + rustc_flags = [ + "--cap-lints=allow", + ], + data = glob(["**"], exclude=[ + # These can be manually added with overrides if needed. + + # If you run `cargo build` in this dir, the target dir can get very big very quick. + "target/**", + + # These are not vendored from the crate - we exclude them to avoid busting caches + # when we change how we generate BUILD files and such. + "BUILD.bazel", + "WORKSPACE.bazel", + "WORKSPACE", + ]), + version = "1.0.66", + tags = [ + "cargo-raze", + "manual", + ], + crate_features = [ + ], + aliases = select({ + # Default + "//conditions:default": { + }, + }), +) +# Unsupported target "cc_env" with type "test" omitted +# Unsupported target "cflags" with type "test" omitted +# Unsupported target "cxxflags" with type "test" omitted +# Unsupported target "test" with type "test" omitted +""", + sha256 = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48", + strip_prefix = "cc-1.0.66", + type = "tar.gz", + url = "https://crates.io/api/v1/crates/cc/1.0.66/download", + ) + + http_archive( + name = "crate_universe_uses_sys_crate_rust_deps__libc__0_2_76", + # TODO: Allow configuring where rust_library comes from + build_file_content = """# buildifier: disable=load +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", + "rust_library", + "rust_test", +) + +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + +package(default_visibility = [ + "//visibility:public", +]) + +licenses([ + "notice", # MIT from expression "MIT OR Apache-2.0" +]) + +# Generated targets +# buildifier: disable=load-on-top +load( + "@rules_rust//cargo:cargo_build_script.bzl", + "cargo_build_script", +) + +# buildifier: leave-alone +cargo_build_script( + name = "libc_build_script", + srcs = glob(["**/*.rs"]), + crate_root = "build.rs", + edition = "2015", + deps = [ + ], + rustc_flags = [ + "--cap-lints=allow", + ], + crate_features = [ + "default", + "std", + ], + build_script_env = { + }, + data = glob(["**"], exclude=[ + # These can be manually added with overrides if needed. + + # If you run `cargo build` in this dir, the target dir can get very big very quick. + "target/**", + + # These are not vendored from the crate - we exclude them to avoid busting caches + # when we change how we generate BUILD files and such. + "BUILD.bazel", + "WORKSPACE.bazel", + "WORKSPACE", + ]), + tags = [ + "cargo-raze", + "manual", + ], + version = "0.2.76", + visibility = ["//visibility:private"], +) + + +# buildifier: leave-alone +rust_library( + name = "libc", + crate_type = "lib", + deps = [ + ":libc_build_script", + ], + srcs = glob(["**/*.rs"]), + crate_root = "src/lib.rs", + edition = "2015", + rustc_flags = [ + "--cap-lints=allow", + ], + data = glob(["**"], exclude=[ + # These can be manually added with overrides if needed. + + # If you run `cargo build` in this dir, the target dir can get very big very quick. + "target/**", + + # These are not vendored from the crate - we exclude them to avoid busting caches + # when we change how we generate BUILD files and such. + "BUILD.bazel", + "WORKSPACE.bazel", + "WORKSPACE", + ]), + version = "0.2.76", + tags = [ + "cargo-raze", + "manual", + ], + crate_features = [ + "default", + "std", + ], + aliases = select({ + # Default + "//conditions:default": { + }, + }), +) +# Unsupported target "const_fn" with type "test" omitted +""", + sha256 = "755456fae044e6fa1ebbbd1b3e902ae19e73097ed4ed87bb79934a867c007bc3", + strip_prefix = "libc-0.2.76", + type = "tar.gz", + url = "https://crates.io/api/v1/crates/libc/0.2.76/download", + ) + + http_archive( + name = "crate_universe_uses_sys_crate_rust_deps__pkg_config__0_3_19", + # TODO: Allow configuring where rust_library comes from + build_file_content = """# buildifier: disable=load +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", + "rust_library", + "rust_test", +) + +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + +package(default_visibility = [ + "//visibility:public", +]) + +licenses([ + "notice", # MIT from expression "MIT OR Apache-2.0" +]) + +# Generated targets + +# buildifier: leave-alone +rust_library( + name = "pkg_config", + crate_type = "lib", + deps = [ + ], + srcs = glob(["**/*.rs"]), + crate_root = "src/lib.rs", + edition = "2015", + rustc_flags = [ + "--cap-lints=allow", + ], + data = glob(["**"], exclude=[ + # These can be manually added with overrides if needed. + + # If you run `cargo build` in this dir, the target dir can get very big very quick. + "target/**", + + # These are not vendored from the crate - we exclude them to avoid busting caches + # when we change how we generate BUILD files and such. + "BUILD.bazel", + "WORKSPACE.bazel", + "WORKSPACE", + ]), + version = "0.3.19", + tags = [ + "cargo-raze", + "manual", + ], + crate_features = [ + ], + aliases = select({ + # Default + "//conditions:default": { + }, + }), +) +# Unsupported target "test" with type "test" omitted +""", + sha256 = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c", + strip_prefix = "pkg-config-0.3.19", + type = "tar.gz", + url = "https://crates.io/api/v1/crates/pkg-config/0.3.19/download", + ) + + +CRATE_TARGET_NAMES = { + "bzip2": "@crate_universe_uses_sys_crate_rust_deps__bzip2__0_3_3//:bzip2", + "libc": "@crate_universe_uses_sys_crate_rust_deps__libc__0_2_76//:libc", +} + +def crate(crate_name): + """Return the name of the target for the given crate. + """ + target_name = CRATE_TARGET_NAMES.get(crate_name) + if target_name == None: + fail("Unknown crate name: {}".format(crate_name)) + return target_name + +def all_deps(): + """Return all standard dependencies explicitly listed in the Cargo.toml or packages list.""" + return [ + crate(crate_name) for crate_name in [ + "bzip2", + "libc", + ] + ] + +def all_proc_macro_deps(): + """Return all proc-macro dependencies explicitly listed in the Cargo.toml or packages list.""" + return [ + crate(crate_name) for crate_name in [ + ] + ] + +def crates_from(label): + mapping = { + "@examples//crate_universe/uses_sys_crate:Cargo.toml": [crate("bzip2")], + } + return mapping[_absolutify(label)] + +def dev_crates_from(label): + mapping = { + "@examples//crate_universe/uses_sys_crate:Cargo.toml": [], + } + return mapping[_absolutify(label)] + +def build_crates_from(label): + mapping = { + "@examples//crate_universe/uses_sys_crate:Cargo.toml": [], + } + return mapping[_absolutify(label)] + +def proc_macro_crates_from(label): + mapping = { + "@examples//crate_universe/uses_sys_crate:Cargo.toml": [], + } + return mapping[_absolutify(label)] + +def _absolutify(label): + if label.startswith("//") or label.startswith("@"): + return label + if label.startswith(":"): + return "//" + native.package_name() + label + return "//" + native.package_name() + ":" + label diff --git a/examples/crate_universe/uses_sys_crate/src/main.rs b/examples/crate_universe/uses_sys_crate/src/main.rs new file mode 100644 index 0000000000..27d3e17682 --- /dev/null +++ b/examples/crate_universe/uses_sys_crate/src/main.rs @@ -0,0 +1,41 @@ +use bzip2::read::BzEncoder; +use bzip2::Compression; +use std::io::Read; + +fn main() { + let stdin = std::io::stdin(); + let mut raw_counter = CountingStream::new(stdin); + + let compressed_count = { + let compressor = BzEncoder::new(&mut raw_counter, Compression::Best); + let mut compressed_counter = CountingStream::new(compressor); + std::io::copy(&mut compressed_counter, &mut std::io::sink()).unwrap(); + compressed_counter.count + }; + + println!( + "Compressed {} to {} bytes", + raw_counter.count, compressed_count + ); +} + +struct CountingStream { + stream: R, + count: usize, +} + +impl CountingStream { + fn new(stream: R) -> Self { + CountingStream { stream, count: 0 } + } +} + +impl Read for CountingStream { + fn read(&mut self, buf: &mut [u8]) -> std::io::Result { + let result = self.stream.read(buf); + if let Ok(read_bytes) = result { + self.count += read_bytes; + } + result + } +} diff --git a/examples/crate_universe/uses_sys_crate/test.sh b/examples/crate_universe/uses_sys_crate/test.sh new file mode 100755 index 0000000000..5e82b327dc --- /dev/null +++ b/examples/crate_universe/uses_sys_crate/test.sh @@ -0,0 +1,6 @@ +#!/bin/bash -eu + +out="$(echo -n "Hello world" | "$1")" + +expected="Compressed 11 to 50 bytes" +[[ "${out}" == ${expected} ]] || { echo "Expected '${expected}', got '${out}'"; exit 1; } diff --git a/examples/examples_deps.bzl b/examples/examples_deps.bzl index c669cca615..5c163c9973 100644 --- a/examples/examples_deps.bzl +++ b/examples/examples_deps.bzl @@ -9,10 +9,15 @@ load("@rules_rust//bindgen:repositories.bzl", "rust_bindgen_repositories") load("@rules_rust//proto:repositories.bzl", "rust_proto_repositories") load("@rules_rust//rust:repositories.bzl", "rust_repositories", "rust_repository_set") load("@rules_rust//wasm_bindgen:repositories.bzl", "rust_wasm_bindgen_repositories") +load("@rules_rust//cargo:repositories.bzl", "crate_universe_deps") +load("@rules_rust//cargo:workspace.bzl", "crate", "crate_universe") -def deps(): + +def deps(is_top_level = False): """Define dependencies for `rules_rust` examples""" + examples_prefix = "@examples" if is_top_level else "" + rust_repositories() rust_bindgen_repositories() @@ -53,3 +58,66 @@ def deps(): ) rules_foreign_cc_dependencies() + + crate_universe_deps() + + crate_universe( + name = "crate_universe_basic_rust_deps", + packages = [ + crate.spec( + name = "lazy_static", + semver = "=1.4", + ), + ], + supported_targets = [ + "x86_64-apple-darwin", + "x86_64-unknown-linux-gnu", + ], + ) + + crate_universe( + name = "crate_universe_uses_proc_macro_rust_deps", + cargo_toml_files = [examples_prefix + "//crate_universe/uses_proc_macro:Cargo.toml"], + supported_targets = [ + "x86_64-apple-darwin", + "x86_64-unknown-linux-gnu", + ], + ) + + crate_universe( + name = "crate_universe_uses_sys_crate_rust_deps", + cargo_toml_files = [examples_prefix + "//crate_universe/uses_sys_crate:Cargo.toml"], + lockfile = examples_prefix + "//crate_universe/uses_sys_crate:lockfile.lock", + packages = [ + crate.spec( + name = "libc", + semver = "=0.2.76", + ), + ], + supported_targets = [ + "x86_64-apple-darwin", + "x86_64-unknown-linux-gnu", + ], + ) + + crate_universe( + name = "crate_universe_has_aliased_deps_rust_deps", + cargo_toml_files = [examples_prefix + "//crate_universe/has_aliased_deps:Cargo.toml"], + overrides = { + "openssl-sys": crate.override( + extra_build_script_env_vars = { + "OPENSSL_DIR": "../openssl/openssl", + }, + extra_bazel_deps = { + "cfg(all())": ["@openssl//:openssl"], + }, + extra_build_script_bazel_data_deps = { + "cfg(all())": ["@openssl//:openssl"], + }, + ), + }, + supported_targets = [ + "x86_64-apple-darwin", + "x86_64-unknown-linux-gnu", + ], + ) diff --git a/examples/examples_transitive_deps.bzl b/examples/examples_transitive_deps.bzl index bac369466b..67410d45c8 100644 --- a/examples/examples_transitive_deps.bzl +++ b/examples/examples_transitive_deps.bzl @@ -8,6 +8,11 @@ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories") load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains") +load("@crate_universe_basic_rust_deps//:defs.bzl", basic_pinned_rust_install = "pinned_rust_install") +load("@crate_universe_uses_proc_macro_rust_deps//:defs.bzl", uses_proc_macro_pinned_rust_install = "pinned_rust_install") +load("@crate_universe_uses_sys_crate_rust_deps//:defs.bzl", uses_sys_crate_pinned_rust_install = "pinned_rust_install") +load("@crate_universe_has_aliased_deps_rust_deps//:defs.bzl", has_aliased_deps_pinned_rust_install = "pinned_rust_install") + # buildifier: disable=unnamed-macro def transitive_deps(is_top_level = False): """Define transitive dependencies for `rules_rust` examples @@ -36,3 +41,11 @@ def transitive_deps(is_top_level = False): ) node_repositories() + + basic_pinned_rust_install() + + uses_proc_macro_pinned_rust_install() + + uses_sys_crate_pinned_rust_install() + + has_aliased_deps_pinned_rust_install()