plausibly have a build that will do better through CI than previously

This commit is contained in:
Quinn Dougherty 2022-08-17 20:42:40 -07:00
parent 2b1485fbec
commit 6f50501b05
19 changed files with 188 additions and 1588 deletions

View File

@ -69,11 +69,11 @@ jobs:
- name: Download wasm-bindgen
uses: jetli/wasm-bindgen-action@v0.1.0
with:
version: 'latest'
version: "latest"
- name: Download wasm-pack
uses: jetli/wasm-pack-action@v0.3.0
with:
version: 'latest'
version: "latest"
- name: Build
run: wasm-pack build --target nodejs
@ -88,7 +88,7 @@ jobs:
working-directory: packages/squiggle-lang
steps:
- uses: actions/checkout@v3
- name: Install Dependencies
- name: Install dependencies
run: cd ../../ && yarn
- name: Check rescript lint
run: yarn lint:rescript
@ -116,13 +116,13 @@ jobs:
- name: Download wasm-bindgen
uses: jetli/wasm-bindgen-action@v0.1.0
with:
version: 'latest'
version: "latest"
- name: Download wasm-pack
uses: jetli/wasm-pack-action@v0.3.0
with:
version: 'latest'
- name: Build
run: wasm-pack build --target nodejs
version: "latest"
- name: Build squiggle-mc
run: cd ../mc && wasm-pack build --target nodejs
- name: Build rescript codebase and typescript interface
run: yarn build
- name: Run rescript tests
@ -169,13 +169,13 @@ jobs:
- name: Download wasm-bindgen
uses: jetli/wasm-bindgen-action@v0.1.0
with:
version: 'latest'
version: "latest"
- name: Download wasm-pack
uses: jetli/wasm-pack-action@v0.3.0
with:
version: 'latest'
- name: Build
run: wasm-pack build --target nodejs
version: "latest"
- name: Build squiggle-mc
run: cd ../mc wasm-pack build --target nodejs
- name: Build rescript codebase and typescript interface in squiggle-lang
run: cd ../squiggle-lang && yarn build
- name: Run webpack
@ -216,13 +216,13 @@ jobs:
- name: Download wasm-bindgen
uses: jetli/wasm-bindgen-action@v0.1.0
with:
version: 'latest'
version: "latest"
- name: Download wasm-pack
uses: jetli/wasm-pack-action@v0.3.0
with:
version: 'latest'
- name: Build
run: wasm-pack build --target nodejs
version: "latest"
- name: Build squiggle-mc
run: cd ../mc wasm-pack build --target nodejs
- name: Build rescript and typescript in squiggle-lang
run: cd ../squiggle-lang && yarn build
- name: Build components
@ -259,7 +259,9 @@ jobs:
- uses: actions/checkout@v3
- name: Install dependencies from monorepo level
run: cd ../../ && yarn
- name: Build
- name: Build squiggle-mc
run: cd ../mc && wasm-pack build --target nodejs
- name: Build vscode
run: yarn compile
cli-lint:

View File

@ -14,3 +14,5 @@ packages/website/build/
packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.js
packages/vscode-ext/media/vendor/
packages/mc/pkg/
packages/mc/target/
result

View File

@ -1,52 +1,12 @@
{
"nodes": {
"cargo2nix": {
"inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils",
"nixpkgs": [
"nixpkgs"
],
"rust-overlay": "rust-overlay"
},
"locked": {
"lastModified": 1655189312,
"narHash": "sha256-gpJ57OgIebUpO+7F00VltxSEy6dz2x6HeJ5BcRM8rDA=",
"owner": "cargo2nix",
"repo": "cargo2nix",
"rev": "c149357cc3d17f2849c73eb7a09d07a307cdcfe8",
"type": "github"
},
"original": {
"owner": "cargo2nix",
"ref": "release-0.11.0",
"repo": "cargo2nix",
"type": "github"
}
},
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1650374568,
"narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "b4a34015c698c7793d592d66adbab377907a2be8",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-utils": {
"locked": {
"lastModified": 1653893745,
"narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=",
"lastModified": 1659877975,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1",
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
"type": "github"
},
"original": {
@ -72,11 +32,11 @@
},
"flake-utils_3": {
"locked": {
"lastModified": 1659877975,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
"lastModified": 1656928814,
"narHash": "sha256-RIFfgBuKz6Hp89yRr7+NR5tzIAbn52h8vT6vXkYjZoM=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
"rev": "7e2a3b3dfd9af950a856d66b0a7d01e3c18aa249",
"type": "github"
},
"original": {
@ -87,7 +47,7 @@
},
"gentype": {
"inputs": {
"flake-utils": "flake-utils_3",
"flake-utils": "flake-utils_2",
"nixpkgs": [
"nixpkgs"
]
@ -126,33 +86,13 @@
"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,
"narHash": "sha256-sgAhmrC1iSnl5T2VPPiMpciH1aRw5c7PYEdXX6jd6Gk=",
"lastModified": 1660581366,
"narHash": "sha256-et+bi9/jlSF/pHx5AYB9ZP2XDdZEQ0vnF7xlvs4503Y=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "879121648fe522b38cc1cf75aef160a14a1f2e7b",
"rev": "3d47bbaa26e7a771059d828eecf3bd8bf28a8b0f",
"type": "github"
},
"original": {
@ -163,31 +103,26 @@
},
"root": {
"inputs": {
"cargo2nix": "cargo2nix",
"flake-utils": "flake-utils_2",
"flake-utils": "flake-utils",
"gentype": "gentype",
"hercules-ci-effects": "hercules-ci-effects",
"naersk": "naersk",
"nixpkgs": "nixpkgs"
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay"
}
},
"rust-overlay": {
"inputs": {
"flake-utils": [
"cargo2nix",
"flake-utils"
],
"flake-utils": "flake-utils_3",
"nixpkgs": [
"cargo2nix",
"nixpkgs"
]
},
"locked": {
"lastModified": 1653878966,
"narHash": "sha256-T51Gck/vrJZi1m+uTbhEFTRgZmE59sydVONadADv358=",
"lastModified": 1660704984,
"narHash": "sha256-9sMoNrKh0b5NOEwe1j6H4dTRAsBsq1fmyDCXHzjB3Nc=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "8526d618af012a923ca116be9603e818b502a8db",
"rev": "2801b291b546dcdcebfa47043fe09f7a0da72880",
"type": "github"
},
"original": {

View File

@ -3,12 +3,8 @@
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";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
gentype = {
@ -25,20 +21,14 @@
};
};
outputs = { self, nixpkgs, gentype, hercules-ci-effects, naersk, cargo2nix
, flake-utils, ... }:
outputs = { self, nixpkgs, rust-overlay, gentype, hercules-ci-effects, 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
rust-overlay.overlays.default
(final: prev: {
# set the node version here
nodejs = prev.nodejs-16_x;
nodejs = prev.nodejs-18_x;
# The override is the only way to get it into mkYarnModules
})
];
@ -48,17 +38,13 @@
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, wasmPkgs, ... }:
mcFn = { pkgs, ... }:
import ./nix/squiggle-mc.nix {
inherit pkgs wasmPkgs commonFn naerskFn;
inherit pkgs;
};
langFn = { pkgs, ... }:
# Probably doesn't work on i686-linux
import ./nix/squiggle-lang.nix {
inherit pkgs commonFn mcFn gentypeOutputFn;
};
@ -72,17 +58,17 @@
};
# local machines
localFlake = { pkgs, wasmPkgs, ... }:
localFlake = { pkgs, ... }:
let
mc = mcFn { inherit pkgs wasmPkgs; };
mc = mcFn pkgs;
lang = langFn pkgs;
components = componentsFn pkgs;
website = websiteFn pkgs;
in {
# validating
checks = flake-utils.lib.flattenTree {
wasm-lint = mc.rust-lint;
wasm-headless-test = mc.firefox-test;
wasm-lint = mc.lint;
wasm-test = mc.test;
lang-lint = lang.lint;
lang-test = lang.test;
components-lint = components.lint;
@ -90,20 +76,16 @@
};
# building
packages = flake-utils.lib.flattenTree {
default = website.docusaurus;
mc-wasm = mc.lib;
mc-wasm2 = mc.lib2;
mc-wasm-pkg = mc.webpack-build-pkg;
default = components.package-build;
mc-wasm = mc.pkg;
lang-bundle = lang.bundle;
components = components.package-build;
storybook = components.site-build;
docs-site = website.docusaurus;
};
# developing
devShells = flake-utils.lib.flattenTree {
default =
(import ./nix/shell.nix { inherit pkgs cargo2nix; }).shell;
(import ./nix/shell.nix { inherit pkgs; }).shell;
};
};
@ -111,16 +93,8 @@
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 {
pkgs = hciPkgs;
wasmPkgs = hciPkgsWasm;
};
mc = mcFn hciPkgs;
lang = langFn hciPkgs;
components = componentsFn hciPkgs;
website = websiteFn hciPkgs;
@ -129,9 +103,9 @@
ciSystems = [ hciSystem ];
onPush = {
wasm.outputs = {
squiggle-wasm-lint = mc.rust-lint;
squiggle-wasm-pkg = mc.webpack-build-pkg;
squiggle-wasm-test-ff = mc.firefox-test;
squiggle-wasm-lint = mc.lint;
squiggle-wasm-pkg = mc.pkg;
squiggle-wasm-test = mc.test;
};
lang.outputs = {
squiggle-lang-lint = lang.lint;
@ -158,14 +132,6 @@
inherit system;
overlays = overlays;
};
pkgsWasm = import nixpkgs {
inherit system;
overlays = overlays;
crossSystem = crossSystemForWasmPkgs;
};
in localFlake {
pkgs = pkgs;
wasmPkgs = pkgsWasm;
}) // herc;
in localFlake pkgs) // herc;
}

5
nix/rust-toolchain.toml Normal file
View File

@ -0,0 +1,5 @@
[toolchain]
channel = "stable"
components = []
targets = [ "wasm32-unknown-unknown" ]
profile = "default"

View File

@ -1,4 +1,4 @@
{ pkgs, cargo2nix }:
{ pkgs }:
with pkgs; {
shell = mkShell {
name = "SQUIGGLE_yarn-wasm-devshell";
@ -13,9 +13,9 @@ with pkgs; {
libressl
nixfmt
rustfmt
cargo2nix.outputs.packages.${pkgs.system}.default
wasmtime
binaryen
wasm-bindgen-cli
];
};
}

View File

@ -17,7 +17,7 @@ rec {
src = ../packages/components;
packageJSON = componentsPackageJson;
yarnLock = ../yarn.lock;
packageResolutions."@quri/squiggle-mc" = mc.webpack-build-pkg;
packageResolutions."@quri/squiggle-mc" = mc.pkg;
packageResolutions."@quri/squiggle-lang" = lang.build;
};
lint = pkgs.stdenv.mkDerivation {
@ -52,17 +52,4 @@ rec {
cp -r deps/@quri/squiggle-components/. $out
'';
};
site-build = pkgs.stdenv.mkDerivation {
name = "squiggle-components-storybook";
src = package-build;
buildInputs = common.buildInputs;
buildPhase = "yarn build:storybook";
installPhase = ''
mkdir -p $out
# patching .gitignore so flake keeps build artefacts
sed -i /build/d .gitignore
sed -i /storybook-static/d .gitignore
'';
};
}

View File

@ -10,7 +10,7 @@ rec {
yarnLock = ../yarn.lock;
pkgConfig = {
rescript = {
buildInputs = common.which ++ [ pkgs.gcc_multi ];
buildInputs = common.which ++ (if pkgs.system != "i686-linux" then [ pkgs.gcc_multi ] else []);
postInstall = ''
echo "PATCHELF'ING RESCRIPT EXECUTABLES (INCL NINJA)"
# Patching interpreter for linux/*.exe's
@ -39,7 +39,7 @@ rec {
'';
};
};
packageResolutions."@quri/squiggle-mc" = mc.webpack-build-pkg;
packageResolutions."@quri/squiggle-mc" = mc.pkg;
};
lint = pkgs.stdenv.mkDerivation {
name = "squiggle-lang-lint";

View File

@ -1,65 +1,43 @@
{ pkgs, wasmPkgs, commonFn, naerskFn }:
{ pkgs }:
rec {
common = commonFn pkgs;
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 {
with pkgs.rustPlatform; rec {
rust = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
pkg = buildRustPackage {
pname = "quri_squiggle_mc";
version = "0.0.1";
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;
nativeBuildInputs = [ rust pkgs.wasm-bindgen-cli ];
yarn-source = pkgs.mkYarnPackage {
name = "squiggle-mc_yarnsource";
buildInputs = common.buildInputs;
src = ../packages/mc;
packageJSON = ../packages/mc/package.json;
yarnLock = ../yarn.lock;
buildPhase = ''
cargo build --lib --release --target=wasm32-unknown-unknown
mkdir -p $out/pkg
wasm-bindgen --target nodejs --out-dir $out/pkg target/wasm32-unknown-unknown/release/quri_squiggle_mc.wasm
'';
installPhase = "echo 'skipping installPhase'";
cargoLock = {
lockFile = ../packages/mc/Cargo.lock;
outputHashes = {
"kernel_density-0.0.2" = "sha256-pHh5p/AS+uopmPSaXK9rKHlmqS26qggXvf1TeitS430=";
};
rust-lint = pkgs.stdenv.mkDerivation {
};
};
lint = pkgs.stdenv.mkDerivation {
name = "squiggle-mc-lint";
src = yarn-source + "/libexec/@quri/squiggle-mc/deps/@quri/squiggle-mc";
src = ../packages/mc;
buildInputs = with pkgs; [ rustfmt ];
buildPhase = "rustfmt --check src";
installPhase = "mkdir -p $out";
};
webpack-build-pkg = pkgs.stdenv.mkDerivation {
name = "squiggle-mc-build";
src = yarn-source + "/libexec/@quri/squiggle-mc";
buildInputs = common.buildInputs ++ (with pkgs; [ wasm-pack ]);
buildPhase = ''
pushd deps/@quri/squiggle-mc
sed -i /pkg/d .gitignore
yarn --offline build
popd
'';
installPhase = ''
mkdir -p $out
cp -r deps/@quri/squiggle-mc/. $out
'';
};
firefox-test = pkgs.stdenv.mkDerivation {
test = pkgs.stdenv.mkDerivation {
name = "squiggle-mc-test";
src = yarn-source + "/libexec/@quri/squiggle-mc/deps/@quri/squiggle-mc";
buildInputs = common.buildInputs
++ (with pkgs; [ geckodriver cargo wasm-pack ]);
buildPhase = "yarn --offline test -- --firefox";
src = mc-pkg + "/pkg";
buildInputs = with pkgs; [ cargo ];
buildPhase = "cargo test";
installPhase = "mkdir -p $out";
};
}

View File

@ -18,7 +18,7 @@ rec {
src = ../packages/website;
packageJSON = websitePackageJson;
yarnLock = ../yarn.lock;
packageResolutions."@quri/squiggle-mc" = mc.webpack-build-pkg + "/pkg";
packageResolutions."@quri/squiggle-mc" = mc.pkg;
packageResolutions."@quri/squiggle-lang" = lang.build;
packageResolutions."@quri/squiggle-components" = components.package-build;
};
@ -29,18 +29,4 @@ rec {
buildPhase = "yarn --offline lint";
installPhase = "mkdir -p $out";
};
docusaurus = pkgs.stdenv.mkDerivation {
name = "squiggle-website";
buildInputs = common.buildInputs;
src = yarn-source + "/libexec/squiggle-website";
buildPhase = ''
pushd deps/squiggle-website
yarn --offline build
popd
'';
installPhase = ''
mkdir -p $out
cp -r $src/build $out
'';
};
}

73
packages/mc/Cargo.lock generated
View File

@ -36,9 +36,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "bumpalo"
version = "3.10.0"
version = "3.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3"
checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d"
[[package]]
name = "cached"
@ -277,9 +277,9 @@ checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754"
[[package]]
name = "js-sys"
version = "0.3.59"
version = "0.3.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2"
checksum = "a38fc24e30fd564ce974c02bf1d337caddff65be6cc4735a1f7eab22a7440f04"
dependencies = [
"wasm-bindgen",
]
@ -305,12 +305,6 @@ version = "0.2.132"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5"
[[package]]
name = "libm"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "292a948cd991e376cf75541fe5b97a1081d713c618b4f1b9500f8844e49eb565"
[[package]]
name = "log"
version = "0.4.17"
@ -332,16 +326,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3"
[[package]]
name = "num-traits"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
dependencies = [
"autocfg",
"libm",
]
[[package]]
name = "num_cpus"
version = "1.13.1"
@ -447,8 +431,8 @@ dependencies = [
"quickcheck",
"quickcheck_macros",
"rand 0.8.5",
"rand_distr",
"serde",
"serde-wasm-bindgen",
"statistics",
"wasm-bindgen",
"wasm-bindgen-futures",
@ -525,16 +509,6 @@ dependencies = [
"getrandom",
]
[[package]]
name = "rand_distr"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32cb0b9bc82b0a0876c2dd994a7e7a2683d3e7390ca40e6886785ef0c7e3ee31"
dependencies = [
"num-traits",
"rand 0.8.5",
]
[[package]]
name = "rdrand"
version = "0.4.0"
@ -582,6 +556,17 @@ dependencies = [
"serde_derive",
]
[[package]]
name = "serde-wasm-bindgen"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cfc62771e7b829b517cb213419236475f434fb480eddd76112ae182d274434a"
dependencies = [
"js-sys",
"serde",
"wasm-bindgen",
]
[[package]]
name = "serde_derive"
version = "1.0.143"
@ -697,9 +682,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-bindgen"
version = "0.2.82"
version = "0.2.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d"
checksum = "25f1af7423d8588a3d840681122e72e6a24ddbcb3f0ec385cac0d12d24256c06"
dependencies = [
"cfg-if 1.0.0",
"serde",
@ -709,13 +694,13 @@ dependencies = [
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.82"
version = "0.2.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f"
checksum = "8b21c0df030f5a177f3cba22e9bc4322695ec43e7257d865302900290bcdedca"
dependencies = [
"bumpalo",
"lazy_static",
"log",
"once_cell",
"proc-macro2 1.0.43",
"quote 1.0.21",
"syn",
@ -737,9 +722,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.82"
version = "0.2.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602"
checksum = "2f4203d69e40a52ee523b2529a773d5ffc1dc0071801c87b3d270b471b80ed01"
dependencies = [
"quote 1.0.21",
"wasm-bindgen-macro-support",
@ -747,9 +732,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.82"
version = "0.2.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da"
checksum = "bfa8a30d46208db204854cadbb5d4baf5fcf8071ba5bf48190c3e59937962ebc"
dependencies = [
"proc-macro2 1.0.43",
"quote 1.0.21",
@ -760,9 +745,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.82"
version = "0.2.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a"
checksum = "3d958d035c4438e28c70e4321a2911302f10135ce78a9c7834c0cab4123d06a2"
[[package]]
name = "wasm-bindgen-test"
@ -791,9 +776,9 @@ dependencies = [
[[package]]
name = "web-sys"
version = "0.3.59"
version = "0.3.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed055ab27f941423197eb86b2035720b1a3ce40504df082cac2ecc6ed73335a1"
checksum = "c060b319f29dd25724f09a2ba1418f142f539b2be99fbf4d2d5a8f7330afb8eb"
dependencies = [
"js-sys",
"wasm-bindgen",

File diff suppressed because it is too large Load Diff

View File

@ -33,13 +33,15 @@ default = ["wee_alloc"]
[dependencies]
# The `wasm-bindgen` crate provides the bare minimum functionality needed
# to interact with JavaScript.
wasm-bindgen = { version = "0.2.82", features = ["serde-serialize"] }
wasm-bindgen = { version = "=0.2.79", features = ["serde-serialize"] }
serde = { version = "1", features = ["derive"] }
serde-wasm-bindgen = "0.4.3"
# The `web-sys` crate allows you to interact with the various browser APIs,
# like the DOM.
web-sys = { version = "0.3.59", features = ["console"] }
web-sys = { version = "0.3", features = ["console"] }
js-sys = "0.3.22"
# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size
# compared to the default allocator's ~10K. However, it is slower than the default
# allocator, so it's not enabled by default.
@ -47,12 +49,12 @@ wee_alloc = { version = "0.4.2", optional = true }
# Numerical things
rand = "0.8.5"
getrandom = { version = "0.2", features = ["js"] }
rand_distr = "0.4.3"
getrandom = { version = "0.2.7", features = ["js"] }
# rand_distr = "0.4.3"
statistics = "0.4.1"
kernel_density = { git = "https://github.com/daithiocrualaoich/kernel_density" }
cached = { version = "0.38.0", features = ["wasm"] }
# instant = { git = "https://github.com/sebcrozet/instant", features = ["wasm-bindgen"] }
# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so it's only enabled
@ -64,7 +66,6 @@ console_error_panic_hook = "0.1.5"
[dev-dependencies]
wasm-bindgen-test = "0.2.45"
futures = "0.1.27"
js-sys = "0.3.22"
wasm-bindgen-futures = "0.3.22"
quickcheck = "1"
quickcheck_macros = "1"

View File

@ -1,54 +1,17 @@
# `@quri/squiggle-mc` - parallel Monte Carlo with memoization for the `@quri/squiggle-lang` javascript interface
# `@quri/squiggle-mc` - (hope to be) parallel Monte Carlo with memoization for the `@quri/squiggle-lang` javascript interface
## How to install
Please run `yarn` at the monorepo level.
In this subrepo, please run `./cargo-refresh-nix.sh` every time `Cargo.toml`/`Cargo.lock` is modified, it requires nix with flakes.
Please view `/.github/workflows/ci.yml` for the most accurate story about how to build in concert with the rest of the packages in the monorepo.
## How to run in debug mode
`nix develop` will set you up quite well. Rust versions for `wasm-pack` and so on could be a pain.
The build you need for the `squiggle-lang` package:
```sh
# Builds the project and opens it in a new browser tab. Auto-reloads when the project changes.
yarn start
wasm-pack build --target nodejs
```
## How to build in release mode
```sh
# Builds the project and places it into the `dist` folder.
yarn build
```
## How to run unit tests
These are the headless browser tests, which will attempt to download and install drivers, and may fail.
```sh
# Runs tests in Firefox
yarn test -- --firefox
# Runs tests in Chrome
yarn test -- --chrome
# Runs tests in Safari
yarn test -- --safari
```
## What does each file do?
* `Cargo.toml` contains the standard Rust metadata. You put your Rust dependencies in here. You must change this file with your details (name, description, version, authors, categories)
* `package.json` contains the standard npm metadata. You put your JavaScript dependencies in here. You must change this file with your details (author, name, version)
* `webpack.config.js` contains the Webpack configuration. You shouldn't need to change this, unless you have very special needs.
* The `js` folder contains your JavaScript code (`index.js` is used to hook everything into Webpack, you don't need to change it).
* The `src` folder contains your Rust code.
* The `static` folder contains any files that you want copied as-is into the final build. It contains an `index.html` file which loads the `index.js` file.
* The `tests` folder contains your Rust unit tests.
the `webpack`/`package.json`/`static` is not active and will be deleted at some point.

View File

@ -1,2 +0,0 @@
#!/usr/bin/env bash
nix run github:cargo2nix/cargo2nix

View File

@ -1,34 +1,51 @@
use wasm_bindgen::prelude::*;
use js_sys::Float64Array;
use rand::Rng;
use rand::thread_rng;
use kernel_density::kde;
use serde::Serialize;
use crate::distribution::bandwidth::{nrd0, nrd};
use serde::{Serialize, Deserialize};
// use crate::distribution::bandwidth::{nrd0, nrd};
// TODO: impl a constructor such that xs.len() == ys.len().
#[wasm_bindgen]
#[derive(Serialize)]
#[derive(Serialize, Deserialize)]
pub struct PdfCurve {
xs: Vec<f64>,
ys: Vec<f64>,
}
pub fn samples_to_continuous_pdf(samples: Vec<f64>, bandwidth: f64) -> JsValue {
let samples_to_map = samples.clone();
let pdf = kde::normal(&samples, bandwidth);
let pdf_curve = PdfCurve {
xs: samples,
ys: samples_to_map.iter().map(|x| pdf.density(*x)).collect(),
};
JsValue::from_serde::<PdfCurve>(&pdf_curve).unwrap()
#[wasm_bindgen]
impl PdfCurve {
#[wasm_bindgen(constructor)]
pub fn new(xs: Vec<f64>, ys: Vec<f64>) -> Result<PdfCurve, String> {
let mut sorted_zip: Vec<(&f64, &f64)> = xs.iter().zip(ys.iter()).collect();
sorted_zip.sort_by(|a, b| a.0.partial_cmp(b.0).unwrap()); // Will panic if there are any NaN.
return match xs.len() != ys.len() {
true => return Err("error: xs and ys are not the same length".to_string()),
false => {
let xs: Vec<f64> = sorted_zip.iter().map(|a| *a.0).collect();
let ys: Vec<f64> = sorted_zip.iter().map(|b| *b.1).collect();
Ok(PdfCurve { xs: xs, ys: ys })
},
}
}
#[wasm_bindgen(getter)]
pub fn xs(&self) -> Float64Array {
Float64Array::from(&self.xs[..])
}
#[wasm_bindgen(getter)]
pub fn ys(&self) -> Float64Array {
Float64Array::from(&self.ys[..])
}
}
// pub fn get_curve(samples: Vec<f64>, n: u64) -> Vec<f64> {
// let bandwidth = nrd(&samples);
// let curve = samples_to_continuous_pdf(samples, bandwidth);
// return curve.ys;
// }
pub fn samples_to_continuous_pdf(samples: Vec<f64>, bandwidth: f64) -> PdfCurve {
let samples_to_map = samples.clone();
let pdf = kde::normal(&samples, bandwidth);
let pdf_curve = PdfCurve::new(samples, samples_to_map.iter().map(|x| pdf.density(*x)).collect());
pdf_curve.unwrap()
}
pub fn sample_n(xs: Vec<f32>, n: i32) -> Vec<f32> {
let m = xs.len();

View File

@ -1,7 +1,7 @@
use wasm_bindgen::prelude::*;
use web_sys::console;
use serde_wasm_bindgen;
mod distribution;
use distribution::{monte_carlo, bandwidth};
use distribution::monte_carlo;
// When the `wee_alloc` feature is enabled, this uses `wee_alloc` as the global
// allocator.
@ -17,14 +17,15 @@ pub fn sample_n(samples: Box<[f32]>, num_samples: i32) -> Vec<f32> {
console_error_panic_hook::set_once();
let samples_vec = Vec::from(samples);
return monte_carlo::sample_n(samples_vec, num_samples);
monte_carlo::sample_n(samples_vec, num_samples)
}
#[wasm_bindgen]
pub fn samples_to_continuous_pdf(samples: Box<[f64]>, bandwidth: f64) -> JsValue {
#[cfg(debug_assertions)]
console_error_panic_hook::set_once();
let samples_vec = Vec::from(samples);
monte_carlo::samples_to_continuous_pdf(samples_vec, bandwidth)
}
// #[wasm_bindgen]
// pub fn samples_to_continuous_pdf(samples: Box<[f64]>, bandwidth: f64) -> JsValue {
// #[cfg(debug_assertions)]
// console_error_panic_hook::set_once();
//
// let samples_vec = Vec::from(samples);
// let pdf = monte_carlo::samples_to_continuous_pdf(samples_vec, bandwidth);
// serde_wasm_bindgen::to_value(&pdf).unwrap()
//}

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta charset="UTF-8" />
<title>For developing squiggle-mc</title>
</head>
<body>

View File

@ -27,7 +27,7 @@ module.exports = {
}),
],
resolve: {
extensions: [".tsx", ".ts", ".js"]
extensions: [".tsx", ".ts", ".js"],
},
experiments: {
asyncWebAssembly: true,