diff options
Diffstat (limited to 'doc/languages-frameworks/rust.md')
-rw-r--r-- | doc/languages-frameworks/rust.md | 100 |
1 files changed, 64 insertions, 36 deletions
diff --git a/doc/languages-frameworks/rust.md b/doc/languages-frameworks/rust.md index aa6a7d654108..d3a25e9d1358 100644 --- a/doc/languages-frameworks/rust.md +++ b/doc/languages-frameworks/rust.md @@ -79,19 +79,24 @@ an example for a minimal `hello` crate: Now, the file produced by the call to `carnix`, called `hello.nix`, looks like: ``` -with import <nixpkgs> {}; +# Generated by carnix 0.6.5: carnix -o hello.nix --src ./. Cargo.lock --standalone +{ lib, buildPlatform, buildRustCrate, fetchgit }: let kernel = buildPlatform.parsed.kernel.name; # ... (content skipped) - hello_0_1_0_ = { dependencies?[], buildDependencies?[], features?[] }: buildRustCrate { - crateName = "hello"; - version = "0.1.0"; - authors = [ "Authorname <user@example.com>" ]; - src = ./.; - inherit dependencies buildDependencies features; - }; in rec { - hello_0_1_0 = hello_0_1_0_ rec {}; + hello = f: hello_0_1_0 { features = hello_0_1_0_features { hello_0_1_0 = f; }; }; + hello_0_1_0_ = { dependencies?[], buildDependencies?[], features?[] }: buildRustCrate { + crateName = "hello"; + version = "0.1.0"; + authors = [ "pe@pijul.org <pe@pijul.org>" ]; + src = ./.; + inherit dependencies buildDependencies features; + }; + hello_0_1_0 = { features?(hello_0_1_0_features {}) }: hello_0_1_0_ {}; + hello_0_1_0_features = f: updateFeatures f (rec { + hello_0_1_0.default = (f.hello_0_1_0.default or true); + }) [ ]; } ``` @@ -103,33 +108,44 @@ dependencies, for instance by adding a single line `libc="*"` to our following nix file: ``` -with import <nixpkgs> {}; +# Generated by carnix 0.6.5: carnix -o hello.nix --src ./. Cargo.lock --standalone +{ lib, buildPlatform, buildRustCrate, fetchgit }: let kernel = buildPlatform.parsed.kernel.name; # ... (content skipped) - hello_0_1_0_ = { dependencies?[], buildDependencies?[], features?[] }: buildRustCrate { - crateName = "hello"; - version = "0.1.0"; - authors = [ "Jörg Thalheim <joerg@thalheim.io>" ]; - src = ./.; - inherit dependencies buildDependencies features; - }; - libc_0_2_34_ = { dependencies?[], buildDependencies?[], features?[] }: buildRustCrate { - crateName = "libc"; - version = "0.2.34"; - authors = [ "The Rust Project Developers" ]; - sha256 = "11jmqdxmv0ka10ay0l8nzx0nl7s2lc3dbrnh1mgbr2grzwdyxi2s"; - inherit dependencies buildDependencies features; - }; in rec { - hello_0_1_0 = hello_0_1_0_ rec { - dependencies = [ libc_0_2_34 ]; + hello = f: hello_0_1_0 { features = hello_0_1_0_features { hello_0_1_0 = f; }; }; + hello_0_1_0_ = { dependencies?[], buildDependencies?[], features?[] }: buildRustCrate { + crateName = "hello"; + version = "0.1.0"; + authors = [ "pe@pijul.org <pe@pijul.org>" ]; + src = ./.; + inherit dependencies buildDependencies features; + }; + libc_0_2_36_ = { dependencies?[], buildDependencies?[], features?[] }: buildRustCrate { + crateName = "libc"; + version = "0.2.36"; + authors = [ "The Rust Project Developers" ]; + sha256 = "01633h4yfqm0s302fm0dlba469bx8y6cs4nqc8bqrmjqxfxn515l"; + inherit dependencies buildDependencies features; }; - libc_0_2_34_features."default".from_hello_0_1_0__default = true; - libc_0_2_34 = libc_0_2_34_ rec { - features = mkFeatures libc_0_2_34_features; + hello_0_1_0 = { features?(hello_0_1_0_features {}) }: hello_0_1_0_ { + dependencies = mapFeatures features ([ libc_0_2_36 ]); }; - libc_0_2_34_features."use_std".self_default = hasDefault libc_0_2_34_features; + hello_0_1_0_features = f: updateFeatures f (rec { + hello_0_1_0.default = (f.hello_0_1_0.default or true); + libc_0_2_36.default = true; + }) [ libc_0_2_36_features ]; + libc_0_2_36 = { features?(libc_0_2_36_features {}) }: libc_0_2_36_ { + features = mkFeatures (features.libc_0_2_36 or {}); + }; + libc_0_2_36_features = f: updateFeatures f (rec { + libc_0_2_36.default = (f.libc_0_2_36.default or true); + libc_0_2_36.use_std = + (f.libc_0_2_36.use_std or false) || + (f.libc_0_2_36.default or false) || + (libc_0_2_36.default or false); + }) []; } ``` @@ -146,7 +162,7 @@ or build inputs by overriding the hello crate in a seperate file. ``` with import <nixpkgs> {}; -(import ./hello.nix).hello_0_1_0.override { +((import ./hello.nix).hello {}).override { crateOverrides = defaultCrateOverrides // { hello = attrs: { buildInputs = [ openssl ]; }; }; @@ -166,7 +182,7 @@ patches the derivation: ``` with import <nixpkgs> {}; -(import ./hello.nix).hello_0_1_0.override { +((import ./hello.nix).hello {}).override { crateOverrides = defaultCrateOverrides // { hello = attrs: lib.optionalAttrs (lib.versionAtLeast attrs.version "1.0") { postPatch = '' @@ -187,7 +203,7 @@ crate, we could do: ``` with import <nixpkgs> {}; -(import hello.nix).hello_0_1_0.override { +((import hello.nix).hello {}).override { crateOverrides = defaultCrateOverrides // { libc = attrs: { buildInputs = []; }; }; @@ -199,23 +215,35 @@ Three more parameters can be overridden: - The version of rustc used to compile the crate: ``` - hello_0_1_0.override { rust = pkgs.rust; }; + (hello {}).override { rust = pkgs.rust; }; ``` - Whether to build in release mode or debug mode (release mode by default): ``` - hello_0_1_0.override { release = false; }; + (hello {}).override { release = false; }; ``` - Whether to print the commands sent to rustc when building (equivalent to `--verbose` in cargo: ``` - hello_0_1_0.override { verbose = false; }; + (hello {}).override { verbose = false; }; ``` +One can also supply features switches. For example, if we want to +compile `diesel_cli` only with the `postgres` feature, and no default +features, we would write: + +``` +(callPackage ./diesel.nix {}).diesel { + default = false; + postgres = true; +} +``` + + ## Using the Rust nightlies overlay |