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