-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use rust overlay with additional targets? #91
Comments
@flosse use rust = (pkgs.latest.rustChannels.nightly.rust.override {
targets = [ "x86_64-unknown-linux-musl" ];
}); i didn't test this, but it should give you a hint, how to read rust-overlay.nix. please reopen the issue if above solution doesn't solve your problem. |
it seems that the overlay was not applied? |
Ok now I can build it. nixpkgs.config.overlays = [rustOverlay]; it has to be nixpkgs.overlays = [rustOverlay]; But running a
|
@flosse Can you compile the default hello world program that comes with |
yes, that is working :) I try to compile openfairdb which depends also on So I tried this:
|
I noticed that same issue with |
|
I tried several things but still without success :( |
Here are the detailed steps to reproduce:
I used the following let
moz_overlay = import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz);
pkgs = import <nixpkgs> { overlays = [ moz_overlay ]; };
channel = pkgs.rustChannelOf {
date = "2018-05-29";
channel = "nightly";
};
rust = (channel.rust.override {
targets = [ "x86_64-unknown-linux-musl" ];
});
in
with pkgs;
stdenv.mkDerivation {
name = "rust-ofdb-dev-env";
buildInputs = [
rust
musl
musl.dev
sqlite
sqlite.dev
cmake
pkgconfig
];
SQLITE3_DIR = "${sqlite.dev}";
SQLITE3_LIB_DIR = "${sqlite.out}/lib";
SQLITE3_INCLUDE_LIB_DIR = "${sqlite.out}/include";
} |
You can do this now by using |
Could someone explain how to use this overlay to compile WASM from Rust in NixOS in simple steps? $ nix-shell -p rustChannels.stable.cargo rustChannels.stable.rustc
$ RUSTFLAGS="" cargo build --target wasm32-unknown-unknown
Compiling wasm-bindgen v0.2.29
error[E0463]: can't find crate for `core`
|
= note: the `wasm32-unknown-unknown` target may not be installed
error: aborting due to previous error
For more information about this error, try `rustc --explain E0463`.
error: Could not compile `wasm-bindgen`.
To learn more, run the command again with --verbose. |
I'm getting a similar error while attempting to compile with musl target: default.nix let
moz_overlay = import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz);
nixpkgs = import <nixpkgs> { overlays = [ moz_overlay ]; };
stableRust = nixpkgs.latest.rustChannels.stable.rust.override {
targets = [ "x86_64-unknown-linux-gnu" "x86_64-unknown-linux-musl" ];
};
stableCargo = nixpkgs.latest.rustChannels.stable.cargo;
buildRustPackage = nixpkgs.callPackage (import <nixpkgs/pkgs/build-support/rust>) {
rust = {
rustc = stableRust;
cargo = stableCargo;
};
};
derivation = { stdenv, rustPlatform, buildRustPackage, llvmPackages_39, rust-bindgen, ... }:
buildRustPackage rec {
name = "foo-package";
version = "0.1.0";
src = ./.;
libclang = llvmPackages_39.libclang.lib;
clang = llvmPackages_39.clang;
buildInputs = [ libclang rust-bindgen ];
propagatedBuildInputs = [ clang ];
configurePhase = ''
export LIBCLANG_PATH=${libclang}/lib
'';
cargoSha256 = "0cwc4m5wfaf5nn4gz4pvfhbc816xv0v9w6vy8y190xjllyv3rr70";
meta = with stdenv.lib; {
description = "foo-package";
license = licenses.mpl20;
maintainers = with maintainers; [ tdbgamer ];
};
shellHook = ''
export LIBCLANG_PATH=${libclang}/lib
'';
};
in
nixpkgs.callPackage derivation {
inherit buildRustPackage;
rust = stableRust;
cargo = stableCargo;
} The output:
|
I got cross compilation to work in a nix-shell using the following configuration: default.nix: { 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 = "castle";
# 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.nightly.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";
} aarch64.nix: import ./default.nix {
crossSystem = (import <nixpkgs> {}).lib.systems.examples.aarch64-multiplatform;
} For normal compilation execute: nix-shell
cargo build For cross-compilation to aarch64 execute: nix-shell aarch64.nix
cargo build |
This does not work for me :(
|
Weird, compiling to musl64 works for me (using |
@haslersn It compiles but for me it doesn't make a static binary (with openssl depends).
I tried OPENSSL_STATIC=1; but I have this error with
Thank you again for your feedback. |
It works with this example
|
@apeyroux can you build a static rust package using |
In my
/etc/nixos/configuration.nix
I triedBut I get this error:
attribute 'latest' missing, at /etc/nixos/configuration.nix:14:11
Where is my fault?
The text was updated successfully, but these errors were encountered: