Rust: Difference between revisions
imported>Jraygauthier New cross-comiling section with ref to a scafolding project targeting windows via rustup |
imported>Malteneuss m Add another external library example with sqlite for database tool diesel, and refer to other FAQ page why it has to be a nix-shell environment |
||
Line 228: | Line 228: | ||
== FAQ == | == FAQ == | ||
=== Building | === 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: | |||
<syntaxHighlight lang=console> | <syntaxHighlight lang=console> | ||
$ nix-shell -p pkg-config openssl | $ nix-shell -p pkg-config openssl | ||
Line 237: | Line 237: | ||
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 | |||
<syntaxHighlight lang=console> | |||
$ nix-shell -p pkg-config sqlite | |||
</syntaxHighlight> | |||
Otherwise the following error occurs: | |||
<syntaxHighlight lang=console> | |||
error: linking with `cc` failed: exit status: 1 | |||
... | |||
= note: /nix/store/kmqs0wll31ylwbqkpmlgbjrn6ny3myik-binutils-2.35.1/bin/ld: cannot find -lsqlite3 | |||
collect2: error: ld returned 1 exit status | |||
</syntaxHighlight> | |||
Note that you need to use a <code>nix-shell</code> environment. Installing the Nix packages <code>openssl</code> or <code>sqlite</code> globally under <code>systemPackages</code> in NixOS or in <code>nix-env</code> [https://nixos.wiki/wiki/FAQ/I_installed_a_library_but_my_compiler_is_not_finding_it._Why%3F is discouraged] and doesn't always work (<code>pkg-config</code> may not be able to locate the libraries). |