aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md11
-rw-r--r--buildRustCrateHelpers.nix18
-rw-r--r--default.nix19
-rw-r--r--hello/Cargo.lock4
-rw-r--r--hello/Cargo.nix26
-rw-r--r--hello/Cargo.toml6
-rw-r--r--hello/crates-io.nix8
-rw-r--r--hello/src/main.rs3
8 files changed, 95 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..3ab75e2
--- /dev/null
+++ b/README.md
@@ -0,0 +1,11 @@
+Test repo to figure out cross compilation with carnix
+
+AFAICT individual packages are largely agnostic wrt. what they're being compiled for.
+nixpkgs-unstable has neat support for cross compilation without fancy flags:
+
+```
+ file $(nix-build --no-out-link '<nixpkgs>' -A pkgsCross.aarch64-multiplatform.hello)/bin/hello
+ /nix/store/6924zrj4fww7xs7qzxfidj5n7id6qngi-hello-2.10-aarch64-unknown-linux-gnu/bin/hello: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /nix/store/rcj93w6gk9l6w9jgmqx911iycs2ya9rg-glibc-2.27-aarch64-unknown-linux-gnu/lib/ld-linux-aarch64.so.1, for GNU/Linux 2.6.32, not stripped
+```
+
+There *is* a pkgsCross.musl64, but it seems to link musl dynamically, not sure what's up with that.
diff --git a/buildRustCrateHelpers.nix b/buildRustCrateHelpers.nix
new file mode 100644
index 0000000..3fdcb66
--- /dev/null
+++ b/buildRustCrateHelpers.nix
@@ -0,0 +1,18 @@
+{ lib, buildPlatform }: {
+ kernel = buildPlatform.parsed.kernel.name;
+ abi = buildPlatform.parsed.abi.name;
+ include = includedFiles: src: builtins.filterSource (path: type:
+ lib.lists.any (f:
+ let p = toString (src + ("/" + f)); in
+ (path == p) || (type == "directory" && lib.strings.hasPrefix path p)
+ ) includedFiles
+ ) src;
+ updateFeatures = f: up: functions: builtins.deepSeq f (lib.lists.foldl' (features: fun: fun features) (lib.attrsets.recursiveUpdate f up) functions);
+ mapFeatures = features: map (fun: fun { features = features; });
+ mkFeatures = feat: lib.lists.foldl (features: featureName:
+ if feat.${featureName} or false then
+ [ featureName ] ++ features
+ else
+ features
+ ) [] (builtins.attrNames feat);
+}
diff --git a/default.nix b/default.nix
new file mode 100644
index 0000000..76c11cf
--- /dev/null
+++ b/default.nix
@@ -0,0 +1,19 @@
+let
+ overlay = self: super: rec {
+ buildRustCrateHelpers = self.callPackage ./buildRustCrateHelpers.nix {};
+
+ carnix-cross-test = self.callPackage hello/Cargo.nix {
+ cratesIO = self.callPackage hello/crates-io.nix { };
+ };
+
+ rustHello = carnix-cross-test.hello {};
+ };
+
+ nixpkgs = import (builtins.fetchTarball https://nixos.org/channels/nixos-unstable/nixexprs.tar.xz) {
+ overlays = [ overlay ];
+ };
+in {
+ inherit (nixpkgs.pkgsCross.aarch64-multiplatform)
+ hello
+ rustHello;
+}
diff --git a/hello/Cargo.lock b/hello/Cargo.lock
new file mode 100644
index 0000000..15b9446
--- /dev/null
+++ b/hello/Cargo.lock
@@ -0,0 +1,4 @@
+[[package]]
+name = "hello"
+version = "0.1.0"
+
diff --git a/hello/Cargo.nix b/hello/Cargo.nix
new file mode 100644
index 0000000..4db6737
--- /dev/null
+++ b/hello/Cargo.nix
@@ -0,0 +1,26 @@
+# Generated by carnix 0.8.5: /home/till/.cargo/bin/carnix nix --src ./.
+{ lib, buildPlatform, buildRustCrate, buildRustCrateHelpers, cratesIO, fetchgit }:
+with buildRustCrateHelpers;
+let inherit (lib.lists) fold;
+ inherit (lib.attrsets) recursiveUpdate;
+in
+let crates = cratesIO // rec {
+ crates.hello."0.1.0" = deps: { features?(features_.hello."0.1.0" deps {}) }: buildRustCrate {
+ crateName = "hello";
+ version = "0.1.0";
+ authors = [ "till" ];
+ src = ./.;
+ };
+ features_.hello."0.1.0" = deps: f: updateFeatures f (rec {
+ hello."0.1.0".default = (f.hello."0.1.0".default or true);
+ }) [];
+
+
+
+}; in
+
+rec {
+ hello = crates.crates.hello."0.1.0" deps;
+ __all = [ (hello {}) ];
+ deps.hello."0.1.0" = {};
+}
diff --git a/hello/Cargo.toml b/hello/Cargo.toml
new file mode 100644
index 0000000..e968470
--- /dev/null
+++ b/hello/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "hello"
+version = "0.1.0"
+authors = ["till"]
+
+[dependencies]
diff --git a/hello/crates-io.nix b/hello/crates-io.nix
new file mode 100644
index 0000000..7a0e584
--- /dev/null
+++ b/hello/crates-io.nix
@@ -0,0 +1,8 @@
+{ lib, buildRustCrate, buildRustCrateHelpers }:
+with buildRustCrateHelpers;
+let inherit (lib.lists) fold;
+ inherit (lib.attrsets) recursiveUpdate;
+in
+rec {
+
+}
diff --git a/hello/src/main.rs b/hello/src/main.rs
new file mode 100644
index 0000000..e7a11a9
--- /dev/null
+++ b/hello/src/main.rs
@@ -0,0 +1,3 @@
+fn main() {
+ println!("Hello, world!");
+}