From 84f0cfd3b044ad27f9da697aabacb2f10982d119 Mon Sep 17 00:00:00 2001 From: Quinn Dougherty Date: Tue, 16 Aug 2022 22:22:03 -0700 Subject: [PATCH] tried to get the nixification to work --- flake.lock | 21 ++++++++++++++++++ flake.nix | 49 +++++++++++++++++++++++++++++------------- nix/shell.nix | 2 +- nix/squiggle-mc.nix | 28 +++++++++++++++++++----- packages/mc/Cargo.toml | 8 +++++++ yarn.lock | 3 --- 6 files changed, 87 insertions(+), 24 deletions(-) diff --git a/flake.lock b/flake.lock index 7c0b2f82..988f334a 100644 --- a/flake.lock +++ b/flake.lock @@ -126,6 +126,26 @@ "type": "github" } }, + "naersk": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1659610603, + "narHash": "sha256-LYgASYSPYo7O71WfeUOaEUzYfzuXm8c8eavJcel+pfI=", + "owner": "nix-community", + "repo": "naersk", + "rev": "c6a45e4277fa58abd524681466d3450f896dc094", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "naersk", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1660496378, @@ -147,6 +167,7 @@ "flake-utils": "flake-utils_2", "gentype": "gentype", "hercules-ci-effects": "hercules-ci-effects", + "naersk": "naersk", "nixpkgs": "nixpkgs" } }, diff --git a/flake.nix b/flake.nix index 9f6e32ca..ed374676 100644 --- a/flake.nix +++ b/flake.nix @@ -3,6 +3,10 @@ inputs = { nixpkgs.url = "nixpkgs/nixos-22.05"; + naersk = { + url = "github:nix-community/naersk"; + inputs.nixpkgs.follows = "nixpkgs"; + }; cargo2nix = { url = "github:cargo2nix/cargo2nix/release-0.11.0"; inputs.nixpkgs.follows = "nixpkgs"; @@ -21,18 +25,33 @@ }; }; - outputs = { self, nixpkgs, gentype, hercules-ci-effects, cargo2nix + outputs = { self, nixpkgs, gentype, hercules-ci-effects, naersk, cargo2nix , flake-utils, ... }: let version = builtins.substring 0 8 self.lastModifiedDate; + crossSystemForWasmPkgs = { + config = "wasm32-unknown-wasi-unknown"; + system = "wasm32-wasi"; + useLLVM = true; + }; + overlays = [ + cargo2nix.overlays.default + (final: prev: { + # set the node version here + nodejs = prev.nodejs-18_x; + # The override is the only way to get it into mkYarnModules + }) + ]; + commonFn = pkgs: { buildInputs = with pkgs; [ nodejs yarn ]; prettier = with pkgs.nodePackages; [ prettier ]; which = [ pkgs.which ]; }; + naerskFn = { pkgs, rust, ... }: pkgs.callPackage naersk { cargo = rust; rustc = rust; }; gentypeOutputFn = pkgs: gentype.outputs.packages.${pkgs.system}.default; - mcFn = { pkgs, ... }: - import ./nix/squiggle-mc.nix { inherit pkgs commonFn; }; + mcFn = { pkgs, wasmPkgs, ... }: + import ./nix/squiggle-mc.nix { inherit pkgs wasmPkgs commonFn naerskFn; }; langFn = { pkgs, ... }: import ./nix/squiggle-lang.nix { inherit pkgs commonFn mcFn gentypeOutputFn; @@ -47,9 +66,9 @@ }; # local machines - localFlake = { pkgs, ... }: + localFlake = { pkgs, wasmPkgs, ... }: let - mc = mcFn pkgs; + mc = mcFn { inherit pkgs wasmPkgs; }; lang = langFn pkgs; components = componentsFn pkgs; website = websiteFn pkgs; @@ -67,6 +86,7 @@ packages = flake-utils.lib.flattenTree { default = website.docusaurus; mc-wasm = mc.lib; + mc-wasm2 = mc.lib2; mc-wasm-pkg = mc.webpack-build-pkg; lang-bundle = lang.bundle; components = components.package-build; @@ -85,8 +105,9 @@ herc = let hciSystem = "x86_64-linux"; hciPkgs = import nixpkgs { system = hciSystem; }; + hciPkgsWasm = import nixpkgs { system = hciSystem; crossSystem = crossSystemForWasmPkgs; overlays = overlays; }; effects = hercules-ci-effects.lib.withPkgs hciPkgs; - mc = mcFn hciPkgs; + mc = mcFn hciPkgs hciPkgsWasm; lang = langFn hciPkgs; components = componentsFn hciPkgs; website = websiteFn hciPkgs; @@ -122,15 +143,13 @@ # globals pkgs = import nixpkgs { inherit system; - overlays = [ - cargo2nix.overlays.default - (final: prev: { - # set the node version here - nodejs = prev.nodejs-18_x; - # The override is the only way to get it into mkYarnModules - }) - ]; + overlays = overlays; + }; + pkgsWasm = import nixpkgs { + inherit system; + overlays = overlays; + crossSystem = crossSystemForWasmPkgs; }; - in localFlake pkgs) // herc; + in localFlake { pkgs = pkgs; wasmPkgs = pkgsWasm; }) // herc; } diff --git a/nix/shell.nix b/nix/shell.nix index 8dcf6a91..aff27300 100644 --- a/nix/shell.nix +++ b/nix/shell.nix @@ -9,7 +9,7 @@ with pkgs; { nodejs rustup pkg-config - openssl + libressl nixfmt rustfmt cargo2nix.outputs.packages.${pkgs.system}.default diff --git a/nix/squiggle-mc.nix b/nix/squiggle-mc.nix index 27e2d4ed..fdd7eb9e 100644 --- a/nix/squiggle-mc.nix +++ b/nix/squiggle-mc.nix @@ -1,11 +1,30 @@ -{ pkgs, commonFn }: +{ pkgs, wasmPkgs, commonFn, naerskFn }: rec { common = commonFn pkgs; - rustPkgs = pkgs.rustBuilder.makePackageSet { - rustVersion = "1.60.0"; - packageFun = import ../packages/mc/Cargo.nix; + + rustVersion = "1.61.0"; + wasmTarget = "wasm32-unknown-unknown"; + rust = pkgs.rust-bin.stable.${rustVersion}.default.override { + targets = [ wasmTarget ]; }; + naersk = naerskFn { inherit pkgs rust; }; + mc-pkg = naersk.buildPackage { + src = ../packages/mc; + copyLibs = true; + copyBins = true; + CARGO_BUILD_TARGET = wasmTarget; + nativeBuildInputs = common.buildInputs; + }; + lib2 = mc-pkg; + + rustPkgsWasm = wasmPkgs.rustBuilder.makePackageSet { + rustVersion = rustVersion; + packageFun = import ../packages/mc/Cargo.nix; + target = wasmTarget; + }; + lib = (rustPkgsWasm.workspace.quri-squiggle-mc { }).out; + yarn-source = pkgs.mkYarnPackage { name = "squiggle-mc_yarnsource"; buildInputs = common.buildInputs; @@ -20,7 +39,6 @@ rec { buildPhase = "rustfmt --check src"; installPhase = "mkdir -p $out"; }; - lib = rustPkgs.workspace.quri-squiggle-mc { }; webpack-build-pkg = pkgs.stdenv.mkDerivation { name = "squiggle-mc-build"; src = yarn-source + "/libexec/@quri/squiggle-mc"; diff --git a/packages/mc/Cargo.toml b/packages/mc/Cargo.toml index fc8d1b9a..dc938fe5 100644 --- a/packages/mc/Cargo.toml +++ b/packages/mc/Cargo.toml @@ -10,6 +10,13 @@ categories = ["wasm", "Monte Carlo"] readme = "README.md" edition = "2018" +[package.metadata.wasm-pack.profile.dev] +wasm-opt = false +[package.metadata.wasm-pack.profile.profiling] +wasm-opt = false +[package.metadata.wasm-pack.profile.release] +wasm-opt = false + [lib] crate-type = ["cdylib"] @@ -21,6 +28,7 @@ lto = true [features] # If you uncomment this line, it will enable `wee_alloc`: default = ["wee_alloc"] +# wasm-bindgen = [ "instant/wasm-bindgen" ] [dependencies] # The `wasm-bindgen` crate provides the bare minimum functionality needed diff --git a/yarn.lock b/yarn.lock index 5eaafd45..1a41e7dd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2504,9 +2504,6 @@ resolved "https://registry.yarnpkg.com/@polka/url/-/url-1.0.0-next.21.tgz#5de5a2385a35309427f6011992b544514d559aa1" integrity sha512-a5Sab1C4/icpTZVzZc5Ghpz88yQtGOyNqYXcZgOssB2uuAr+wF/MvN6bgtW32q7HHrvBki+BsZ0OuNv6EV3K9g== -"@quri/par-cached-monte-carlo@file:packages/squiggle-mc-cached/pkg": - version "0.0.0" - "@quri/squiggle-components@^0.2.23": version "0.2.24" resolved "https://registry.yarnpkg.com/@quri/squiggle-components/-/squiggle-components-0.2.24.tgz#16a2d72fb16f46a0bf71388c85d1238927676923"