From cb8e992f27cd9d8bc17ed9fab4d72a268dae7c7c Mon Sep 17 00:00:00 2001 From: Philippe Loctaux
Date: Wed, 20 Nov 2024 23:40:29 +0100
Subject: [PATCH] flake: cross building on arm64 from x86_64, need to cleanup
and improve
---
flake.nix | 106 +++++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 93 insertions(+), 13 deletions(-)
diff --git a/flake.nix b/flake.nix
index f1999c3..c6edf60 100644
--- a/flake.nix
+++ b/flake.nix
@@ -21,17 +21,19 @@
...
}:
flake-utils.lib.eachDefaultSystem (
- system:
+ localSystem:
let
+ crossSystem = "aarch64-linux";
pkgs = import nixpkgs {
- inherit system;
+ inherit crossSystem localSystem;
overlays = [ (import rust-overlay) ];
};
inherit (pkgs) lib;
tailwindStylesheet = import ./crates/plcom/tailwind.nix {
- pkgs = import nixpkgs { inherit system; };
+ stdenvNoCC = pkgs.stdenvNoCC;
+ tailwindcss = pkgs.tailwindcss;
src = ./crates/plcom;
inputFile = "css/main.css";
};
@@ -52,12 +54,92 @@
'';
};
- # in
- craneLib = crane.mkLib pkgs;
+ craneLib = (crane.mkLib pkgs).overrideToolchain (p: p.rust-bin.stable.latest.default);
# Get metadata from Cargo.toml
metadata = craneLib.crateNameFromCargoToml { cargoToml = ./crates/plcom/Cargo.toml; };
+ # TODO: move to its own module
+ crateExpression =
+ {
+ openssl,
+ libiconv,
+ lib,
+ pkg-config,
+ qemu,
+ stdenv,
+ }:
+ craneLib.buildPackage (
+ metadata
+ // {
+ src = lib.cleanSourceWith {
+ src = craneLib.path ./.; # The original, unfiltered source
+ filter =
+ path: type:
+ # Assets for codegen
+ (lib.hasSuffix ".json" path)
+ ||
+ # Default filter from crane (allow .rs files)
+ (craneLib.filterCargoSources path type);
+ };
+ cargoExtraArgs = "-p plcom";
+ strictDeps = true;
+
+ # Build-time tools which are target agnostic. build = host = target = your-machine.
+ # Emulators should essentially also go `nativeBuildInputs`. But with some packaging issue,
+ # currently it would cause some rebuild.
+ # We put them here just for a workaround.
+ # See: https://github.com/NixOS/nixpkgs/pull/146583
+ depsBuildBuild = [
+ qemu
+ ];
+
+ # Dependencies which need to be build for the current platform
+ # on which we are doing the cross compilation. In this case,
+ # pkg-config needs to run on the build platform so that the build
+ # script can find the location of openssl. Note that we don't
+ # need to specify the rustToolchain here since it was already
+ # overridden above.
+ nativeBuildInputs =
+ [
+ pkg-config
+ stdenv.cc
+ ]
+ ++ lib.optionals stdenv.buildPlatform.isDarwin [
+ libiconv
+ ];
+
+ # Dependencies which need to be built for the platform on which
+ # the binary will run. In this case, we need to compile openssl
+ # so that it can be linked with our executable.
+ buildInputs = [
+ # Add additional build inputs here
+ openssl
+ ];
+
+ # Tell cargo about the linker and an optional emulater. So they can be used in `cargo build`
+ # and `cargo run`.
+ # Environment variables are in format `CARGO_TARGET_