first commit: mc-cached-wasm

This commit is contained in:
Quinn Dougherty 2022-08-15 19:38:25 -07:00
parent 1cd10a9cad
commit a635219f46
19 changed files with 15311 additions and 14083 deletions

View File

@ -1,5 +1,20 @@
{
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1659877975,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"gentype": {
"inputs": {
"nixpkgs": [
@ -42,21 +57,22 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1660485612,
"narHash": "sha256-sSLW1KaB1adKTJn9+Ja3h3AaS7QCZyhUKiSUStcLg80=",
"lastModified": 1660496378,
"narHash": "sha256-sgAhmrC1iSnl5T2VPPiMpciH1aRw5c7PYEdXX6jd6Gk=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "6512b21eabb4d52e87ea2edcf31a288e67b2e4f8",
"rev": "879121648fe522b38cc1cf75aef160a14a1f2e7b",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-unstable",
"ref": "nixos-22.05",
"type": "indirect"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"gentype": "gentype",
"hercules-ci-effects": "hercules-ci-effects",
"nixpkgs": "nixpkgs"

View File

@ -3,7 +3,7 @@
# Derived from https://gitlab.com/Silvers_Gw2/Stats_Frontend/-/blob/cc5d783abd54e95363410592c390ca6925462262/flake.nix
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
nixpkgs.url = "nixpkgs/nixos-22.05";
gentype = {
url = "github:quinn-dougherty/genType";
inputs.nixpkgs.follows = "nixpkgs";
@ -12,16 +12,20 @@
url = "github:hercules-ci/hercules-ci-effects";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils = {
url = "github:numtide/flake-utils";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, gentype, hercules-ci-effects, ... }:
outputs = { self, nixpkgs, gentype, hercules-ci-effects, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
# globals
system = "x86_64-linux";
hciSystem = "x86_64-linux";
pkgs = import nixpkgs {
system = system;
overlays = [
hercules-ci-effects.overlay
(final: prev: {
# set the node version here
nodejs = prev.nodejs-16_x;
@ -29,6 +33,9 @@
})
];
};
hciPkgs = import nixpkgs { system = hciSystem; };
effects = hercules-ci-effects.lib.withPkgs hciPkgs;
buildInputsCommon = with pkgs; [ nodejs yarn ];
prettierCommon = with pkgs.nodePackages; [ prettier ];
pkgWhich = [ pkgs.which ];
@ -155,13 +162,14 @@
'';
};
componentsPackageJson =
let
componentsPackageJson = let
raw = pkgs.lib.importJSON ./packages/components/package.json;
modified = pkgs.lib.recursiveUpdate raw { dependencies.react-dom = "^18.2.0"; };
modified = pkgs.lib.recursiveUpdate raw {
dependencies.react-dom = "^18.2.0";
};
packageJsonString = builtins.toJSON modified;
in
pkgs.writeText "packages/components/patched-package.json" packageJsonString;
in pkgs.writeText "packages/components/patched-package.json"
packageJsonString;
components-yarnPackage = pkgs.mkYarnPackage {
name = "squiggle-components_source";
buildInputs = buildInputsCommon;
@ -216,16 +224,15 @@
'';
};
websitePackageJson =
let
websitePackageJson = let
raw = pkgs.lib.importJSON ./packages/website/package.json;
modified = pkgs.lib.recursiveUpdate raw {
dependencies.postcss-import = "^14.1.0";
dependencies.tailwindcss = "^3.1.8";
};
packageJsonString = builtins.toJSON modified;
in
pkgs.writeText "packages/website/patched-package.json" packageJsonString;
in pkgs.writeText "packages/website/patched-package.json"
packageJsonString;
website-yarnPackage = pkgs.mkYarnPackage {
name = "squiggle-website_source";
src = ./packages/website;
@ -260,13 +267,13 @@
};
in rec {
checks.${system} = {
checks = flake-utils.lib.flattenTree {
lang-lint = lang-lint;
lang-test = lang-test;
components-lint = components-lint;
docusaurus-lint = website-lint;
};
packages.${system} = {
packages = flake-utils.lib.flattenTree {
default = website;
lang-bundle = lang-bundle;
components = components-package-build;
@ -282,19 +289,19 @@
# herc
herculesCI.onPush = {
lang.outputs = {
squiggle-lang-lint = checks.${system}.lang-lint;
squiggle-lang-test = checks.${system}.lang-test;
squiggle-lang-lint = checks.${hciSystem}.lang-lint;
squiggle-lang-test = checks.${hciSystem}.lang-test;
squiggle-lang-build = lang-build;
squiggle-lang-bundle = packages.${system}.lang-bundle;
squiggle-lang-bundle = packages.${hciSystem}.lang-bundle;
};
components.outputs = {
squiggle-components = packages.${system}.components;
squiggle-components-lint = checks.${system}.components-lint;
squiggle-components-storybook = packages.${system}.storybook;
squiggle-components = packages.${hciSystem}.components;
squiggle-components-lint = checks.${hciSystem}.components-lint;
squiggle-components-storybook = packages.${hciSystem}.storybook;
};
docs-site.outputs = {
squiggle-website = packages.${system}.docs-site;
docusaurus-lint = checks.${system}.docusaurus-lint;
squiggle-website = packages.${hciSystem}.docs-site;
docusaurus-lint = checks.${hciSystem}.docusaurus-lint;
};
};
devShells.${system}.default = pkgs.mkShell {
@ -309,5 +316,5 @@
openssl
];
};
};
});
}

View File

@ -1,6 +0,0 @@
/target
**/*.rs.bk
Cargo.lock
bin/
pkg/
wasm-pack.log

View File

@ -1,40 +0,0 @@
[package]
name = "rust"
version = "0.1.0"
authors = ["Quinn Dougherty <quinnd@riseup.net>"]
edition = "2018"
[package.metadata.wasm-pack.profile]
dev.wasm-opt = false
profiling.wasm-opt = false
release.wasm-opt = false
[lib]
crate-type = ["cdylib", "rlib"]
[features]
default = ["console_error_panic_hook"]
[dependencies]
getrandom = { version = "0.2", features = ["js"] }
rand_distr = "0.4.3"
wasm-bindgen = "0.2.63"
# 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 isn't great for
# code size when deploying.
console_error_panic_hook = { version = "0.1.6", optional = true }
# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size
# compared to the default allocator's ~10K. It is slower than the default
# allocator, however.
#
# Unfortunately, `wee_alloc` requires nightly Rust when targeting wasm for now.
wee_alloc = { version = "0.4.5", optional = true }
[dev-dependencies]
wasm-bindgen-test = "0.3.13"
[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"

View File

@ -1,69 +0,0 @@
<div align="center">
<h1><code>wasm-pack-template</code></h1>
<strong>A template for kick starting a Rust and WebAssembly project using <a href="https://github.com/rustwasm/wasm-pack">wasm-pack</a>.</strong>
<p>
<a href="https://travis-ci.org/rustwasm/wasm-pack-template"><img src="https://img.shields.io/travis/rustwasm/wasm-pack-template.svg?style=flat-square" alt="Build Status" /></a>
</p>
<h3>
<a href="https://rustwasm.github.io/docs/wasm-pack/tutorials/npm-browser-packages/index.html">Tutorial</a>
<span> | </span>
<a href="https://discordapp.com/channels/442252698964721669/443151097398296587">Chat</a>
</h3>
<sub>Built with 🦀🕸 by <a href="https://rustwasm.github.io/">The Rust and WebAssembly Working Group</a></sub>
</div>
## About
[**📚 Read this template tutorial! 📚**][template-docs]
This template is designed for compiling Rust libraries into WebAssembly and
publishing the resulting package to NPM.
Be sure to check out [other `wasm-pack` tutorials online][tutorials] for other
templates and usages of `wasm-pack`.
[tutorials]: https://rustwasm.github.io/docs/wasm-pack/tutorials/index.html
[template-docs]: https://rustwasm.github.io/docs/wasm-pack/tutorials/npm-browser-packages/index.html
## 🚴 Usage
### 🐑 Use `cargo generate` to Clone this Template
[Learn more about `cargo generate` here.](https://github.com/ashleygwilliams/cargo-generate)
```
cargo generate --git https://github.com/rustwasm/wasm-pack-template.git --name my-project
cd my-project
```
### 🛠️ Build with `wasm-pack build`
```
wasm-pack build
```
### 🔬 Test in Headless Browsers with `wasm-pack test`
```
wasm-pack test --headless --firefox
```
### 🎁 Publish to NPM with `wasm-pack publish`
```
wasm-pack publish
```
## 🔋 Batteries Included
* [`wasm-bindgen`](https://github.com/rustwasm/wasm-bindgen) for communicating
between WebAssembly and JavaScript.
* [`console_error_panic_hook`](https://github.com/rustwasm/console_error_panic_hook)
for logging panic messages to the developer console.
* [`wee_alloc`](https://github.com/rustwasm/wee_alloc), an allocator optimized
for small code size.

View File

@ -1,23 +0,0 @@
mod utils;
use wasm_bindgen::prelude::*;
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
// allocator.
#[cfg(feature = "wee_alloc")]
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
#[wasm_bindgen]
extern {
fn alert(s: &str);
}
// implement monte carlo in rust
//
#[wasm_bindgen]
pub fn greet() {
alert("Hello, rust!");
}

View File

@ -1,10 +0,0 @@
pub fn set_panic_hook() {
// When the `console_error_panic_hook` feature is enabled, we can call the
// `set_panic_hook` function at least once during initialization, and then
// we will get better error messages if our code ever panics.
//
// For more details see
// https://github.com/rustwasm/console_error_panic_hook#readme
#[cfg(feature = "console_error_panic_hook")]
console_error_panic_hook::set_once();
}

View File

@ -1,13 +0,0 @@
//! Test suite for the Web and headless browsers.
#![cfg(target_arch = "wasm32")]
extern crate wasm_bindgen_test;
use wasm_bindgen_test::*;
wasm_bindgen_test_configure!(run_in_browser);
#[wasm_bindgen_test]
fn pass() {
assert_eq!(1 + 1, 2);
}

View File

@ -1,15 +0,0 @@
{ pkgs ? import <nixpkgs> {} }:
with pkgs;
mkShell {
buildInputs = [
wasm-pack
cargo-generate
nodePackages.npm
rustup
cargo
pkg-config
openssl
];
}

View File

@ -0,0 +1,5 @@
node_modules
/dist
/target
/pkg
/wasm-pack.log

View File

@ -0,0 +1,55 @@
# You must change these to your own details.
[package]
name = "squiggle-mc-cached-wasm"
description = "Caching for Monte Carlo simulations in WebAssembly"
version = "0.0.1"
authors = ["Quinn <quinn@quantifieduncertainty.org>"]
categories = ["wasm"]
readme = "README.md"
edition = "2018"
[lib]
crate-type = ["cdylib"]
[profile.release]
# This makes the compiled code faster and smaller, but it makes compiling slower,
# so it's only enabled in release mode.
lto = true
[features]
# If you uncomment this line, it will enable `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"
# `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.
wee_alloc = { version = "0.4.2", optional = true }
# Numerical things
getrandom = { version = "0.2", features = ["js"] }
rand_distr = "0.4.3"
# 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
# in debug mode.
[target."cfg(debug_assertions)".dependencies]
console_error_panic_hook = "0.1.5"
# These crates are used for running unit tests.
[dev-dependencies]
wasm-bindgen-test = "0.2.45"
futures = "0.1.27"
js-sys = "0.3.22"
wasm-bindgen-futures = "0.3.22"

View File

@ -0,0 +1,48 @@
## How to install
```sh
npm install
```
## How to run in debug mode
```sh
# Builds the project and opens it in a new browser tab. Auto-reloads when the project changes.
npm start
```
## How to build in release mode
```sh
# Builds the project and places it into the `dist` folder.
npm run build
```
## How to run unit tests
```sh
# Runs tests in Firefox
npm test -- --firefox
# Runs tests in Chrome
npm test -- --chrome
# Runs tests in Safari
npm 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.

View File

@ -0,0 +1 @@
import("../pkg/index.js").catch(console.error);

View File

@ -0,0 +1,18 @@
{
"author": "You <you@example.com>",
"name": "rust-webpack-template",
"version": "0.1.0",
"scripts": {
"build": "rimraf dist pkg && webpack",
"start": "rimraf dist pkg && webpack-dev-server --open -d",
"test": "cargo test && wasm-pack test --headless"
},
"devDependencies": {
"@wasm-tool/wasm-pack-plugin": "^1.1.0",
"copy-webpack-plugin": "^5.0.3",
"webpack": "^4.42.0",
"webpack-cli": "^3.3.3",
"webpack-dev-server": "^3.7.1",
"rimraf": "^3.0.0"
}
}

View File

@ -0,0 +1,27 @@
use wasm_bindgen::prelude::*;
use web_sys::console;
// When the `wee_alloc` feature is enabled, this uses `wee_alloc` as the global
// allocator.
//
// If you don't want to use `wee_alloc`, you can safely delete this.
#[cfg(feature = "wee_alloc")]
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
// This is like the `main` function, except for JavaScript.
#[wasm_bindgen(start)]
pub fn main_js() -> Result<(), JsValue> {
// This provides better error messages in debug mode.
// It's disabled in release mode so it doesn't bloat up the file size.
#[cfg(debug_assertions)]
console_error_panic_hook::set_once();
// Your code goes here!
console::log_1(&JsValue::from_str("Hello world!"));
Ok(())
}

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>My Rust + Webpack project!</title>
</head>
<body>
<script src="index.js"></script>
</body>
</html>

View File

@ -0,0 +1,35 @@
use wasm_bindgen_test::{wasm_bindgen_test_configure, wasm_bindgen_test};
use futures::prelude::*;
use wasm_bindgen::JsValue;
use wasm_bindgen_futures::JsFuture;
wasm_bindgen_test_configure!(run_in_browser);
// This runs a unit test in native Rust, so it can only use Rust APIs.
#[test]
fn rust_test() {
assert_eq!(1, 1);
}
// This runs a unit test in the browser, so it can use browser APIs.
#[wasm_bindgen_test]
fn web_test() {
assert_eq!(1, 1);
}
// This runs a unit test in the browser, and in addition it supports asynchronous Future APIs.
#[wasm_bindgen_test(async)]
fn async_test() -> impl Future<Item = (), Error = JsValue> {
// Creates a JavaScript Promise which will asynchronously resolve with the value 42.
let promise = js_sys::Promise::resolve(&JsValue::from(42));
// Converts that Promise into a Future.
// The unit test will wait for the Future to resolve.
JsFuture::from(promise)
.map(|x| {
assert_eq!(x, 42);
})
}

View File

@ -0,0 +1,28 @@
const path = require("path");
const CopyPlugin = require("copy-webpack-plugin");
const WasmPackPlugin = require("@wasm-tool/wasm-pack-plugin");
const dist = path.resolve(__dirname, "dist");
module.exports = {
mode: "production",
entry: {
index: "./js/index.js"
},
output: {
path: dist,
filename: "[name].js"
},
devServer: {
contentBase: dist,
},
plugins: [
new CopyPlugin([
path.resolve(__dirname, "static")
]),
new WasmPackPlugin({
crateDirectory: __dirname,
}),
]
};

28420
yarn.lock

File diff suppressed because it is too large Load Diff