Last active
April 3, 2019 02:19
-
-
Save dhl/207acff034a280af446a26ccd2a8b33a to your computer and use it in GitHub Desktop.
Compiling rust against musl target with Nix. Adapted from https://github.com/mozilla/nixpkgs-mozilla/issues/91#issuecomment-464483970
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgsPath ? <nixpkgs>, crossSystem ? null }: | |
let | |
mozOverlay = import ( | |
builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz | |
); | |
pkgs = import pkgsPath { | |
overlays = [ mozOverlay ]; | |
inherit crossSystem; | |
}; | |
targets = [ pkgs.stdenv.targetPlatform.config ]; | |
my_openssl = pkgs.openssl_1_1 or pkgs.openssl_1_1_0; | |
in | |
with pkgs; | |
stdenv.mkDerivation { | |
name = "lambda-rust"; | |
# build time dependencies targeting the build platform | |
depsBuildBuild = [ | |
buildPackages.stdenv.cc | |
]; | |
HOST_CC = "cc"; | |
# build time dependencies targeting the host platform | |
nativeBuildInputs = [ | |
(buildPackages.buildPackages.latest.rustChannels.stable.rust.override { inherit targets; }) | |
buildPackages.buildPackages.rustfmt | |
]; | |
shellHook = '' | |
export RUSTFLAGS="-C linker=$CC" | |
''; | |
CARGO_BUILD_TARGET = targets; | |
# run time dependencies | |
OPENSSL_DIR = my_openssl.dev; | |
OPENSSL_LIB_DIR = "${my_openssl.out}/lib"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ./default.nix { | |
crossSystem = (import <nixpkgs> {}).lib.systems.examples.musl64; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment