From 07c3004c82a3c143c6d9acfd01eaaee56de1763e Mon Sep 17 00:00:00 2001 From: Quinn Dougherty Date: Tue, 16 Aug 2022 20:25:31 -0700 Subject: [PATCH] just `mc` --- .gitignore | 2 + flake.nix | 31 +++++-- nix/squiggle-components.nix | 7 +- nix/squiggle-lang.nix | 11 ++- nix/squiggle-mc.nix | 46 ++++++++++ nix/squiggle-mcCache.nix | 9 -- nix/squiggle-website.nix | 8 +- packages/mc/.gitignore | 5 ++ .../{squiggle-mc-cached => mc}/Cargo.lock | 44 +++++----- packages/{squiggle-mc-cached => mc}/Cargo.nix | 83 ++++++++++--------- .../{squiggle-mc-cached => mc}/Cargo.toml | 14 ++-- packages/{squiggle-mc-cached => mc}/README.md | 8 +- packages/mc/cargo-refresh-nix.sh | 2 + .../{squiggle-mc-cached => mc}/js/index.js | 0 .../{squiggle-mc-cached => mc}/package.json | 2 +- .../src/distribution/bandwidth.rs | 0 .../src/distribution/e/mod.rs | 0 .../src/distribution/magic_numbers.rs | 0 .../src/distribution/mod.rs | 0 .../src/distribution/monte_carlo.rs | 0 .../{squiggle-mc-cached => mc}/src/lib.rs | 0 .../static/index.html | 0 .../{squiggle-mc-cached => mc}/tests/app.rs | 0 .../webpack.config.js | 0 packages/squiggle-lang/package.json | 2 +- packages/squiggle-mc-cached/.gitignore | 5 -- .../squiggle-mc-cached/cargo-refresh-nix.sh | 2 - 27 files changed, 168 insertions(+), 113 deletions(-) create mode 100644 nix/squiggle-mc.nix delete mode 100644 nix/squiggle-mcCache.nix create mode 100644 packages/mc/.gitignore rename packages/{squiggle-mc-cached => mc}/Cargo.lock (99%) rename packages/{squiggle-mc-cached => mc}/Cargo.nix (96%) rename packages/{squiggle-mc-cached => mc}/Cargo.toml (93%) rename packages/{squiggle-mc-cached => mc}/README.md (77%) create mode 100755 packages/mc/cargo-refresh-nix.sh rename packages/{squiggle-mc-cached => mc}/js/index.js (100%) rename packages/{squiggle-mc-cached => mc}/package.json (91%) rename packages/{squiggle-mc-cached => mc}/src/distribution/bandwidth.rs (100%) rename packages/{squiggle-mc-cached => mc}/src/distribution/e/mod.rs (100%) rename packages/{squiggle-mc-cached => mc}/src/distribution/magic_numbers.rs (100%) rename packages/{squiggle-mc-cached => mc}/src/distribution/mod.rs (100%) rename packages/{squiggle-mc-cached => mc}/src/distribution/monte_carlo.rs (100%) rename packages/{squiggle-mc-cached => mc}/src/lib.rs (100%) rename packages/{squiggle-mc-cached => mc}/static/index.html (100%) rename packages/{squiggle-mc-cached => mc}/tests/app.rs (100%) rename packages/{squiggle-mc-cached => mc}/webpack.config.js (100%) delete mode 100644 packages/squiggle-mc-cached/.gitignore delete mode 100755 packages/squiggle-mc-cached/cargo-refresh-nix.sh diff --git a/.gitignore b/.gitignore index 5b48f91c..a9914a6f 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ yarn-error.log **/.sync.ffs_db .direnv .log +result +result-bin diff --git a/flake.nix b/flake.nix index 49ef7a16..9f6e32ca 100644 --- a/flake.nix +++ b/flake.nix @@ -21,7 +21,8 @@ }; }; - outputs = { self, nixpkgs, gentype, hercules-ci-effects, cargo2nix, flake-utils, ... }: + outputs = { self, nixpkgs, gentype, hercules-ci-effects, cargo2nix + , flake-utils, ... }: let version = builtins.substring 0 8 self.lastModifiedDate; commonFn = pkgs: { @@ -30,29 +31,33 @@ which = [ pkgs.which ]; }; gentypeOutputFn = pkgs: gentype.outputs.packages.${pkgs.system}.default; - mcCacheFn = { pkgs, ... }: - import ./nix/squiggle-mcCache.nix { inherit pkgs; }; + mcFn = { pkgs, ... }: + import ./nix/squiggle-mc.nix { inherit pkgs commonFn; }; langFn = { pkgs, ... }: import ./nix/squiggle-lang.nix { - inherit pkgs commonFn mcCacheFn gentypeOutputFn; + inherit pkgs commonFn mcFn gentypeOutputFn; }; componentsFn = { pkgs, ... }: - import ./nix/squiggle-components.nix { inherit pkgs commonFn mcCacheFn langFn; }; + import ./nix/squiggle-components.nix { + inherit pkgs commonFn mcFn langFn; + }; websiteFn = { pkgs, ... }: import ./nix/squiggle-website.nix { - inherit pkgs commonFn mcCacheFn langFn componentsFn; + inherit pkgs commonFn mcFn langFn componentsFn; }; # local machines localFlake = { pkgs, ... }: let - mcCache = mcCacheFn pkgs; + 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; lang-lint = lang.lint; lang-test = lang.test; components-lint = components.lint; @@ -61,7 +66,8 @@ # building packages = flake-utils.lib.flattenTree { default = website.docusaurus; - mc-wasm = mcCache.mc-cached; + mc-wasm = mc.lib; + mc-wasm-pkg = mc.webpack-build-pkg; lang-bundle = lang.bundle; components = components.package-build; storybook = components.site-build; @@ -70,7 +76,8 @@ # developing devShells = flake-utils.lib.flattenTree { - default = (import ./nix/shell.nix { inherit pkgs cargo2nix; }).shell; + default = + (import ./nix/shell.nix { inherit pkgs cargo2nix; }).shell; }; }; @@ -79,6 +86,7 @@ hciSystem = "x86_64-linux"; hciPkgs = import nixpkgs { system = hciSystem; }; effects = hercules-ci-effects.lib.withPkgs hciPkgs; + mc = mcFn hciPkgs; lang = langFn hciPkgs; components = componentsFn hciPkgs; website = websiteFn hciPkgs; @@ -86,6 +94,11 @@ herculesCI = { ciSystems = [ hciSystem ]; onPush = { + wasm.outputs = { + squiggle-wasm-lint = mc.rust-lint; + squiggle-wasm-pkg = mc.webpack-build-pkg; + squiggle-wasm-test-ff = mc.rust-firefox-test; + }; lang.outputs = { squiggle-lang-lint = lang.lint; squiggle-lang-build = lang.build; diff --git a/nix/squiggle-components.nix b/nix/squiggle-components.nix index dcd82b05..566b7eb1 100644 --- a/nix/squiggle-components.nix +++ b/nix/squiggle-components.nix @@ -1,8 +1,8 @@ -{ pkgs, commonFn, mcCacheFn, langFn }: +{ pkgs, commonFn, mcFn, langFn }: rec { common = commonFn pkgs; - mcCache = mcCacheFn pkgs; + mc = mcFn pkgs; lang = langFn pkgs; componentsPackageJson = let raw = pkgs.lib.importJSON ../packages/components/package.json; @@ -12,11 +12,12 @@ rec { in pkgs.writeText "packages/components/patched-package.json" packageJsonString; yarn-source = pkgs.mkYarnPackage { - name = "squiggle-components_source"; + name = "squiggle-components_yarnsource"; buildInputs = common.buildInputs; src = ../packages/components; packageJSON = componentsPackageJson; yarnLock = ../yarn.lock; + packageResolutions."@quri/squiggle-mc" = mc.webpack-build-pkg; packageResolutions."@quri/squiggle-lang" = lang.build; }; lint = pkgs.stdenv.mkDerivation { diff --git a/nix/squiggle-lang.nix b/nix/squiggle-lang.nix index 8284d85c..bb5a21df 100644 --- a/nix/squiggle-lang.nix +++ b/nix/squiggle-lang.nix @@ -1,10 +1,10 @@ -{ pkgs, commonFn, mcCacheFn, gentypeOutputFn }: +{ pkgs, commonFn, mcFn, gentypeOutputFn }: rec { common = commonFn pkgs; - mcCache = mcCacheFn pkgs; + mc = mcFn pkgs; yarn-source = pkgs.mkYarnPackage { - name = "squiggle-lang_source"; + name = "squiggle-lang_yarnsource"; src = ../packages/squiggle-lang; packageJSON = ../packages/squiggle-lang/package.json; yarnLock = ../yarn.lock; @@ -23,8 +23,7 @@ rec { ''; }; bisect_ppx = { - buildInputs = - common.which; # ++ (with pkgs; [ ocaml nodePackages.esy ocamlPackages.bisect_ppx ]); + buildInputs = common.which; postInstall = '' echo "PATCHELF'ING BISECT_PPX EXECUTABLE" THE_LD=$(patchelf --print-interpreter $(which mkdir)) @@ -39,7 +38,7 @@ rec { ''; }; }; - packageResolutions."@quri/par-cached-monte-carlo" = mcCache.mc-cached; + packageResolutions."@quri/squiggle-mc" = mc.webpack-build-pkg; }; lint = pkgs.stdenv.mkDerivation { name = "squiggle-lang-lint"; diff --git a/nix/squiggle-mc.nix b/nix/squiggle-mc.nix new file mode 100644 index 00000000..27e2d4ed --- /dev/null +++ b/nix/squiggle-mc.nix @@ -0,0 +1,46 @@ +{ pkgs, commonFn }: + +rec { + common = commonFn pkgs; + rustPkgs = pkgs.rustBuilder.makePackageSet { + rustVersion = "1.60.0"; + packageFun = import ../packages/mc/Cargo.nix; + }; + yarn-source = pkgs.mkYarnPackage { + name = "squiggle-mc_yarnsource"; + buildInputs = common.buildInputs; + src = ../packages/mc; + packageJSON = ../packages/mc/package.json; + yarnLock = ../yarn.lock; + }; + rust-lint = pkgs.stdenv.mkDerivation { + name = "squiggle-mc-lint"; + src = yarn-source + "/libexec/@quri/squiggle-mc/deps/@quri/squiggle-mc"; + buildInputs = with pkgs; [ rustfmt ]; + 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"; + 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 { + 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"; + installPhase = "mkdir -p $out"; + }; +} diff --git a/nix/squiggle-mcCache.nix b/nix/squiggle-mcCache.nix deleted file mode 100644 index de337969..00000000 --- a/nix/squiggle-mcCache.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ pkgs }: - -rec { - rustPkgs = pkgs.rustBuilder.makePackageSet { - rustVersion = "1.60.0"; - packageFun = import ./../packages/squiggle-mc-cached/Cargo.nix; - }; - mc-cached = rustPkgs.workspace.squiggle-mc-cached-wasm {}; -} diff --git a/nix/squiggle-website.nix b/nix/squiggle-website.nix index 11abb1e9..df2eec54 100644 --- a/nix/squiggle-website.nix +++ b/nix/squiggle-website.nix @@ -1,8 +1,8 @@ -{ pkgs, commonFn, mcCacheFn, langFn, componentsFn }: +{ pkgs, commonFn, mcFn, langFn, componentsFn }: rec { common = commonFn pkgs; - mcCache = mcCacheFn pkgs; + mc = mcFn pkgs; lang = langFn pkgs; components = componentsFn pkgs; websitePackageJson = let @@ -14,13 +14,13 @@ rec { packageJsonString = builtins.toJSON modified; in pkgs.writeText "packages/website/patched-package.json" packageJsonString; yarn-source = pkgs.mkYarnPackage { - name = "squiggle-website_source"; + name = "squiggle-website_yarnsource"; src = ../packages/website; packageJSON = websitePackageJson; yarnLock = ../yarn.lock; + packageResolutions."@quri/squiggle-mc" = mc.webpack-build-pkg + "/pkg"; packageResolutions."@quri/squiggle-lang" = lang.build; packageResolutions."@quri/squiggle-components" = components.package-build; - workspaceDependencies = [ lang.yarn-source components.yarn-source ]; }; lint = pkgs.stdenv.mkDerivation { name = "squiggle-website-lint"; diff --git a/packages/mc/.gitignore b/packages/mc/.gitignore new file mode 100644 index 00000000..335b7dc3 --- /dev/null +++ b/packages/mc/.gitignore @@ -0,0 +1,5 @@ +node_modules +dist +target +pkg +wasm-pack.log diff --git a/packages/squiggle-mc-cached/Cargo.lock b/packages/mc/Cargo.lock similarity index 99% rename from packages/squiggle-mc-cached/Cargo.lock rename to packages/mc/Cargo.lock index 1b401384..5762451a 100644 --- a/packages/squiggle-mc-cached/Cargo.lock +++ b/packages/mc/Cargo.lock @@ -448,6 +448,28 @@ dependencies = [ "proc-macro2 1.0.43", ] +[[package]] +name = "quri-squiggle-mc" +version = "0.0.1" +dependencies = [ + "cached", + "console_error_panic_hook", + "futures 0.1.31", + "getrandom", + "js-sys", + "kernel_density", + "quickcheck", + "quickcheck_macros", + "rand 0.8.5", + "rand_distr", + "statistics", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-bindgen-test", + "web-sys", + "wee_alloc", +] + [[package]] name = "rand" version = "0.3.23" @@ -558,28 +580,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" -[[package]] -name = "squiggle-mc-cached-wasm" -version = "0.0.1" -dependencies = [ - "cached", - "console_error_panic_hook", - "futures 0.1.31", - "getrandom", - "js-sys", - "kernel_density", - "quickcheck", - "quickcheck_macros", - "rand 0.8.5", - "rand_distr", - "statistics", - "wasm-bindgen", - "wasm-bindgen-futures", - "wasm-bindgen-test", - "web-sys", - "wee_alloc", -] - [[package]] name = "statistics" version = "0.4.1" diff --git a/packages/squiggle-mc-cached/Cargo.nix b/packages/mc/Cargo.nix similarity index 96% rename from packages/squiggle-mc-cached/Cargo.nix rename to packages/mc/Cargo.nix index 3769210f..1fee7081 100644 --- a/packages/squiggle-mc-cached/Cargo.nix +++ b/packages/mc/Cargo.nix @@ -4,7 +4,7 @@ args@{ release ? true, rootFeatures ? [ - "squiggle-mc-cached-wasm/default" + "quri-squiggle-mc/default" ], rustPackages, buildRustPackages, @@ -38,7 +38,7 @@ in { cargo2nixVersion = "0.11.0"; workspace = { - squiggle-mc-cached-wasm = rustPackages.unknown.squiggle-mc-cached-wasm."0.0.1"; + quri-squiggle-mc = rustPackages.unknown.quri-squiggle-mc."0.0.1"; }; "registry+https://github.com/rust-lang/crates.io-index".aho-corasick."0.7.18" = overridableMkRustCrate (profileName: rec { name = "aho-corasick"; @@ -659,6 +659,37 @@ in }; }); + "unknown".quri-squiggle-mc."0.0.1" = overridableMkRustCrate (profileName: rec { + name = "quri-squiggle-mc"; + version = "0.0.1"; + registry = "unknown"; + src = fetchCrateLocal workspaceSrc; + features = builtins.concatLists [ + (lib.optional (rootFeatures' ? "quri-squiggle-mc/default") "default") + (lib.optional (rootFeatures' ? "quri-squiggle-mc/default" || rootFeatures' ? "quri-squiggle-mc/wee_alloc") "wee_alloc") + ]; + dependencies = { + cached = rustPackages."registry+https://github.com/rust-lang/crates.io-index".cached."0.38.0" { inherit profileName; }; + ${ if false then "console_error_panic_hook" else null } = rustPackages."registry+https://github.com/rust-lang/crates.io-index".console_error_panic_hook."0.1.7" { inherit profileName; }; + getrandom = rustPackages."registry+https://github.com/rust-lang/crates.io-index".getrandom."0.2.7" { inherit profileName; }; + kernel_density = rustPackages."registry+https://github.com/rust-lang/crates.io-index".kernel_density."0.0.1" { inherit profileName; }; + rand = rustPackages."registry+https://github.com/rust-lang/crates.io-index".rand."0.8.5" { inherit profileName; }; + rand_distr = rustPackages."registry+https://github.com/rust-lang/crates.io-index".rand_distr."0.4.3" { inherit profileName; }; + statistics = rustPackages."registry+https://github.com/rust-lang/crates.io-index".statistics."0.4.1" { inherit profileName; }; + wasm_bindgen = rustPackages."registry+https://github.com/rust-lang/crates.io-index".wasm-bindgen."0.2.82" { inherit profileName; }; + web_sys = rustPackages."registry+https://github.com/rust-lang/crates.io-index".web-sys."0.3.59" { inherit profileName; }; + ${ if rootFeatures' ? "quri-squiggle-mc/default" || rootFeatures' ? "quri-squiggle-mc/wee_alloc" then "wee_alloc" else null } = rustPackages."registry+https://github.com/rust-lang/crates.io-index".wee_alloc."0.4.5" { inherit profileName; }; + }; + devDependencies = { + futures = rustPackages."registry+https://github.com/rust-lang/crates.io-index".futures."0.1.31" { inherit profileName; }; + js_sys = rustPackages."registry+https://github.com/rust-lang/crates.io-index".js-sys."0.3.59" { inherit profileName; }; + quickcheck = rustPackages."registry+https://github.com/rust-lang/crates.io-index".quickcheck."1.0.3" { inherit profileName; }; + quickcheck_macros = buildRustPackages."registry+https://github.com/rust-lang/crates.io-index".quickcheck_macros."1.0.0" { profileName = "__noProfile"; }; + wasm_bindgen_futures = rustPackages."registry+https://github.com/rust-lang/crates.io-index".wasm-bindgen-futures."0.3.27" { inherit profileName; }; + wasm_bindgen_test = rustPackages."registry+https://github.com/rust-lang/crates.io-index".wasm-bindgen-test."0.2.50" { inherit profileName; }; + }; + }); + "registry+https://github.com/rust-lang/crates.io-index".rand."0.3.23" = overridableMkRustCrate (profileName: rec { name = "rand"; version = "0.3.23"; @@ -823,36 +854,6 @@ in src = fetchCratesIo { inherit name version; sha256 = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2"; }; }); - "unknown".squiggle-mc-cached-wasm."0.0.1" = overridableMkRustCrate (profileName: rec { - name = "squiggle-mc-cached-wasm"; - version = "0.0.1"; - registry = "unknown"; - src = fetchCrateLocal workspaceSrc; - features = builtins.concatLists [ - (lib.optional (rootFeatures' ? "squiggle-mc-cached-wasm/wee_alloc") "wee_alloc") - ]; - dependencies = { - cached = rustPackages."registry+https://github.com/rust-lang/crates.io-index".cached."0.38.0" { inherit profileName; }; - ${ if false then "console_error_panic_hook" else null } = rustPackages."registry+https://github.com/rust-lang/crates.io-index".console_error_panic_hook."0.1.7" { inherit profileName; }; - getrandom = rustPackages."registry+https://github.com/rust-lang/crates.io-index".getrandom."0.2.7" { inherit profileName; }; - kernel_density = rustPackages."registry+https://github.com/rust-lang/crates.io-index".kernel_density."0.0.1" { inherit profileName; }; - rand = rustPackages."registry+https://github.com/rust-lang/crates.io-index".rand."0.8.5" { inherit profileName; }; - rand_distr = rustPackages."registry+https://github.com/rust-lang/crates.io-index".rand_distr."0.4.3" { inherit profileName; }; - statistics = rustPackages."registry+https://github.com/rust-lang/crates.io-index".statistics."0.4.1" { inherit profileName; }; - wasm_bindgen = rustPackages."registry+https://github.com/rust-lang/crates.io-index".wasm-bindgen."0.2.82" { inherit profileName; }; - web_sys = rustPackages."registry+https://github.com/rust-lang/crates.io-index".web-sys."0.3.59" { inherit profileName; }; - ${ if rootFeatures' ? "squiggle-mc-cached-wasm/wee_alloc" then "wee_alloc" else null } = rustPackages."registry+https://github.com/rust-lang/crates.io-index".wee_alloc."0.4.5" { inherit profileName; }; - }; - devDependencies = { - futures = rustPackages."registry+https://github.com/rust-lang/crates.io-index".futures."0.1.31" { inherit profileName; }; - js_sys = rustPackages."registry+https://github.com/rust-lang/crates.io-index".js-sys."0.3.59" { inherit profileName; }; - quickcheck = rustPackages."registry+https://github.com/rust-lang/crates.io-index".quickcheck."1.0.3" { inherit profileName; }; - quickcheck_macros = buildRustPackages."registry+https://github.com/rust-lang/crates.io-index".quickcheck_macros."1.0.0" { profileName = "__noProfile"; }; - wasm_bindgen_futures = rustPackages."registry+https://github.com/rust-lang/crates.io-index".wasm-bindgen-futures."0.3.27" { inherit profileName; }; - wasm_bindgen_test = rustPackages."registry+https://github.com/rust-lang/crates.io-index".wasm-bindgen-test."0.2.50" { inherit profileName; }; - }; - }); - "registry+https://github.com/rust-lang/crates.io-index".statistics."0.4.1" = overridableMkRustCrate (profileName: rec { name = "statistics"; version = "0.4.1"; @@ -1139,14 +1140,14 @@ in registry = "registry+https://github.com/rust-lang/crates.io-index"; src = fetchCratesIo { inherit name version; sha256 = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e"; }; features = builtins.concatLists [ - (lib.optional (rootFeatures' ? "squiggle-mc-cached-wasm/wee_alloc") "default") - (lib.optional (rootFeatures' ? "squiggle-mc-cached-wasm/wee_alloc") "size_classes") + (lib.optional (rootFeatures' ? "quri-squiggle-mc/default" || rootFeatures' ? "quri-squiggle-mc/wee_alloc") "default") + (lib.optional (rootFeatures' ? "quri-squiggle-mc/default" || rootFeatures' ? "quri-squiggle-mc/wee_alloc") "size_classes") ]; dependencies = { - ${ if rootFeatures' ? "squiggle-mc-cached-wasm/wee_alloc" then "cfg_if" else null } = rustPackages."registry+https://github.com/rust-lang/crates.io-index".cfg-if."0.1.10" { inherit profileName; }; - ${ if rootFeatures' ? "squiggle-mc-cached-wasm/wee_alloc" && hostPlatform.isUnix && !(hostPlatform.parsed.cpu.name == "wasm32") then "libc" else null } = rustPackages."registry+https://github.com/rust-lang/crates.io-index".libc."0.2.132" { inherit profileName; }; - ${ if rootFeatures' ? "squiggle-mc-cached-wasm/wee_alloc" then "memory_units" else null } = rustPackages."registry+https://github.com/rust-lang/crates.io-index".memory_units."0.4.0" { inherit profileName; }; - ${ if rootFeatures' ? "squiggle-mc-cached-wasm/wee_alloc" && hostPlatform.parsed.kernel.name == "windows" then "winapi" else null } = rustPackages."registry+https://github.com/rust-lang/crates.io-index".winapi."0.3.9" { inherit profileName; }; + ${ if rootFeatures' ? "quri-squiggle-mc/default" || rootFeatures' ? "quri-squiggle-mc/wee_alloc" then "cfg_if" else null } = rustPackages."registry+https://github.com/rust-lang/crates.io-index".cfg-if."0.1.10" { inherit profileName; }; + ${ if (rootFeatures' ? "quri-squiggle-mc/default" || rootFeatures' ? "quri-squiggle-mc/wee_alloc") && hostPlatform.isUnix && !(hostPlatform.parsed.cpu.name == "wasm32") then "libc" else null } = rustPackages."registry+https://github.com/rust-lang/crates.io-index".libc."0.2.132" { inherit profileName; }; + ${ if rootFeatures' ? "quri-squiggle-mc/default" || rootFeatures' ? "quri-squiggle-mc/wee_alloc" then "memory_units" else null } = rustPackages."registry+https://github.com/rust-lang/crates.io-index".memory_units."0.4.0" { inherit profileName; }; + ${ if (rootFeatures' ? "quri-squiggle-mc/default" || rootFeatures' ? "quri-squiggle-mc/wee_alloc") && hostPlatform.parsed.kernel.name == "windows" then "winapi" else null } = rustPackages."registry+https://github.com/rust-lang/crates.io-index".winapi."0.3.9" { inherit profileName; }; }; }); @@ -1156,12 +1157,12 @@ in registry = "registry+https://github.com/rust-lang/crates.io-index"; src = fetchCratesIo { inherit name version; sha256 = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"; }; features = builtins.concatLists [ - (lib.optional (rootFeatures' ? "squiggle-mc-cached-wasm/wee_alloc") "memoryapi") + (lib.optional (rootFeatures' ? "quri-squiggle-mc/default" || rootFeatures' ? "quri-squiggle-mc/wee_alloc") "memoryapi") [ "minwindef" ] [ "ntsecapi" ] [ "profileapi" ] - (lib.optional (rootFeatures' ? "squiggle-mc-cached-wasm/wee_alloc") "synchapi") - (lib.optional (rootFeatures' ? "squiggle-mc-cached-wasm/wee_alloc") "winbase") + (lib.optional (rootFeatures' ? "quri-squiggle-mc/default" || rootFeatures' ? "quri-squiggle-mc/wee_alloc") "synchapi") + (lib.optional (rootFeatures' ? "quri-squiggle-mc/default" || rootFeatures' ? "quri-squiggle-mc/wee_alloc") "winbase") [ "winnt" ] ]; dependencies = { diff --git a/packages/squiggle-mc-cached/Cargo.toml b/packages/mc/Cargo.toml similarity index 93% rename from packages/squiggle-mc-cached/Cargo.toml rename to packages/mc/Cargo.toml index c41493d2..fc8d1b9a 100644 --- a/packages/squiggle-mc-cached/Cargo.toml +++ b/packages/mc/Cargo.toml @@ -1,6 +1,6 @@ # You must change these to your own details. [package] -name = "squiggle-mc-cached-wasm" +name = "quri-squiggle-mc" description = "Cached and parallel Monte Carlo simulations in WebAssembly" version = "0.0.1" authors = ["Quinn "] @@ -20,13 +20,17 @@ lto = true [features] # If you uncomment this line, it will enable `wee_alloc`: -#default = ["wee_alloc"] +default = ["wee_alloc"] [dependencies] # The `wasm-bindgen` crate provides the bare minimum functionality needed # to interact with JavaScript. wasm-bindgen = "0.2.45" +# The `web-sys` crate allows you to interact with the various browser APIs, +# like the DOM. +web-sys = { version = "0.3.59", features = ["console"] } + # `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. @@ -40,12 +44,6 @@ statistics = "0.4.1" kernel_density = "0.0.1" cached = { version = "0.38.0", features = ["wasm"] } -# The `web-sys` crate allows you to interact with the various browser APIs, -# like the DOM. -[dependencies.web-sys] -version = "0.3.22" -features = ["console"] - # 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 diff --git a/packages/squiggle-mc-cached/README.md b/packages/mc/README.md similarity index 77% rename from packages/squiggle-mc-cached/README.md rename to packages/mc/README.md index 10a2fd68..8cd764b5 100644 --- a/packages/squiggle-mc-cached/README.md +++ b/packages/mc/README.md @@ -1,8 +1,10 @@ -# `@quri/par-cached-monte-carlo` - parallel Monte Carlo with memoization +# `@quri/squiggle-mc` - parallel Monte Carlo with memoization for the `@quri/squiggle-lang` javascript interface ## How to install -Please run `yarn` at hte monorepo level +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. ## How to run in debug mode @@ -20,6 +22,8 @@ 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 diff --git a/packages/mc/cargo-refresh-nix.sh b/packages/mc/cargo-refresh-nix.sh new file mode 100755 index 00000000..0437d6b6 --- /dev/null +++ b/packages/mc/cargo-refresh-nix.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +nix run github:cargo2nix/cargo2nix diff --git a/packages/squiggle-mc-cached/js/index.js b/packages/mc/js/index.js similarity index 100% rename from packages/squiggle-mc-cached/js/index.js rename to packages/mc/js/index.js diff --git a/packages/squiggle-mc-cached/package.json b/packages/mc/package.json similarity index 91% rename from packages/squiggle-mc-cached/package.json rename to packages/mc/package.json index 7ba8e061..90ec463a 100644 --- a/packages/squiggle-mc-cached/package.json +++ b/packages/mc/package.json @@ -1,6 +1,6 @@ { "author": "Quinn Dougherty ", - "name": "@quri/par-cached-monte-carlo", + "name": "@quri/squiggle-mc", "version": "0.0.1", "scripts": { "build": "rimraf dist pkg && webpack", diff --git a/packages/squiggle-mc-cached/src/distribution/bandwidth.rs b/packages/mc/src/distribution/bandwidth.rs similarity index 100% rename from packages/squiggle-mc-cached/src/distribution/bandwidth.rs rename to packages/mc/src/distribution/bandwidth.rs diff --git a/packages/squiggle-mc-cached/src/distribution/e/mod.rs b/packages/mc/src/distribution/e/mod.rs similarity index 100% rename from packages/squiggle-mc-cached/src/distribution/e/mod.rs rename to packages/mc/src/distribution/e/mod.rs diff --git a/packages/squiggle-mc-cached/src/distribution/magic_numbers.rs b/packages/mc/src/distribution/magic_numbers.rs similarity index 100% rename from packages/squiggle-mc-cached/src/distribution/magic_numbers.rs rename to packages/mc/src/distribution/magic_numbers.rs diff --git a/packages/squiggle-mc-cached/src/distribution/mod.rs b/packages/mc/src/distribution/mod.rs similarity index 100% rename from packages/squiggle-mc-cached/src/distribution/mod.rs rename to packages/mc/src/distribution/mod.rs diff --git a/packages/squiggle-mc-cached/src/distribution/monte_carlo.rs b/packages/mc/src/distribution/monte_carlo.rs similarity index 100% rename from packages/squiggle-mc-cached/src/distribution/monte_carlo.rs rename to packages/mc/src/distribution/monte_carlo.rs diff --git a/packages/squiggle-mc-cached/src/lib.rs b/packages/mc/src/lib.rs similarity index 100% rename from packages/squiggle-mc-cached/src/lib.rs rename to packages/mc/src/lib.rs diff --git a/packages/squiggle-mc-cached/static/index.html b/packages/mc/static/index.html similarity index 100% rename from packages/squiggle-mc-cached/static/index.html rename to packages/mc/static/index.html diff --git a/packages/squiggle-mc-cached/tests/app.rs b/packages/mc/tests/app.rs similarity index 100% rename from packages/squiggle-mc-cached/tests/app.rs rename to packages/mc/tests/app.rs diff --git a/packages/squiggle-mc-cached/webpack.config.js b/packages/mc/webpack.config.js similarity index 100% rename from packages/squiggle-mc-cached/webpack.config.js rename to packages/mc/webpack.config.js diff --git a/packages/squiggle-lang/package.json b/packages/squiggle-lang/package.json index de23a37f..fdc494a8 100644 --- a/packages/squiggle-lang/package.json +++ b/packages/squiggle-lang/package.json @@ -41,7 +41,7 @@ ], "author": "Quantified Uncertainty Research Institute", "dependencies": { - "@quri/par-cached-monte-carlo": "file:../squiggle-mc-cached/pkg", + "@quri/squiggle-mc": "^0.0.1", "@rescript/std": "^9.1.4", "@stdlib/stats": "^0.0.13", "jstat": "^1.9.5", diff --git a/packages/squiggle-mc-cached/.gitignore b/packages/squiggle-mc-cached/.gitignore deleted file mode 100644 index 33a3be33..00000000 --- a/packages/squiggle-mc-cached/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -node_modules -/dist -/target -/pkg -/wasm-pack.log diff --git a/packages/squiggle-mc-cached/cargo-refresh-nix.sh b/packages/squiggle-mc-cached/cargo-refresh-nix.sh deleted file mode 100755 index 73d1404b..00000000 --- a/packages/squiggle-mc-cached/cargo-refresh-nix.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -cargo2nix