73 lines
1.7 KiB
Nix
73 lines
1.7 KiB
Nix
{
|
|
lib
|
|
, stdenv
|
|
, mkShell
|
|
|
|
, llvmPackages
|
|
|
|
, rust-channel ? "stable"
|
|
, rust-bin
|
|
, rust-toolchain ? rust-bin.${rust-channel}.latest.default.override {
|
|
extensions = [ "rust-src" "rust-analyzer" "rust-std" ];
|
|
}
|
|
|
|
, enableSccache ? true
|
|
, pkgsBuildBuild
|
|
|
|
# Rust tools
|
|
, cargo-deny
|
|
, cargo-insta
|
|
, cargo-nextest
|
|
|
|
# Commonly used libraries
|
|
, pkg-config
|
|
, openssl
|
|
, zstd
|
|
, systemdLibs
|
|
}:
|
|
mkShell {
|
|
packages = [
|
|
rust-toolchain
|
|
|
|
cargo-deny
|
|
cargo-insta
|
|
cargo-nextest
|
|
|
|
pkg-config
|
|
];
|
|
|
|
buildInputs = [
|
|
openssl
|
|
zstd
|
|
systemdLibs
|
|
];
|
|
|
|
env = {
|
|
RUST_SRC_PATH = "${rust-toolchain}/lib/rustlib/src/rust/library";
|
|
LIBCLANG_PATH = "${llvmPackages.libclang}/lib";
|
|
} // (lib.optionalAttrs (enableSccache) {
|
|
RUSTC_WRAPPER = "${pkgsBuildBuild.sccache}/bin/sccache";
|
|
});
|
|
|
|
# https://hoverbear.org/blog/rust-bindgen-in-nix/
|
|
shellHook = let
|
|
clangArgs = lib.concatStringsSep " " [
|
|
"-idirafter ${stdenv.cc.cc}/lib/clang/${lib.getVersion stdenv.cc.cc}/include"
|
|
];
|
|
gccArgs = lib.concatStringsSep " " [
|
|
"-isystem ${stdenv.cc.cc}/include/c++/${lib.getVersion stdenv.cc.cc}"
|
|
"-isystem ${stdenv.cc.cc}/include/c++/${lib.getVersion stdenv.cc.cc}/${stdenv.hostPlatform.config}"
|
|
"-idirafter ${stdenv.cc.cc}/lib/gcc/${stdenv.hostPlatform.config}/${lib.getVersion stdenv.cc.cc}/include"
|
|
];
|
|
in ''
|
|
export BINDGEN_EXTRA_CLANG_ARGS="${lib.concatStringsSep " " [
|
|
"$(< ${stdenv.cc}/nix-support/libc-crt1-cflags)"
|
|
"$(< ${stdenv.cc}/nix-support/libc-cflags)"
|
|
"$(< ${stdenv.cc}/nix-support/cc-cflags)"
|
|
"$(< ${stdenv.cc}/nix-support/libcxx-cxxflags)"
|
|
"${lib.optionalString stdenv.cc.isClang clangArgs}"
|
|
"${lib.optionalString stdenv.cc.isGNU gccArgs}"
|
|
]}"
|
|
'';
|
|
}
|