Rust: Difference between revisions
Console4852 (talk | contribs) Remove Rust Nightlies section. This section had no information that wasn't found on the rest of the page (only having two bullet points referring to other sections of the page). Instead, modify the page to elaborate more in the respective sections. |
add bindgen example |
||
| Line 21: | Line 21: | ||
in pkgs.mkShell { | in pkgs.mkShell { | ||
buildInputs = [ pkgs.cargo pkgs.rustc ]; | buildInputs = [ pkgs.cargo pkgs.rustc ]; | ||
} | |||
</syntaxHighlight> | |||
== Installating with bindgen support == | |||
By default crates using <code>bindgen</code> will not compile. To add bindegen support add the <code>rustPlatform.bindegenHook</code> to your <code>nativeBuildInputs</code>. | |||
Here's an example <code>shell.nix</code>: | |||
<syntaxHighlight lang="nix"> | |||
{ pkgs ? import <nixpkgs> {} }: | |||
pkgs.mkShell { | |||
nativeBuildInputs = [ | |||
pkgs.cargo | |||
pkgs.rustc | |||
pkgs.rustPlatform.bindgenHook | |||
# optional: add pkg-config support | |||
pkgs.pkg-config | |||
]; | |||
buildInputs = [ | |||
# add desired native packages | |||
# ... | |||
]; | |||
} | |||
</syntaxHighlight> | |||
This also works, when compiling rust crates: | |||
<syntaxHighlight lang="nix"> | |||
{ | |||
rustPlatform, | |||
pkg-config, | |||
... | |||
}: | |||
rustPlatform.buildRustPackage { | |||
# ... | |||
nativeBuildInputs = [ | |||
rustPlatform.bindgenHook | |||
pkg-config | |||
]; | |||
buildInputs = [ | |||
# add desired native packages | |||
# ... | |||
]; | |||
} | } | ||
</syntaxHighlight> | </syntaxHighlight> | ||