diff --git a/docs/src/rust/components.md b/docs/src/rust/components.md index 18b6d99..d15b5e9 100644 --- a/docs/src/rust/components.md +++ b/docs/src/rust/components.md @@ -9,7 +9,41 @@ - `mkComponent` is made for building extensions where you can create your own Nedryland component types by passing in the `nedrylandType` string. -## Specifying Dependencies +## Specifying Crate Dependencies + +In order to be deterministic crates are downloaded and verified ahead of building, and +these crates need to be made available to the build environment. This is done through +`buildInputs`. Crates can be be defined using +`base.languages.rust.fetchCrate {name = "some-crate-name"; version = "x.y.z"; sha256 = "sha"; deps = [crate]}` +where sha256 is the same as you will find on +[crates index](https://github.com/rust-lang/crates.io-index) and deps is a list of these +kind of derivations. + +To ease writing of multiple such expressions there's a CLI tool +`gen-crate-expression` both in each rust shell and as an app in Nedryglot's +flake. Use `gen-crate-expression --help` for usage information. + +A set of crates has also been generated and ships with nedryglot under +`base.languages.rust.crates`. These are roughly equivalent to the crates +available in [Rust Playground](https://play.rust-lang.org/). This default crate +set can be overridden by making an extension. This extension overrides the crate +set with a set of one crate: +```nix +{ base }: +{ + languages.rust = base.languages.rust.overrideAttr { + crates = { + gimli = base.languages.rust.fetchCrate { + name="gimli"; + version="0.27.3"; + sha256="b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e"; deps=[]; + }; + }; + }; +} +``` + +## Specifying Other Dependencies Specifying dependencies in a Rust component can be done in two ways. First option is to assign any of the standard `mkDerivation` arguments a list with the needed inputs. diff --git a/docs/src/rust/override.md b/docs/src/rust/override.md index 98c97c0..94b2327 100644 --- a/docs/src/rust/override.md +++ b/docs/src/rust/override.md @@ -1,6 +1,6 @@ # Overriding the Rust Version -`base.languages.rust` exposes the function `overrideRust` to change the +`base.languages.rust` exposes the function `mkRustToolset` to change the build/lint tools. This function takes a number of required arguments to override the specific tools. The non-overriden tools are the following: diff --git a/flake.nix b/flake.nix index 5feb6af..1f76a04 100644 --- a/flake.nix +++ b/flake.nix @@ -47,7 +47,12 @@ (import ./test.nix nedry).all; }; - apps = nedryland.apps.${system}; + apps = nedryland.apps.${system} // { + gen-crate-expression = { + type = "app"; + program = ''${pkgs.python3}/bin/python ${./rust/gen-crates-expr.py} "$@"}''; + }; + }; } ); } diff --git a/rust/cargo-internal.config.toml b/rust/cargo-internal.config.toml deleted file mode 100644 index 678ea9c..0000000 --- a/rust/cargo-internal.config.toml +++ /dev/null @@ -1,9 +0,0 @@ -[registries] -nix = { index = "https://fake-nix-registry/not-really-an-index" } - -[source.nix] -registry = "https://fake-nix-registry/not-really-an-index" -replace-with = "vendored-internal" - -[source.vendored-internal] -directory = "@vendorDir@" diff --git a/rust/crate-setup-hook.sh b/rust/crate-setup-hook.sh new file mode 100644 index 0000000..7a0870f --- /dev/null +++ b/rust/crate-setup-hook.sh @@ -0,0 +1,18 @@ +#! /usr/bin/env bash + +crates="$NIX_BUILD_TOP"/.nedryglot/.dependency-crates +name="$crates/$(echo "@out@" | sed -E 's|/nix/store/\w{32}-||')" +mkdir -p "$crates" +if [ ! -e "@out@"/Cargo.toml ]; then + for crate in "@out@"/*; do + if [ ! -e "$crates/$(basename "$crate")" ] && [ -f "$crate"/Cargo.toml ]; then + ln -s "$crate" "$crates/$(basename "$crate")" + fi + done +elif [ ! -e "$name" ]; then + ln -s "@out@" "$name" +fi + +echo "[source.crates-io] +directory=\"$NIX_BUILD_TOP/.nedryglot/.dependency-crates\"" >"$NIX_BUILD_TOP"/.nedryglot/config.toml +export CARGO_HOME="$NIX_BUILD_TOP"/.nedryglot diff --git a/rust/default-crates.nix b/rust/default-crates.nix new file mode 100644 index 0000000..446394e --- /dev/null +++ b/rust/default-crates.nix @@ -0,0 +1,140 @@ +fetchCrate: rec{ + addr2line = fetchCrate { name = "addr2line"; version = "0.21.0"; sha256 = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"; deps = [ gimli ]; }; + adler = fetchCrate { name = "adler"; version = "1.0.2"; sha256 = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"; deps = [ ]; }; + aho-corasick = fetchCrate { name = "aho-corasick"; version = "1.0.4"; sha256 = "6748e8def348ed4d14996fa801f4122cd763fff530258cdc03f64b25f89d3a5a"; deps = [ ]; }; + ansi_term = fetchCrate { name = "ansi_term"; version = "0.12.1"; sha256 = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"; deps = [ winapi ]; }; + anstyle = fetchCrate { name = "anstyle"; version = "1.0.1"; sha256 = "3a30da5c5f2d5e72842e00bcb57657162cdabef0931f40e2deb9b4140440cecd"; deps = [ ]; }; + anyhow = fetchCrate { name = "anyhow"; version = "1.0.75"; sha256 = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"; deps = [ ]; }; + atty = fetchCrate { name = "atty"; version = "0.2.14"; sha256 = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"; deps = [ winapi hermit-abi libc ]; }; + autocfg = fetchCrate { name = "autocfg"; version = "1.1.0"; sha256 = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"; deps = [ ]; }; + backtrace = fetchCrate { name = "backtrace"; version = "0.3.69"; sha256 = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837"; deps = [ cc libc rustc-demangle miniz_oxide cfg-if addr2line object ]; }; + base64 = fetchCrate { name = "base64"; version = "0.21.2"; sha256 = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d"; deps = [ ]; }; + bitflags = fetchCrate { name = "bitflags"; version = "2.4.0"; sha256 = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"; deps = [ ]; }; + block-buffer = fetchCrate { name = "block-buffer"; version = "0.11.0-pre"; sha256 = "23b6a33d658e9ef24ba0c4566d3d023d7978ca2ea3efb65e4eacd4586695892b"; deps = [ crypto-common generic-array ]; }; + byteorder = fetchCrate { name = "byteorder"; version = "1.4.3"; sha256 = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"; deps = [ ]; }; + bytes = fetchCrate { name = "bytes"; version = "1.4.0"; sha256 = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be"; deps = [ ]; }; + cc = fetchCrate { name = "cc"; version = "1.0.83"; sha256 = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"; deps = [ libc ]; }; + cfg-if = fetchCrate { name = "cfg-if"; version = "1.0.0"; sha256 = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"; deps = [ ]; }; + chrono = fetchCrate { name = "chrono"; version = "0.4.20-rc.1"; sha256 = "856628f00a013eb30ae7b136b20fba37f7a39f8026d6f735dfac07c6fce1b8cf"; deps = [ num-integer num-traits ]; }; + clap = fetchCrate { name = "clap"; version = "4.3.23"; sha256 = "03aef18ddf7d879c15ce20f04826ef8418101c7e528014c3eeea13321047dca3"; deps = [ clap_builder ]; }; + clap_builder = fetchCrate { name = "clap_builder"; version = "4.3.23"; sha256 = "f8ce6fffb678c9b80a70b6b6de0aad31df727623a70fd9a842c30cd573e2fa98"; deps = [ clap_lex anstyle ]; }; + clap_lex = fetchCrate { name = "clap_lex"; version = "0.5.0"; sha256 = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"; deps = [ ]; }; + cpufeatures = fetchCrate { name = "cpufeatures"; version = "0.2.9"; sha256 = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1"; deps = [ libc ]; }; + crossbeam-channel = fetchCrate { name = "crossbeam-channel"; version = "0.5.8"; sha256 = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200"; deps = [ cfg-if ]; }; + crossbeam-epoch = fetchCrate { name = "crossbeam-epoch"; version = "0.9.15"; sha256 = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7"; deps = [ memoffset scopeguard crossbeam-utils cfg-if autocfg ]; }; + crossbeam-utils = fetchCrate { name = "crossbeam-utils"; version = "0.8.16"; sha256 = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294"; deps = [ cfg-if ]; }; + crypto-common = fetchCrate { name = "crypto-common"; version = "0.2.0-pre"; sha256 = "6faaa83e7700e0832cbbf84854d4c356270526907d9b14fab927fc7a9b5befb8"; deps = [ typenum generic-array ]; }; + deranged = fetchCrate { name = "deranged"; version = "0.3.8"; sha256 = "f2696e8a945f658fd14dc3b87242e6b80cd0f36ff04ea560fa39082368847946"; deps = [ ]; }; + digest = fetchCrate { name = "digest"; version = "0.11.0-pre"; sha256 = "1f2e47350a84ef81587a050177f84af69defbf2bee70bdfb92b500dbbd247e97"; deps = [ crypto-common ]; }; + either = fetchCrate { name = "either"; version = "1.9.0"; sha256 = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"; deps = [ ]; }; + env_logger = fetchCrate { name = "env_logger"; version = "0.10.0"; sha256 = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0"; deps = [ log ]; }; + equivalent = fetchCrate { name = "equivalent"; version = "1.0.1"; sha256 = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"; deps = [ ]; }; + fnv = fetchCrate { name = "fnv"; version = "1.0.7"; sha256 = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"; deps = [ ]; }; + form_urlencoded = fetchCrate { name = "form_urlencoded"; version = "1.2.0"; sha256 = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652"; deps = [ percent-encoding ]; }; + futures = fetchCrate { name = "futures"; version = "0.3.28"; sha256 = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40"; deps = [ futures-sink futures-core futures-task futures-channel futures-util futures-io ]; }; + futures-channel = fetchCrate { name = "futures-channel"; version = "0.3.28"; sha256 = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2"; deps = [ futures-core ]; }; + futures-core = fetchCrate { name = "futures-core"; version = "0.3.28"; sha256 = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c"; deps = [ ]; }; + futures-io = fetchCrate { name = "futures-io"; version = "0.3.28"; sha256 = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964"; deps = [ ]; }; + futures-sink = fetchCrate { name = "futures-sink"; version = "0.3.28"; sha256 = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e"; deps = [ ]; }; + futures-task = fetchCrate { name = "futures-task"; version = "0.3.28"; sha256 = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65"; deps = [ ]; }; + futures-util = fetchCrate { name = "futures-util"; version = "0.3.28"; sha256 = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533"; deps = [ futures-core pin-project-lite futures-task pin-utils ]; }; + generic-array = fetchCrate { name = "generic-array"; version = "1.0.0-alpha.1"; sha256 = "b52c12c7083a12e2f5090ffa80947276573c0fcd7a1c910b73b34f78ddf5626c"; deps = [ typenum version_check ]; }; + getrandom = fetchCrate { name = "getrandom"; version = "0.2.10"; sha256 = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"; deps = [ cfg-if wasi libc ]; }; + gimli = fetchCrate { name = "gimli"; version = "0.28.0"; sha256 = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0"; deps = [ ]; }; + hashbrown = fetchCrate { name = "hashbrown"; version = "0.14.0"; sha256 = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"; deps = [ ]; }; + heck = fetchCrate { name = "heck"; version = "0.5.0-rc.1"; sha256 = "28eaf72f9d21ee92f580d066b93d05742a4d188e91016b8165dc7a75c0475309"; deps = [ ]; }; + hermit-abi = fetchCrate { name = "hermit-abi"; version = "0.3.2"; sha256 = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b"; deps = [ ]; }; + http = fetchCrate { name = "http"; version = "0.2.9"; sha256 = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482"; deps = [ itoa bytes fnv ]; }; + http-body = fetchCrate { name = "http-body"; version = "1.0.0-rc1"; sha256 = "f038884e63a5a85612eeea789f5e0f54c3ada7306234502543b23d98744781f0"; deps = [ http bytes ]; }; + httparse = fetchCrate { name = "httparse"; version = "1.8.0"; sha256 = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904"; deps = [ ]; }; + httpdate = fetchCrate { name = "httpdate"; version = "1.0.3"; sha256 = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"; deps = [ ]; }; + hyper = fetchCrate { name = "hyper"; version = "1.0.0-rc.4"; sha256 = "d280a71f348bcc670fc55b02b63c53a04ac0bf2daff2980795aeaf53edae10e6"; deps = [ want httpdate itoa http-body futures-channel tokio http bytes futures-util pin-project-lite tracing httparse ]; }; + idna = fetchCrate { name = "idna"; version = "0.4.0"; sha256 = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c"; deps = [ unicode-normalization unicode-bidi ]; }; + indexmap = fetchCrate { name = "indexmap"; version = "2.0.0"; sha256 = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d"; deps = [ equivalent hashbrown ]; }; + itertools = fetchCrate { name = "itertools"; version = "0.11.0"; sha256 = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57"; deps = [ either ]; }; + itoa = fetchCrate { name = "itoa"; version = "1.0.9"; sha256 = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"; deps = [ ]; }; + lazy_static = fetchCrate { name = "lazy_static"; version = "1.4.0"; sha256 = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"; deps = [ ]; }; + libc = fetchCrate { name = "libc"; version = "0.2.147"; sha256 = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"; deps = [ ]; }; + lock_api = fetchCrate { name = "lock_api"; version = "0.4.10"; sha256 = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16"; deps = [ scopeguard autocfg ]; }; + log = fetchCrate { name = "log"; version = "0.4.20"; sha256 = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"; deps = [ ]; }; + memchr = fetchCrate { name = "memchr"; version = "2.5.0"; sha256 = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"; deps = [ ]; }; + memoffset = fetchCrate { name = "memoffset"; version = "0.9.0"; sha256 = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c"; deps = [ autocfg ]; }; + minimal-lexical = fetchCrate { name = "minimal-lexical"; version = "0.2.1"; sha256 = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"; deps = [ ]; }; + miniz_oxide = fetchCrate { name = "miniz_oxide"; version = "0.7.1"; sha256 = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7"; deps = [ adler ]; }; + mio = fetchCrate { name = "mio"; version = "0.8.8"; sha256 = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2"; deps = [ wasi libc windows-sys ]; }; + nom = fetchCrate { name = "nom"; version = "7.1.3"; sha256 = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"; deps = [ minimal-lexical memchr ]; }; + num_cpus = fetchCrate { name = "num_cpus"; version = "1.16.0"; sha256 = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43"; deps = [ hermit-abi libc ]; }; + num-integer = fetchCrate { name = "num-integer"; version = "0.1.45"; sha256 = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"; deps = [ num-traits autocfg ]; }; + num-traits = fetchCrate { name = "num-traits"; version = "0.2.16"; sha256 = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2"; deps = [ autocfg ]; }; + object = fetchCrate { name = "object"; version = "0.32.0"; sha256 = "77ac5bbd07aea88c60a577a1ce218075ffd59208b2d7ca97adf9bfc5aeb21ebe"; deps = [ memchr ]; }; + once_cell = fetchCrate { name = "once_cell"; version = "1.18.0"; sha256 = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"; deps = [ ]; }; + parking_lot = fetchCrate { name = "parking_lot"; version = "0.12.1"; sha256 = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"; deps = [ parking_lot_core lock_api ]; }; + parking_lot_core = fetchCrate { name = "parking_lot_core"; version = "0.9.8"; sha256 = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447"; deps = [ libc redox_syscall windows-targets cfg-if smallvec ]; }; + percent-encoding = fetchCrate { name = "percent-encoding"; version = "2.3.0"; sha256 = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94"; deps = [ ]; }; + pin-project-lite = fetchCrate { name = "pin-project-lite"; version = "0.2.12"; sha256 = "12cc1b0bf1727a77a54b6654e7b5f1af8604923edc8b81885f8ec92f9e3f0a05"; deps = [ ]; }; + pin-utils = fetchCrate { name = "pin-utils"; version = "0.1.0"; sha256 = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"; deps = [ ]; }; + pkg-config = fetchCrate { name = "pkg-config"; version = "0.3.27"; sha256 = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"; deps = [ ]; }; + ppv-lite86 = fetchCrate { name = "ppv-lite86"; version = "0.2.17"; sha256 = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"; deps = [ ]; }; + proc-macro2 = fetchCrate { name = "proc-macro2"; version = "1.0.66"; sha256 = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"; deps = [ unicode-ident ]; }; + quote = fetchCrate { name = "quote"; version = "1.0.33"; sha256 = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"; deps = [ proc-macro2 ]; }; + rand = fetchCrate { name = "rand"; version = "0.8.5"; sha256 = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"; deps = [ rand_core ]; }; + rand_chacha = fetchCrate { name = "rand_chacha"; version = "0.3.1"; sha256 = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"; deps = [ ppv-lite86 rand_core ]; }; + rand_core = fetchCrate { name = "rand_core"; version = "0.6.4"; sha256 = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"; deps = [ ]; }; + redox_syscall = fetchCrate { name = "redox_syscall"; version = "0.3.5"; sha256 = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29"; deps = [ bitflags ]; }; + regex = fetchCrate { name = "regex"; version = "1.9.3"; sha256 = "81bc1d4caf89fac26a70747fe603c130093b53c773888797a6329091246d651a"; deps = [ regex-syntax regex-automata ]; }; + regex-automata = fetchCrate { name = "regex-automata"; version = "0.3.6"; sha256 = "fed1ceff11a1dddaee50c9dc8e4938bd106e9d89ae372f192311e7da498e3b69"; deps = [ ]; }; + regex-syntax = fetchCrate { name = "regex-syntax"; version = "0.7.4"; sha256 = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2"; deps = [ ]; }; + rustc_version = fetchCrate { name = "rustc_version"; version = "0.4.0"; sha256 = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366"; deps = [ semver ]; }; + rustc-demangle = fetchCrate { name = "rustc-demangle"; version = "0.1.23"; sha256 = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"; deps = [ ]; }; + ryu = fetchCrate { name = "ryu"; version = "1.0.15"; sha256 = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"; deps = [ ]; }; + scopeguard = fetchCrate { name = "scopeguard"; version = "1.2.0"; sha256 = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"; deps = [ ]; }; + semver = fetchCrate { name = "semver"; version = "1.0.18"; sha256 = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918"; deps = [ ]; }; + serde = fetchCrate { name = "serde"; version = "1.0.172-alpha.0"; sha256 = "0c4d129c1e009c34022bfa546ef5f80a299e232db60e57fcdffed0882d736d16"; deps = [ ]; }; + serde_derive = fetchCrate { name = "serde_derive"; version = "1.0.172-alpha.0"; sha256 = "c17860c5973d806a49e6424f50331599589ca7020efb87c9335109fa1fc69102"; deps = [ syn proc-macro2 quote ]; }; + serde_json = fetchCrate { name = "serde_json"; version = "1.0.105"; sha256 = "693151e1ac27563d6dbcec9dee9fbd5da8539b20fa14ad3752b2e6d363ace360"; deps = [ itoa ryu serde ]; }; + serde_spanned = fetchCrate { name = "serde_spanned"; version = "0.6.3"; sha256 = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186"; deps = [ ]; }; + sha2 = fetchCrate { name = "sha2"; version = "0.10.7"; sha256 = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8"; deps = [ cfg-if cpufeatures digest ]; }; + slab = fetchCrate { name = "slab"; version = "0.4.9"; sha256 = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67"; deps = [ autocfg ]; }; + smallvec = fetchCrate { name = "smallvec"; version = "1.11.0"; sha256 = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9"; deps = [ ]; }; + socket2 = fetchCrate { name = "socket2"; version = "0.5.3"; sha256 = "2538b18701741680e0322a2302176d3253a35388e2e62f172f64f4f16605f877"; deps = [ libc windows-sys ]; }; + strsim = fetchCrate { name = "strsim"; version = "0.10.0"; sha256 = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"; deps = [ ]; }; + syn = fetchCrate { name = "syn"; version = "2.0.29"; sha256 = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a"; deps = [ proc-macro2 unicode-ident ]; }; + termcolor = fetchCrate { name = "termcolor"; version = "1.2.0"; sha256 = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6"; deps = [ winapi-util ]; }; + textwrap = fetchCrate { name = "textwrap"; version = "0.16.0"; sha256 = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d"; deps = [ ]; }; + thiserror = fetchCrate { name = "thiserror"; version = "1.0.47"; sha256 = "97a802ec30afc17eee47b2855fc72e0c4cd62be9b4efe6591edde0ec5bd68d8f"; deps = [ thiserror-impl ]; }; + thiserror-impl = fetchCrate { name = "thiserror-impl"; version = "1.0.47"; sha256 = "6bb623b56e39ab7dcd4b1b98bb6c8f8d907ed255b18de254088016b27a8ee19b"; deps = [ syn proc-macro2 quote ]; }; + thread_local = fetchCrate { name = "thread_local"; version = "1.1.7"; sha256 = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152"; deps = [ cfg-if once_cell ]; }; + time = fetchCrate { name = "time"; version = "0.3.27"; sha256 = "0bb39ee79a6d8de55f48f2293a830e040392f1c5f16e336bdd1788cd0aadce07"; deps = [ time-core deranged ]; }; + time-core = fetchCrate { name = "time-core"; version = "0.1.1"; sha256 = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb"; deps = [ ]; }; + tinyvec = fetchCrate { name = "tinyvec"; version = "1.6.0"; sha256 = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50"; deps = [ ]; }; + tokio = fetchCrate { name = "tokio"; version = "1.32.0"; sha256 = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9"; deps = [ pin-project-lite backtrace ]; }; + tokio-util = fetchCrate { name = "tokio-util"; version = "0.7.8"; sha256 = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d"; deps = [ futures-sink futures-core tokio pin-project-lite bytes ]; }; + toml = fetchCrate { name = "toml"; version = "0.7.6"; sha256 = "c17e963a819c331dcacd7ab957d80bc2b9a9c1e71c804826d2f283dd65306542"; deps = [ toml_datetime serde_spanned serde ]; }; + toml_datetime = fetchCrate { name = "toml_datetime"; version = "0.6.3"; sha256 = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b"; deps = [ ]; }; + tracing = fetchCrate { name = "tracing"; version = "0.1.37"; sha256 = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"; deps = [ cfg-if pin-project-lite tracing-core ]; }; + tracing-core = fetchCrate { name = "tracing-core"; version = "0.1.31"; sha256 = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a"; deps = [ ]; }; + try-lock = fetchCrate { name = "try-lock"; version = "0.2.4"; sha256 = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed"; deps = [ ]; }; + typenum = fetchCrate { name = "typenum"; version = "1.16.0"; sha256 = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"; deps = [ ]; }; + unicode-bidi = fetchCrate { name = "unicode-bidi"; version = "0.3.13"; sha256 = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460"; deps = [ ]; }; + unicode-ident = fetchCrate { name = "unicode-ident"; version = "1.0.11"; sha256 = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c"; deps = [ ]; }; + unicode-normalization = fetchCrate { name = "unicode-normalization"; version = "0.1.22"; sha256 = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921"; deps = [ tinyvec ]; }; + unicode-width = fetchCrate { name = "unicode-width"; version = "0.1.10"; sha256 = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"; deps = [ ]; }; + unicode-xid = fetchCrate { name = "unicode-xid"; version = "0.2.4"; sha256 = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"; deps = [ ]; }; + url = fetchCrate { name = "url"; version = "2.4.0"; sha256 = "50bff7831e19200a85b17131d085c25d7811bc4e186efdaf54bbd132994a88cb"; deps = [ form_urlencoded percent-encoding idna ]; }; + version_check = fetchCrate { name = "version_check"; version = "0.9.4"; sha256 = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"; deps = [ ]; }; + want = fetchCrate { name = "want"; version = "0.3.1"; sha256 = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e"; deps = [ try-lock ]; }; + wasi = fetchCrate { name = "wasi"; version = "0.11.0+wasi-snapshot-preview1"; sha256 = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"; deps = [ ]; }; + winapi = fetchCrate { name = "winapi"; version = "0.3.9"; sha256 = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"; deps = [ winapi-i686-pc-windows-gnu winapi-x86_64-pc-windows-gnu ]; }; + winapi-i686-pc-windows-gnu = fetchCrate { name = "winapi-i686-pc-windows-gnu"; version = "0.4.0"; sha256 = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"; deps = [ ]; }; + winapi-util = fetchCrate { name = "winapi-util"; version = "0.1.5"; sha256 = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"; deps = [ winapi ]; }; + winapi-x86_64-pc-windows-gnu = fetchCrate { name = "winapi-x86_64-pc-windows-gnu"; version = "0.4.0"; sha256 = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"; deps = [ ]; }; + windows_aarch64_gnullvm = fetchCrate { name = "windows_aarch64_gnullvm"; version = "0.48.5"; sha256 = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"; deps = [ ]; }; + windows_aarch64_msvc = fetchCrate { name = "windows_aarch64_msvc"; version = "0.48.5"; sha256 = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"; deps = [ ]; }; + windows_i686_gnu = fetchCrate { name = "windows_i686_gnu"; version = "0.48.5"; sha256 = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"; deps = [ ]; }; + windows_i686_msvc = fetchCrate { name = "windows_i686_msvc"; version = "0.48.5"; sha256 = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"; deps = [ ]; }; + windows_x86_64_gnu = fetchCrate { name = "windows_x86_64_gnu"; version = "0.48.5"; sha256 = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"; deps = [ ]; }; + windows_x86_64_gnullvm = fetchCrate { name = "windows_x86_64_gnullvm"; version = "0.48.5"; sha256 = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"; deps = [ ]; }; + windows_x86_64_msvc = fetchCrate { name = "windows_x86_64_msvc"; version = "0.48.5"; sha256 = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"; deps = [ ]; }; + windows-sys = fetchCrate { name = "windows-sys"; version = "0.48.0"; sha256 = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"; deps = [ windows-targets ]; }; + windows-targets = fetchCrate { name = "windows-targets"; version = "0.48.5"; sha256 = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"; deps = [ windows_x86_64_msvc windows_i686_gnu windows_x86_64_gnullvm windows_aarch64_gnullvm windows_x86_64_gnu windows_i686_msvc windows_aarch64_msvc ]; }; +} diff --git a/rust/default.nix b/rust/default.nix index ed6c38b..bfa876f 100644 --- a/rust/default.nix +++ b/rust/default.nix @@ -4,10 +4,8 @@ let , callPackage , cargo , clippy - , coreutils , jq , lib - , makeSetupHook , j2cli , pkgs , python3 @@ -17,8 +15,10 @@ let , rustfmt , stdenv , symlinkJoin + , fetchurl , tonicVersion ? "0.7.2" , xdg-utils + , crates ? null , crossTargets ? { } , extraAttrs ? { } }: @@ -180,15 +180,6 @@ let package.overrideAttrs ( oldAttrs: { - nativeBuildInputs = oldAttrs.nativeBuildInputs - ++ [ - (makeSetupHook - { - name = "generate-cargo-checksums"; - deps = [ jq coreutils ]; - } ./generateCargoChecksums.sh) - ]; - buildPhase = '' runHook preBuild cargo package --no-verify --no-metadata @@ -198,13 +189,16 @@ let installPhase = '' runHook preInstall ${oldAttrs.installPhase or ""} - mkdir -p $out/src/rust + mkdir -p $out for crate in target/package/*.crate; do - tar -xzf $crate -C $out/src/rust + tar -xzf $crate -C $out + echo "{\"files\":{},\"package\":\"$(sha256sum $crate | grep -E -o '^(\w*)')\"}" >$out/"$(basename "''${crate//.crate/}")"/.cargo-checksum.json done runHook postInstall ''; + + setupHook = ./crate-setup-hook.sh; } ); @@ -216,9 +210,29 @@ let addAttributes = f: inner (args // { extraAttrs = (extraAttrs // (f extraAttrs)); }); + + fetchCrate = { name, version, sha256, deps ? [ ] }: + stdenv.mkDerivation rec{ + inherit version; + pname = name; + propagatedBuildInputs = deps; + src = fetchurl { + name = "${name}.tar.gz"; + inherit sha256; + url = "https://crates.io/api/v1/crates/${name}/${version}/download"; + }; + installPhase = '' + mkdir $out + cp -r . $out + echo "{\"files\":{},\"package\":\"$(sha256sum ${src} | grep -E -o '^(\w*)')\"}" >$out/.cargo-checksum.json + ''; + setupHook = ./crate-setup-hook.sh; + }; + in extraAttrs // { - inherit overrideAttrs mkRustToolset mkCrossTarget overrideCrossTargets toApplication toLibrary mkLibrary addAttributes toRustTarget; + inherit overrideAttrs mkRustToolset mkCrossTarget overrideCrossTargets toApplication toLibrary mkLibrary addAttributes toRustTarget fetchCrate; + crates = if crates == null then import ./default-crates.nix fetchCrate else crates; crossTargets = crossTargets' // { override = overrideCrossTargets; }; @@ -243,7 +257,6 @@ let defaultVersion = { inherit rustc cargo; }; - mkClient = mkComponentWith base.mkClient toApplication; mkService = mkComponentWith base.mkService toApplication; diff --git a/rust/gen-crates-expr.py b/rust/gen-crates-expr.py new file mode 100644 index 0000000..0e79756 --- /dev/null +++ b/rust/gen-crates-expr.py @@ -0,0 +1,132 @@ +from pathlib import Path +import argparse +import io +import json +import sys +import tarfile +import tempfile +import typing +import urllib.request + + +FETCH_CRATE_EXPR = ' {name} = fetchCrate {{ name="{name}"; version="{version}"; sha256="{sha256}"; deps=[{deps}];}};' + + +def comparable_version(semver: str) -> str: + return ".".join(map(lambda i: i.zfill(4), semver.split("."))) + + +def to_nix_expression(content: io.BufferedReader, version: typing.Optional[str], include_optional_deps: bool) -> (str, typing.List[str]): + """Generate a nix expression from a file inside a tar archive. + + Args: + content: A file inside a tar archive. + version: Use a specific version instead of latest. + include_optional_deps: If optional dependencies should be returned in the deps list + + Returns: + (str, list): The nix expression to fetch the crate and a list of dependencies. + """ + versions = map(json.loads, content.readlines()) + for version_info in sorted(versions, key=lambda v: comparable_version(v.get("vers")), reverse=True): + if version is not None and version_info["vers"] != version: + continue + if not version_info["yanked"]: + deps = set( + map( + lambda dep: dep.get("package", dep["name"]), + filter( + lambda dep: True if dep.get("optional", False) and include_optional_deps else not dep.get("optional", False), + filter( + lambda dep: dep.get("kind") in ["normal", "build"] and dep.get("name") != version_info["name"], + version_info["deps"] + ) + ) + ) + ) + return ( + FETCH_CRATE_EXPR.format( + name=version_info["name"], + version=version_info["vers"], + sha256=version_info["cksum"], + deps=" ".join(deps), + ), + list(deps), + ) + return ("", []) + +def is_crate(tar_member: tarfile.TarInfo) -> bool: + """Filter tar member to only include files describing crates. + + Exclude everything in the .github folder, everything with an extension and + directories. + + Args: + tar_member: The object representing a file in the tar archive. + + Returns: + bool: whether a file is a crate description. + """ + return ( + tar_member.isreg() + and tar_member.name.split("/")[1] != ".github" + and "." not in tar_member.name.split("/")[-1] + ) + +def main(github_ref: str, crates: typing.List[str], output: typing.Optional[Path], include_deps: bool, optional_deps: bool, silent: bool) -> None: + """Generate a nix expression to fetch crates from crates.io index. + + Args: + github_ref: The ref to use on creates.io-index. + creates: The list of crate names to look up. + output: An optional file to output to instead of stdout. + include_deps: If nix expressions should be generated for dependencies. + optional_deps: If optional dependencies should be considered. + silent: If progress and messages should be omitted. + """ + + visited_crates = [] + crates_to_visit = crates + result = [] + + if not silent: + print(f"Downloading crates index at {github_ref}...", file=sys.stderr) + with urllib.request.urlopen(f"https://github.com/rust-lang/crates.io-index/tarball/{github_ref}") as tarball: + with tempfile.NamedTemporaryFile("w+b") as temp_tar: + temp_tar.write(tarball.read()) + with tarfile.open(temp_tar.name) as tar: + for crate in crates_to_visit: + if not silent: + print(f"Looking for {crate}...", file=sys.stderr) + visited_crates.append(crate) + for tar_member in filter(is_crate, tar.getmembers()): + if tar_member.name.split("/")[-1] == crate.split(":")[0]: + version = crate.split(":")[1] if ":" in crate else None + expr, deps = to_nix_expression(tar.extractfile(tar_member.name), version, optional_deps) + if expr: + result.append(expr) + if include_deps and deps: + crates_to_visit.extend([c for c in deps if c not in visited_crates and c not in crates_to_visit]) + break + + expression = "fetchCrate: rec{\n" + "\n\n".join(result) + "\n}" + + if output: + with open(output, "w") as out: + out.write(expression) + else: + print(expression) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Generate a nix expression to fetch rust crates when building with Nedryglot's rust language tooling.") + parser.add_argument("--ref", type=str, help="Git ref of https://github.com/rust-lang/crates.io-index to use for crate lookup, if omitted master is used.", default="master") + parser.add_argument("--output", type=Path, help="Write output to a file instead of stdout.") + parser.add_argument("--no-deps", action="store_true", help="Turn off dependency traversal and only download the listed crates.") + parser.add_argument("--optional-deps", action="store_true", help="Include optional dependencies.") + parser.add_argument("--silent", action="store_true", help="Do not print progress and info to stderr.") + parser.add_argument("crates", nargs="*", help="A space separated list of crates to generate expressions for. Use name:version to fetch a specific version.", default=[]) + args = parser.parse_args() + main(args.ref, args.crates, args.output, not args.no_deps, args.optional_deps, args.silent) + sys.exit(0) + diff --git a/rust/generateCargoChecksums.sh b/rust/generateCargoChecksums.sh deleted file mode 100644 index c978797..0000000 --- a/rust/generateCargoChecksums.sh +++ /dev/null @@ -1,15 +0,0 @@ -#! /usr/bin/env bash - -generateCargoChecksums() { - echo " 🖨 generating checksums for ${name:-}." - for crate in "${out:-}"/src/rust/*; do - if [ ! -f "$crate/.cargo-checksum.json" ]; then - (cd "$crate" || return 1; find . -type f -exec sha256sum {} \; | \ - jq -Rn '{files: (reduce inputs as $val ({}; . + ($val | split("\\s+"; "") | {(.[1]): (.[0])})))}' > \ - ../.cargo-checksum.json; mv ../.cargo-checksum.json .) - fi - done - echo " 🖨 checksums generated!" -} - -fixupOutputHooks+=(generateCargoChecksums) diff --git a/rust/internalDepsSetupHook.sh b/rust/internalDepsSetupHook.sh deleted file mode 100644 index 5319ab3..0000000 --- a/rust/internalDepsSetupHook.sh +++ /dev/null @@ -1,11 +0,0 @@ -#! /usr/bin/env bash - -addRustDeps() { - if [ -d "$1/src/rust" ]; then - for dep in "$1/src/rust/"*; do - export rustDependencies+=" $dep" - done - fi -} - -addEnvHooks "${targetOffset:-}" addRustDeps diff --git a/rust/package.nix b/rust/package.nix index 9de71b4..6bde861 100644 --- a/rust/package.nix +++ b/rust/package.nix @@ -5,6 +5,7 @@ , removeReferencesTo , rootCallPackage , symlinkJoin +, python3 , hostTriple , buildTriple }: @@ -47,11 +48,6 @@ let nativeBuildInputs = resolveInputs name "nativeBuildInputs" [ componentTargetName "rust" ] attrs.nativeBuildInputs or [ ]; checkInputs = resolveInputs name "checkInputs" [ componentTargetName "rust" ] attrs.checkInputs or [ ]; - vendor = callPackage ./vendor.nix { - inherit name buildInputs propagatedBuildInputs; - extraCargoConfig = attrs.extraCargoConfig or ""; - }; - getFeatures = features: if (builtins.length features) == 0 then "" @@ -128,19 +124,23 @@ base.mkDerivation ''; description = "Runs cargo check, clippy and fmt."; }; + gen-crate-expression = { + script = '' + ${python3}/bin/python ${./gen-crates-expr.py} "$@" + ''; + description = "Generate a nix expression for Nedryglot to use as crates. Use --help for usage details."; + }; } // safeAttrs.shellCommands or { }; strictDeps = true; - disallowedReferences = [ vendor ]; + srcFilter = path: type: !(type == "directory" && baseNameOf path == "target") && !(type == "directory" && baseNameOf path == ".cargo") && !(filterCargoLock && type == "regular" && baseNameOf path == "Cargo.lock") && !(builtins.any (pred: pred path type) srcExclude); - vendoredDependencies = vendor; nativeBuildInputs = [ cacert removeReferencesTo - vendor ] ++ (builtins.attrValues rustPlatform.rust) ++ nativeBuildInputs; @@ -165,8 +165,8 @@ base.mkDerivation if [ -z "$IN_NIX_SHELL" ]; then sed -i '/\[patch\.nix\]/,/^[.*]$/d' Cargo.toml fi - export CARGO_HOME=$NIX_BUILD_TOP export RUSTFLAGS="$RUSTFLAGS --remap-path-prefix $NIX_BUILD_TOP=build-root" + runHook postConfigure ''; @@ -195,7 +195,9 @@ base.mkDerivation # by finding store paths in the binary. We strip these store paths so # Nix won't find them. preFixup = '' - find $out -type f -exec remove-references-to -t ${vendor} '{}' + + for crate in "$NIX_BUILD_TOP"/.nedryglot/.dependency-crates/*; do + find $out -type f -exec remove-references-to -t "$(realpath "$crate")" '{}' + + done '' # rustLibSrc is not required for rustPlatform + (if rustPlatform.rust.rustc ? src then diff --git a/rust/setupHook.sh b/rust/setupHook.sh deleted file mode 100644 index 8294587..0000000 --- a/rust/setupHook.sh +++ /dev/null @@ -1,17 +0,0 @@ -#! /usr/bin/env bash - -createCargoConfig() { - if [ -f .cargo/config.toml ] && [ ! -L .cargo/config.toml ]; then - echo -e "\e[31mERROR: $PWD/.cargo/config.toml exists and is not a link.\e[0m" - echo "This is not currently supported and we need to link the file for" - echo "internal dependencies to work. Please remove it and add to .gitignore." - exit 1 - fi - - mkdir -p .cargo - ln -sf @out@/cargo.config.toml .cargo/config.toml - echo "🚜 Linked Cargo vendor config .cargo/config.toml -> @out@/cargo.config.toml" -} - -preConfigureHooks+=(createCargoConfig) -preShellHooks+=(createCargoConfig) diff --git a/rust/vendor.nix b/rust/vendor.nix deleted file mode 100644 index 8f5ff47..0000000 --- a/rust/vendor.nix +++ /dev/null @@ -1,45 +0,0 @@ -{ name -, extraCargoConfig -, stdenv -, makeSetupHook -, buildInputs -, propagatedBuildInputs -}: -# derivation that creates a fake vendor dir with our internal nix dependencies -stdenv.mkDerivation { - inherit extraCargoConfig buildInputs propagatedBuildInputs; - name = "${name}-internal-deps"; - - phases = [ "buildPhase" "installPhase" ]; - nativeBuildInputs = [ - (makeSetupHook - { name = "internal-deps-hook"; } - ./internalDepsSetupHook.sh) - ]; - - buildPhase = '' - mkdir -p vendored - if [ -n "''${rustDependencies}" ]; then - echo "🏡 vendoring internal dependencies..." - - # symlink in all deps - for dep in $rustDependencies; do - ln -sf "$dep" ./vendored/ - done - - echo "🏡 internal dependencies vendored!" - fi - ''; - - installPhase = '' - mkdir $out - cp -r vendored $out - substitute ${./cargo-internal.config.toml} $out/cargo.config.toml \ - --subst-var-by vendorDir $out/vendored - echo "$extraCargoConfig" >> $out/cargo.config.toml - mkdir -p "$out/nix-support" - substituteAll "$setupHook" "$out/nix-support/setup-hook" - ''; - - setupHook = ./setupHook.sh; -} diff --git a/tests/rust.nix b/tests/rust.nix index fcdb739..060e10b 100644 --- a/tests/rust.nix +++ b/tests/rust.nix @@ -67,10 +67,4 @@ assert libraryWasi ? rust && libraryWasi ? wasi && libraryWasi.rust != libraryWa # With inline, default cross target assert libraryRiscv ? rust; -# rust component inter-dependencies -let - lib = rust.mkLibrary { name = "libban"; version = "2.3.1"; src = null; }; - client = rust.mkClient { name = "kunden"; version = "255.255.1"; src = null; buildInputs = [ lib ]; }; -in -assert client.rust.buildInputs == client.rust.vendoredDependencies.buildInputs; -builtins.trace ''✔️ Rust tests succeeded ${rust.emoji}'' { } +{ }