packaging stuff
This commit is contained in:
@@ -93,3 +93,4 @@ wasm-bindgen-test = { version = "0.3.34" }
|
||||
[profile.release]
|
||||
# Tell `rustc` to optimize for small code size.
|
||||
opt-level = "s"
|
||||
|
||||
|
||||
@@ -55,6 +55,9 @@ let
|
||||
src = self;
|
||||
doCheck = false; # tests does not work in wasm
|
||||
CARGO_BUILD_TARGET = "wasm32-unknown-unknown";
|
||||
cargoExtraArgs = "--features wasm-target --no-default-features";
|
||||
RUSTFLAGS="-C linker=wasm-ld";
|
||||
buildInputs = with pkgs; [ cargo-binutils lld ];
|
||||
});
|
||||
|
||||
defaultMizeConfig = {
|
||||
@@ -124,6 +127,7 @@ in {
|
||||
cargoExtraArgs = "--bin mize --features wasm-target";
|
||||
doCheck = false;
|
||||
};
|
||||
inherit wasmArtifacts;
|
||||
|
||||
# Thanks to:
|
||||
# - https://github.com/dl-solarity/hardhat-diamond-tools/blob/e5b8bc9624fbf89eda83a8ce4f6b6672ea83f550/flake.nix#L103
|
||||
@@ -144,7 +148,8 @@ in {
|
||||
echo build hiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
|
||||
mkdir -p $out/pkg
|
||||
|
||||
HOME=$(mktemp -d fake-homeXXXX) wasm-pack build --out-dir $out/pkg --scope=c2vi -- --no-default-features --features wasm-target
|
||||
export HOME=$(mktemp -d fake-homeXXXX)
|
||||
wasm-pack build --out-dir $out/pkg --scope=c2vi -- --no-default-features --features wasm-target
|
||||
'';
|
||||
|
||||
buildInputs = with pkgs; [ wasm-bindgen-cli binaryen wasm-pack wasmToolchain ];
|
||||
|
||||
49
lib.nix
49
lib.nix
@@ -129,19 +129,20 @@ rec {
|
||||
|
||||
toolchain_version = pkgs.lib.strings.removeSuffix "\n" (builtins.readFile "${toolchain_version_drv}/rustc-version");
|
||||
|
||||
mkMizeModule = attrs: pkgsCross.stdenv.mkDerivation ({
|
||||
mkMizeModule = attrs: pkgsCross.stdenv.mkDerivation ( rec {
|
||||
name = attrs.modName;
|
||||
inherit (attrs) modName;
|
||||
selector_string = mkSelString (attrs.select or {} // {
|
||||
inherit (attrs) modName;
|
||||
});
|
||||
hash = builtins.substring 0 32 (builtins.hashString "sha256" selector_string);
|
||||
} // attrs);
|
||||
|
||||
|
||||
|
||||
########## build Rust Module
|
||||
mkMizeRustModule = attrs: craneLib.buildPackage (attrs // {
|
||||
MIZE_BUILD_CONFIG = mizeBildConfig;
|
||||
MIZE_BUILD_CONFIG = mizeBuildConfigStr;
|
||||
selector_string = mkSelString (attrs.select or {} // {
|
||||
inherit (attrs) modName;
|
||||
});
|
||||
@@ -202,6 +203,7 @@ rec {
|
||||
|
||||
|
||||
buildModule = path: extraArgs: pkgs.callPackage ((import path).module or (attrs: null)) ({
|
||||
inherit buildMizeForSystem mizeBuildConfig mizeBuildConfigStr;
|
||||
inherit mkSelString craneLib toolchain_version;
|
||||
inherit mkMizeModule mkMizeRustModule buildModule findModules crossSystem pkgsCross pkgsNative mkMizeRustShell;
|
||||
mize_version = main-default.version;
|
||||
@@ -214,14 +216,16 @@ rec {
|
||||
};
|
||||
|
||||
|
||||
mizeBildConfig = let
|
||||
settingsFormat = pkgs.formats.toml { };
|
||||
in settingsFormat.generate "mize-build-config.toml" {
|
||||
config = {
|
||||
mizeBuildConfig = {
|
||||
namespace = "mize.buildtime.ns";
|
||||
module_url = "c2vi.dev";
|
||||
selector = builtins.fromJSON (mkSelString {});
|
||||
};
|
||||
};
|
||||
|
||||
mizeBuildConfigStr = let
|
||||
settingsFormat = pkgs.formats.toml { };
|
||||
in settingsFormat.generate "mize-build-config.toml" {
|
||||
config = mizeBuildConfig;
|
||||
};
|
||||
|
||||
####### build mize
|
||||
@@ -240,7 +244,7 @@ rec {
|
||||
(if crossSystem.nameFull == "x86_64-unknown-linux-gnu" then pkgs.openssl else pkgsCross.openssl)
|
||||
];
|
||||
|
||||
MIZE_BUILD_CONFIG = mizeBildConfig;
|
||||
MIZE_BUILD_CONFIG = mizeBuildConfigStr;
|
||||
|
||||
# patch the interpreter to run on most linux-gnu distros
|
||||
postBuild =
|
||||
@@ -272,7 +276,7 @@ rec {
|
||||
|
||||
CARGO_BUILD_TARGET = "${crossSystem.cpu.name}-pc-windows-gnu";
|
||||
|
||||
MIZE_BUILD_CONFIG = mizeBildConfig;
|
||||
MIZE_BUILD_CONFIG = mizeBuildConfigStr;
|
||||
|
||||
# fixes issues related to libring
|
||||
TARGET_CC = "${pkgs.pkgsCross.mingwW64.stdenv.cc}/bin/${pkgs.pkgsCross.mingwW64.stdenv.cc.targetPrefix}cc";
|
||||
@@ -295,6 +299,8 @@ rec {
|
||||
doCheck = false; # tests does not work in wasm
|
||||
CARGO_BUILD_TARGET = "wasm32-unknown-unknown";
|
||||
cargoExtraArgs = "--features wasm-target --no-default-features";
|
||||
RUSTFLAGS="-C linker=wasm-ld";
|
||||
buildInputs = with pkgs; [ cargo-binutils lld ];
|
||||
});
|
||||
main-wasm = craneLib.mkCargoDerivation {
|
||||
name = "mize-npm-package";
|
||||
@@ -302,21 +308,26 @@ rec {
|
||||
# i can't use CARGO_BUILD_TARGET to set the target
|
||||
# because then the cargo install run by wasm-pack tries to build the wasm-bindgen-cli for a wasm target...
|
||||
|
||||
|
||||
src = self;
|
||||
|
||||
doInstallCargoArtifacts = false;
|
||||
|
||||
cargoArtifacts = wasmArtifacts;
|
||||
doCheck = false;
|
||||
|
||||
buildPhaseCargoCommand = ''
|
||||
mkdir -p $out/pkg
|
||||
|
||||
HOME=$(mktemp -d fake-homeXXXX) wasm-pack build --out-dir $out/pkg --scope=c2vi -- --features wasm-target --no-default-features
|
||||
HOME=$(mktemp -d fake-homeXXXX) wasm-pack build --target no-modules --out-dir $out/pkg --scope=c2vi -- --features wasm-target --no-default-features
|
||||
'';
|
||||
|
||||
postInstall = ''
|
||||
rm -rf $out/target.tar.zst
|
||||
'';
|
||||
|
||||
buildInputs = with pkgsNative; [ wasm-bindgen-cli binaryen wasm-pack ];
|
||||
|
||||
MIZE_BUILD_CONFIG = mizeBildConfig;
|
||||
MIZE_BUILD_CONFIG = mizeBuildConfigStr;
|
||||
};
|
||||
|
||||
|
||||
@@ -351,7 +362,7 @@ rec {
|
||||
});
|
||||
|
||||
mkMizeModuleShell = attrs: pkgs.mkShell (attrs // {
|
||||
MIZE_BUILD_CONFIG = mizeBildConfig;
|
||||
MIZE_BUILD_CONFIG = mizeBuildConfigStr;
|
||||
});
|
||||
|
||||
|
||||
@@ -372,7 +383,7 @@ rec {
|
||||
pkg-config
|
||||
];
|
||||
|
||||
MIZE_BUILD_CONFIG = mizeBildConfig;
|
||||
MIZE_BUILD_CONFIG = mizeBuildConfigStr;
|
||||
|
||||
shellHook = ''
|
||||
export MIZE_CONFIG_FILE=${self}/test-config.toml
|
||||
@@ -412,13 +423,7 @@ rec {
|
||||
# install mize
|
||||
mkdir -p $out/mize/${mize.system.name}
|
||||
|
||||
${
|
||||
if mize.system.kernel.name == "windows"
|
||||
then "cp ${mize.main}/bin/mize.exe $out/mize/${mize.system.name}/"
|
||||
else if mize.system.cpu.name == "wasm32"
|
||||
then "cp ${mize.main}/lib/mize.wasm $out/mize/${mize.system.name}/"
|
||||
else "cp ${mize.main}/bin/mize $out/mize/${mize.system.name}/"
|
||||
}
|
||||
cp -r ${mize.main}/* $out/mize/${mize.system.name}/
|
||||
|
||||
# intall the modules
|
||||
${mkModulesInstallPhase mize.modulesList}
|
||||
@@ -427,7 +432,7 @@ rec {
|
||||
mkModulesInstallPhase = modules: pkgs.lib.concatStringsSep "\n" (map mkModuleInstallPhase modules);
|
||||
|
||||
mkModuleInstallPhase = module: let
|
||||
hash = builtins.substring 0 32 (builtins.hashString "sha256" module.selector_string);
|
||||
hash = module.hach;
|
||||
in ''
|
||||
echo got module: ${module.name}
|
||||
echo out: $out
|
||||
|
||||
@@ -16,11 +16,11 @@ pub struct EmptyModule {
|
||||
}
|
||||
|
||||
impl Module for EmptyModule {
|
||||
fn init(&mut self, instance: Instance) -> MizeResult<()> {
|
||||
fn init(&mut self, instance: &Instance) -> MizeResult<()> {
|
||||
println!("empty module fn init");
|
||||
Ok(())
|
||||
}
|
||||
fn exit(&mut self, instance: Instance) -> MizeResult<()> {
|
||||
fn exit(&mut self, instance: &Instance) -> MizeResult<()> {
|
||||
println!("empty module fn exit");
|
||||
Ok(())
|
||||
|
||||
|
||||
@@ -98,6 +98,6 @@ pub fn instance_init(instance: &mut core::instance::Instance) {}
|
||||
|
||||
pub fn load_module(instance: &mut core::instance::Instance, name: &str, path: Option<PathBuf>) -> MizeResult<()> { Ok(()) }
|
||||
|
||||
pub fn fetch_module(instance: &mut core::instance::Instance, name: &str, path: Option<PathBuf>) -> MizeResult<String> { Ok("oh noooooooooooooo, something went really really wrong, if this ends up in the executable....".to_owned()) }
|
||||
pub fn fetch_module(instance: &mut core::instance::Instance, name: &str) -> MizeResult<String> { Ok("oh noooooooooooooo, something went really really wrong, if this ends up in the executable....".to_owned()) }
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user