Fix cross-compilation

This commit is contained in:
Brian Picciano 2023-11-09 23:52:07 +01:00
parent ab2e5fb55a
commit dce01bd31b

View File

@ -29,7 +29,7 @@
supportedSystems
);
mkPkgs = buildSystem: hostSystem: import nixpkgs {
mkPkgs = buildSystem: hostSystem: import nixpkgs ({
system = buildSystem;
overlays = [
(import rust-overlay)
@ -44,42 +44,49 @@
# only set up the cross-compiling config if the target platform is
# different.
crossSystem.config = hostSystem;
});
}));
mkRustEnv = pkgs: {
mkRustEnv = crossPkgs: hostSystem: {
OPENSSL_STATIC = "1";
OPENSSL_LIB_DIR = "${pkgs.pkgsStatic.openssl.out}/lib";
OPENSSL_INCLUDE_DIR = "${pkgs.pkgsStatic.openssl.dev}/include";
CARGO_BUILD_TARGET = buildTargetsBySystem.${pkgs.stdenv.hostPlatform.system};
CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static";
OPENSSL_LIB_DIR = "${crossPkgs.pkgsStatic.openssl.out}/lib";
OPENSSL_INCLUDE_DIR = "${crossPkgs.pkgsStatic.openssl.dev}/include";
CARGO_BUILD_TARGET = buildTargetsBySystem.${hostSystem};
CARGO_BUILD_RUSTFLAGS = [
"-C" "target-feature=+crt-static"
"-C" "linker=${crossPkgs.stdenv.cc}/bin/${crossPkgs.stdenv.cc.targetPrefix}cc"
"-C" "link-arg=-static"
];
};
in
{
packages = eachCrossSystem (buildSystem: hostSystem: let
pkgs = mkPkgs buildSystem hostSystem;
pkgs = mkPkgs buildSystem buildSystem;
crossPkgs = mkPkgs buildSystem hostSystem;
naersk-lib = pkgs.callPackage naersk {
cargo = pkgs.rust-toolchain;
rustc = pkgs.rust-toolchain;
};
rustEnv = mkRustEnv pkgs;
rustEnv = mkRustEnv crossPkgs hostSystem;
in
naersk-lib.buildPackage ({
src = ./.;
doCheck = false;
nativeBuildInputs = [ pkgs.pkgsStatic.stdenv.cc ];
nativeBuildInputs = [ crossPkgs.pkgsStatic.stdenv.cc ];
} // rustEnv)
);
devShells = eachCrossSystem (buildSystem: hostSystem: let
pkgs = mkPkgs buildSystem hostSystem;
rustEnv = mkRustEnv pkgs;
pkgs = mkPkgs buildSystem buildSystem;
crossPkgs = mkPkgs buildSystem hostSystem;
rustEnv = mkRustEnv crossPkgs hostSystem;
in
pkgs.mkShell ({
nativeBuildInputs = [
pkgs.stdenv.cc
pkgs.openssl
pkgs.rust-toolchain
crossPkgs.stdenv.cc
crossPkgs.openssl
pkgs.nmap # ncat
pkgs.rust-toolchain
];
shellHook = ''
export CARGO_HOME=$(pwd)/.cargo