getting mize to build as a module

This commit is contained in:
Sebastian Moser
2025-05-04 12:55:01 +02:00
parent 45a911ee78
commit 5bf94e9bcb
3 changed files with 28 additions and 9 deletions

4
Cargo.lock generated
View File

@@ -1,6 +1,6 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
version = 4
[[package]]
name = "addr2line"
@@ -1133,7 +1133,7 @@ dependencies = [
[[package]]
name = "mize"
version = "0.0.0"
version = "0.0.1"
dependencies = [
"axum",
"axum-extra",

View File

@@ -75,7 +75,7 @@ rec {
buildMizeForSystem = system: let
hostSystem = getCrossSystem system;
pkgsCross = import nixpkgs { inherit buildSystem hostSystem; overlays = [ rust-overlay.overlays.default ]; };
pkgsCross = import nixpkgs { inherit buildSystem hostSystem; localSystem = buildSystem; overlays = [ rust-overlay.overlays.default ]; };
pkgsNative = import nixpkgs { inherit buildSystem; overlays = [ rust-overlay.overlays.default ]; };
@@ -161,11 +161,12 @@ rec {
cp $build_dir/target/${hostSystem.nameRust}/$debugOrRelease/libmize_module_${attrs.modName}.so $out/lib/
'';
mizeBuildPhase = attrs.mizeBuildPhase or ''
cargo --color always build --target ${hostSystem.nameRust} --manifest-path $build_dir/Cargo.toml --lib
cargo --color always build --target ${hostSystem.nameRust} ${if builtins.hasAttr "cargoExtraArgs" attrs then attrs.cargoExtraArgs else ""} --manifest-path $build_dir/Cargo.toml --lib
'';
selector_string = mkSelString (attrs.select or {} // {
inherit (attrs) modName;
});
devShell = if builtins.hasAttr "devShell" attrs then attrs.devShell else mkMizeRustShell {};
}

View File

@@ -1,6 +1,6 @@
{
module = { mkMizeRustModule, hostSystem, pkgsCross, pkgs, lib, craneLib, ... }:
module = { mkMizeRustModule, mkMizeRustShell, hostSystem, pkgsCross, pkgs, lib, craneLib, ... }:
mkMizeRustModule (
@@ -18,6 +18,10 @@ module = { mkMizeRustModule, hostSystem, pkgsCross, pkgs, lib, craneLib, ... }:
// (lib.attrsets.optionalAttrs (hostSystem.kernel.name == "linux") {
strictDeps = true;
cargoExtraArgs = "--bin mize --features os-target";
mizeInstallPhase = ''
mkdir -p $out
cp $build_dir/target/${hostSystem.nameRust}/$debugOrRelease/mize $out/
'';
})
@@ -25,7 +29,7 @@ module = { mkMizeRustModule, hostSystem, pkgsCross, pkgs, lib, craneLib, ... }:
# x86_64-linux stuff
// (lib.attrsets.optionalAttrs (hostSystem.name == "x86_64-linux-gnu") {
// (lib.attrsets.optionalAttrs (hostSystem.name == "x86_64-linux-gnu") rec {
nativeBuildInputs = [
@@ -35,9 +39,13 @@ module = { mkMizeRustModule, hostSystem, pkgsCross, pkgs, lib, craneLib, ... }:
buildInputs = [
(if hostSystem.nameFull == "x86_64-unknown-linux-gnu" then pkgs.openssl else pkgsCross.openssl)
pkgs.openssl
];
devShell = mkMizeRustShell {
inherit buildInputs nativeBuildInputs;
};
# patch the interpreter to run on most linux-gnu distros
# postBuild = "patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 /build/source/target/release/mize";
@@ -80,7 +88,7 @@ module = { mkMizeRustModule, hostSystem, pkgsCross, pkgs, lib, craneLib, ... }:
#browser stuff
// (lib.attrsets.optionalAttrs (hostSystem.name == "wasm32-none-unknown") {
// (lib.attrsets.optionalAttrs (hostSystem.name == "wasm32-none-unknown") rec {
cargoArtifacts = craneLib.buildDepsOnly ({
src = ./.;
@@ -91,6 +99,12 @@ module = { mkMizeRustModule, hostSystem, pkgsCross, pkgs, lib, craneLib, ... }:
buildInputs = with pkgs; [ cargo-binutils lld ];
});
mizeBuildPhase = ''
cd $build_dir
RUST_LOG=off wasm-pack build --target no-modules --dev --out-dir $out -- --features wasm-target --no-default-features
'';
mizeInstallPhase = "";
doInstallCargoArtifacts = false;
doCheck = false;
@@ -107,7 +121,11 @@ module = { mkMizeRustModule, hostSystem, pkgsCross, pkgs, lib, craneLib, ... }:
cat $src/src/platform/wasm/init.js >> $out/pkg/mize.js
'';
buildInputs = with pkgs; [ wasm-bindgen-cli binaryen wasm-pack ];
nativeBuildInputs = with pkgs; [ wasm-bindgen-cli binaryen wasm-pack ];
devShell = mkMizeRustShell {
inherit nativeBuildInputs;
};
})