Rust: Difference between revisions
imported>Wackbyte m lang=nix -> lang="nix" |
imported>Wackbyte m fix broken/unsupported/missing syntax highlighting |
||
Line 98: | Line 98: | ||
It's important to have a file named <code>rust-toolchain</code> lying in the same directory as the shell.nix. | It's important to have a file named <code>rust-toolchain</code> lying in the same directory as the shell.nix. | ||
It's purpose is to pin the version of the used rust compiler. | It's purpose is to pin the version of the used rust compiler. | ||
<syntaxHighlight lang=" | <syntaxHighlight lang="shell-session"> | ||
$ cat rust-toolchain | $ cat rust-toolchain | ||
nightly-2021-09-19 | nightly-2021-09-19 | ||
Line 232: | Line 232: | ||
=== Building Rust crates that require external system libraries === | === Building Rust crates that require external system libraries === | ||
For example, the <code>openssl-sys</code> crate needs the OpenSSL static libraries and searches for the library path with <code>pkg-config</code>. That's why you need to have the Nix derivatives <code>openssl</code> and <code>pkg-config</code> in order to build that crate. You'll need to start a shell providing these packages: | For example, the <code>openssl-sys</code> crate needs the OpenSSL static libraries and searches for the library path with <code>pkg-config</code>. That's why you need to have the Nix derivatives <code>openssl</code> and <code>pkg-config</code> in order to build that crate. You'll need to start a shell providing these packages: | ||
<syntaxHighlight lang= | <syntaxHighlight lang="shell-session"> | ||
$ nix-shell -p pkg-config openssl | $ nix-shell -p pkg-config openssl | ||
</syntaxHighlight> | </syntaxHighlight> | ||
In some cases (eg [https://discourse.nixos.org/t/rust-openssl-woes/12340 here]) you may also need | In some cases (eg [https://discourse.nixos.org/t/rust-openssl-woes/12340 here]) you may also need | ||
<syntaxHighlight> | <syntaxHighlight lang="nix"> | ||
PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig"; | PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig"; | ||
</syntaxHighlight> | </syntaxHighlight> | ||
Similarly, the crate <code>libsqlite3-sys</code>, e.g. to use and compile the database ORM tool <code>diesel-cli</code> with Sqlite support, needs | Similarly, the crate <code>libsqlite3-sys</code>, e.g. to use and compile the database ORM tool <code>diesel-cli</code> with Sqlite support, needs | ||
<syntaxHighlight lang= | <syntaxHighlight lang="shell-session"> | ||
$ nix-shell -p pkg-config sqlite | $ nix-shell -p pkg-config sqlite | ||
</syntaxHighlight> | </syntaxHighlight> | ||
Otherwise the following error occurs: | Otherwise the following error occurs: | ||
<syntaxHighlight lang= | <syntaxHighlight lang="shell-session"> | ||
error: linking with `cc` failed: exit status: 1 | error: linking with `cc` failed: exit status: 1 | ||
... | ... |