Building packages with llvmPackages.stdenv
#913
-
|
What is the right way to modify |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 8 replies
-
|
I thought using |
Beta Was this translation helpful? Give feedback.
-
|
I don't know if this can be done at a "higher" level, but Lines 1229 to 1232 in 1979a25 stdenv as an arg to mkCargoDerivation (note that it's a function!), and buildDepsOnly/buildPackage simply pass their args down to mkCargoDerivation:
Lines 38 to 39 in 1979a25 Lines 52 to 53 in 1979a25 For Lines 971 to 983 in 1979a25 |
Beta Was this translation helpful? Give feedback.
-
|
The intended way is to do something like: let
commonArgs = {
...
stdenv = p: p.clangStdenv;
....
};
in
craneLib.buildPackage (commonArgs // {
...
})You can also instance craneLib with pkgsLLVM: cranelib = crane.mkLin pkgs.pkgsLLVM;Then everything will be LLVM-based. |
Beta Was this translation helpful? Give feedback.
-
|
Here's an MVCE that shows the issue when trying to use {
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
crane.url = "github:ipetkov/crane";
flake-utils.url = "github:numtide/flake-utils";
};
outputs =
{
self,
nixpkgs,
crane,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs { inherit system; };
craneLib = crane.mkLib pkgs;
cargoToml = pkgs.writeText "Cargo.toml" ''
[package]
name = "hello-world"
version = "0.1.0"
edition = "2024"
[dependencies]
rocksdb = { version = "0.24", default-features = false, features = [ "bindgen-runtime", "zstd", "lto" ] }
tempfile = "3"
'';
cargoLock = pkgs.fetchurl {
url = "https://gist.githubusercontent.com/lovesegfault/6acc6ece622ec63127bc100c76d51d2f/raw/cefaf30fb69c9f83c55313ead96590cf820d6184/Cargo.lock";
hash = "sha256-Cn9brESnCOgOyt5EK2miJ/LgqAp7rII4d47m63j84fw=";
};
mainRs = pkgs.writeText "main.rs" ''
fn main() -> Result<(), Box<dyn std::error::Error>> {
let tempdir = tempfile::Builder::new().tempdir()?;
let db = rocksdb::DB::open_default(tempdir.path())?;
db.put(b"my key", b"my value")?;
std::mem::drop(db);
let _ = rocksdb::DB::destroy(&rocksdb::Options::default(), tempdir.path());
Ok(())
}
'';
src = pkgs.runCommand "rust-src" { } ''
echo $out
mkdir -p $out/src
cp ${cargoToml} "$out/Cargo.toml"
cp ${cargoLock} "$out/Cargo.lock"
cp ${mainRs} "$out/src/main.rs"
'';
in
{
packages.default = craneLib.buildPackage {
pname = "hello-world";
version = "0.0.1";
src = src;
strictDeps = true;
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
};
}
);
}This is why I'm trying to use the LLVM stdenv, for context. |
Beta Was this translation helpful? Give feedback.
Oh, I see. I would recommend reading the rocks-db documentation that talks about the LTO feature:
https://github.com/rust-rocksdb/rust-rocksdb/blob/d6171b7ac13df012c250cebca26294f4f76cd52e/README.md#lto
So I gave this patch a try and it built fine: