Skip to content

Commit

Permalink
Start of wasm build
Browse files Browse the repository at this point in the history
  • Loading branch information
prozacchiwawa committed Sep 20, 2024
1 parent f63e0d7 commit e639ac8
Show file tree
Hide file tree
Showing 19 changed files with 6,569 additions and 5 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/wasm-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: npm publish

on:
push:
branches:
- base
release:
types: [published]
pull_request:
branches:
- '**'

concurrency:
# SHA is added to the end if on `main` to let all main workflows run
group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }}-${{ (github.ref == 'refs/heads/main') && github.sha || '' }}
cancel-in-progress: true

jobs:
build_npm:
name: Npm
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set Env
uses: Chia-Network/actions/setjobenv@main
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Set up rusts
uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy

- name: install wasm-pack
run: cargo install --version 0.11.1 wasm-pack

- name: wasm-pack build and pack
run: wasm-pack build --release --target=nodejs wasm && wasm-pack pack wasm

- name: Setup Node 16.x
uses: actions/setup-node@v3
with:
node-version: '16.x'
run: cd wasm/tests && yarn test
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"
[features]
sim-tests = ["dep:pyo3"]
simulator = ["dep:pyo3"]
server = ["dep:tokio","dep:salvo","dep:ctor"]

[dependencies]
clvm_tools_rs = { git = "https://github.com/Chia-Network/clvm_tools_rs.git", rev = "ec75759377791c9b785123d2d3e2457d08ac6621" }
Expand All @@ -26,14 +27,13 @@ sha2 = "0.10.8"
indoc = "2.0.5"
serde = "1.0.203"
hex = "0.4.3"
salvo = "0.64.0"
tokio = { version = "1", features = ["macros"] }
salvo = { version = "0.64.0", optional = true }
tokio = { version = "1", features = ["macros"], optional = true }
tracing = "0.1"
tracing-subscriber = "0.3"
ctor = "0.2.8"
ctor = { version = "0.2.8", optional = true }
log = "0.4.22"
env_logger = "0.11.3"
exec = "0.3.1"
pyo3 = { version = "0.20.0", features = ["auto-initialize"], optional = true }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod channel_handler;
pub mod common;
pub mod games;
mod log;
pub mod log;
/// Provides as simple as possible a full blockchain interface that can be spoken
/// with via a trait interface that's either local and synchronous or over a pipe.
pub mod peer_container;
Expand Down
6 changes: 6 additions & 0 deletions src/log.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
#[ctor::ctor]
fn init() {
env_logger::init();
}

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
pub fn wasm_init() {
env_logger::init();
}
26 changes: 26 additions & 0 deletions wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "chia_gaming_wasm"
version = "0.1.0"
edition = "2018"
authors = ["Art Yerkes <[email protected]>"]
description = "tools for working with chialisp language; compiler, repl, python and wasm bindings"
homepage = "https://prozacchiwawa.github.io/clvm_tools_rs/"
readme = "README.md"
repository = "https://github.com/Chia-Network/clvm_tools_rs"
license = "MIT"
keywords = ["chia", "chialisp", "clvm"]
categories = ["command-line-utilities"]

[lib]
name = "chia_gaming_wasm"
crate-type = ["cdylib"]
path = "src/mod.rs"

[dependencies]
chia_gaming = { path= "..", features = [] }
clvmr = { version = "0.3.0", features = ["pre-eval"] }
wasm-bindgen = "=0.2.83"
wasm-bindgen-test = "=0.3.25"
js-sys = "0.3.60"
num-bigint = "0.4.0"
num-traits = "0.2.15"
8 changes: 8 additions & 0 deletions wasm/src/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use wasm_bindgen::prelude::*;

use chia_gaming::log::wasm_init;

#[wasm_bindgen]
pub fn init() {
wasm_init();
}
2 changes: 2 additions & 0 deletions wasm/tests/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/*
/**/*.d.ts
31 changes: 31 additions & 0 deletions wasm/tests/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"modules": true,
"experimentalObjectRestSpread": true
}
},
"plugins": ["@typescript-eslint"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"rules": {
"comma-dangle": 0,
"no-unused-vars": "warn",
"no-unexpected-multiline": "warn",
"prefer-const": "warn",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-var-requires": "off"
},
"settings": {},
"env": {
"browser": true,
"node": true,
"jasmine": true,
"jest": true,
"es6": true
}
}
21 changes: 21 additions & 0 deletions wasm/tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
.vscode

npm-debug.log*
yarn-debug.log*
yarn-error.log*
36 changes: 36 additions & 0 deletions wasm/tests/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# dependencies
/node_modules

# testing
/tests
/coverage

# docs
/docs

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
/.github
/demo
.esdoc.json

npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Development folders and files
public
src
scripts
config
.travis.yml
CHANGELOG.md
README.md
.eslintignore
.eslintrc.json
webpack.config.js
babel.config.js
7 changes: 7 additions & 0 deletions wasm/tests/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
presets: [["@babel/env"]],
plugins: [
["@babel/plugin-proposal-class-properties"],
["@babel/plugin-transform-typescript"],
],
};
80 changes: 80 additions & 0 deletions wasm/tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"name": "clvm-tools-interface",
"version": "0.1.35",
"description": "Tests and extras for the clvm_tools_rs javascript interface",
"main": "build/index.js",
"types": "build/types/index.d.ts",
"scripts": {
"start": "webpack serve --config webpack.config.demo.js",
"build": "webpack && tsc",
"build:demo": "webpack --config webpack.config.demo.js",
"test": "tsc -p tstestconfig.json --noEmit && jest",
"coverage": "npm run test -- --coverage",
"prepare": "npm run build",
"trypublish": "npm publish || true"
},
"repository": {
"type": "git",
"url": "https://github.com/hodgef/ts-library-boilerplate-basic"
},
"author": "Francisco Hodge <[email protected]> (https://github.com/hodgef)",
"license": "MIT",
"bugs": {
"url": "https://github.com/hodgef/ts-library-boilerplate-basic/issues"
},
"homepage": "https://github.com/hodgef/ts-library-boilerplate-basic",
"keywords": [
"library",
"starter",
"es6"
],
"devDependencies": {
"@babel/cli": "^7.22.9",
"@babel/core": "^7.22.10",
"@babel/plugin-proposal-class-properties": "^7.16.0",
"@babel/plugin-transform-typescript": "^7.22.10",
"@babel/polyfill": "^7.12.1",
"@babel/preset-env": "^7.22.10",
"@types/jest": "^29.5.3",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"babel-eslint": "^10.1.0",
"babel-loader": "^9.1.3",
"babel-preset-minify": "^0.5.2",
"css-loader": "^6.8.1",
"css-minimizer-webpack-plugin": "^5.0.1",
"eslint": "^7.32.0",
"file-loader": "^6.2.0",
"html-webpack-plugin": "^5.5.3",
"jest": "^29.6.2",
"mini-css-extract-plugin": "^2.7.6",
"style-loader": "^3.3.2",
"terser-webpack-plugin": "^5.3.9",
"typescript": "^4.9.5",
"url-loader": "^4.1.1",
"webpack": "^5.88.2",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "4.13.3"
},
"jest": {
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/scripts/testMock.js",
"\\.(css|less)$": "<rootDir>/scripts/testMock.js"
},
"moduleFileExtensions": [
"web.js",
"js",
"web.ts",
"ts",
"web.tsx",
"tsx",
"json",
"web.jsx",
"jsx",
"node"
]
},
"dependencies": {
"bls-signatures": "^2.0.2"
}
}
Empty file added wasm/tests/src/lib/index.ts
Empty file.
10 changes: 10 additions & 0 deletions wasm/tests/src/lib/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { init } from '../../../../pkg/chia_gaming_wasm.js';

import * as fs from 'fs';
import { resolve } from 'path';
import * as assert from 'assert';
import * as bls_loader from 'bls-signatures';

it('loads', async () => {
init();
});
19 changes: 19 additions & 0 deletions wasm/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"noImplicitAny": true,
"outDir": "build/types",
"module": "esnext",
"target": "es5",
"allowJs": true,
"checkJs": false,
"sourceMap": true,
"declaration": true,
"emitDeclarationOnly": true,
"suppressImplicitAnyIndexErrors": true,
"lib": ["es2018", "dom"],
"moduleResolution": "node",
"target": "es2020"
},
"include": ["src/lib"],
"exclude": ["src/lib/**/tests"],
}
10 changes: 10 additions & 0 deletions wasm/tests/tstestconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"emitDeclarationOnly": false,
"noEmitOnError": true,
"strict": true,
},
"include": ["src/lib/**/tests"],
"exclude": []
}
Loading

0 comments on commit e639ac8

Please sign in to comment.