Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WASM build changes #275

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 6 additions & 24 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ jobs:
args: --workspace --all-features --all-targets -- --deny "clippy::all"
- name: all:test
run: cargo test
- name: chain:install
working-directory: chain/wasm
- name: cml:install
working-directory: cml/wasm
run: npm install
- name: chain:rust:build-nodejs
working-directory: chain/wasm
- name: cml:rust:build-nodejs
working-directory: cml/wasm
run: npm run rust:build-nodejs
- name: chain:rust:build-browser
working-directory: chain/wasm
- name: cml:rust:build-browser
working-directory: cml/wasm
run: npm run rust:build-browser
- name: multi-era:install
working-directory: multi-era/wasm
Expand All @@ -72,21 +72,3 @@ jobs:
- name: multi-era:rust:build-browser
working-directory: multi-era/wasm
run: npm run rust:build-browser
- name: cip25:install
working-directory: cip25/wasm
run: npm install
- name: cip25:rust:build-nodejs
working-directory: cip25/wasm
run: npm run rust:build-nodejs
- name: cip25:rust:build-browser
working-directory: cip25/wasm
run: npm run rust:build-browser
- name: cip36:install
working-directory: cip36/wasm
run: npm install
- name: cip36:rust:build-nodejs
working-directory: cip36/wasm
run: npm run rust:build-nodejs
- name: cip36:rust:build-browser
working-directory: cip36/wasm
run: npm run rust:build-browser
24 changes: 22 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,27 @@ chain/rust/Cargo.lock
chain/wasm/target/**
chain/wasm/Cargo.lock
chain/wasm/pkg/**
chain/wasm/json-gen/target/**
chain/wasm/json-gen/output/**
chain/wasm/json-gen/schemas/**

cip25/rust/target/**
cip25/rust/Cargo.lock
cip25/wasm/target/**
cip25/wasm/Cargo.lock
cip25/wasm/pkg/**
cip25/wasm/json-gen/target/**
cip25/wasm/json-gen/output/**
cip25/wasm/json-gen/schemas/**

cip36/rust/target/**
cip36/rust/Cargo.lock
cip36/wasm/target/**
cip36/wasm/Cargo.lock
cip36/wasm/pkg/**
cip36/wasm/json-gen/target/**
cip36/wasm/json-gen/output/**
cip36/wasm/json-gen/schemas/**

core/rust/target/**
core/rust/Cargo.lock
Expand All @@ -45,13 +52,26 @@ crypto/wasm/target/**
crypto/wasm/Cargo.lock
crypto/wasm/pkg/**

tools/metadata-cddl-checker/Cargo.lock
multi-era/rust/target/**
multi-era/rust/Cargo.lock
multi-era/wasm/target/**
multi-era/wasm/Cargo.lock
multi-era/wasm/pkg/**
multi-era/wasm/json-gen/target/**
multi-era/wasm/json-gen/output/**
multi-era/wasm/json-gen/schemas/**
multi-era/wasm/node_modules/**

cml/wasm/json-gen/target/**
cml/wasm/json-gen/output/**
cml/wasm/json-gen/schemas/**
cml/wasm/node_modules/**

tools/metadata-cddl-checker/Cargo.lock

# Docs
docs/node_modules/
docs/.docusaurus/

# Examples
examples/wasm-browser/node_modules/

10 changes: 7 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
members = [
"chain/rust",
"chain/wasm",
# names changed - will be replaced in the PR coming soon to regen chain
"chain/wasm/json-gen",
"cip25/rust",
"cip25/wasm",
"cip25/wasm/json-gen",
"cip36/rust",
"cip36/wasm",
# TODO: where did this go? replace it (will do when doing finishing cip36 work)
# "cip36/wasm/json-gen",
"cip36/wasm/json-gen",
"cml/wasm",
"cml/wasm/json-gen",
"core/rust",
"core/wasm",
"crypto/rust",
Expand All @@ -27,3 +27,7 @@ exclude = [
"rust",
"rust/json-gen"
]

[profile.release]
lto = true
opt-level = "z"
42 changes: 0 additions & 42 deletions chain/wasm/package.json

This file was deleted.

2 changes: 1 addition & 1 deletion cip25/wasm/json-gen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "cip25-json-schema-gen"
name = "cml-cip25-json-schema-gen"
version = "0.0.1"
edition = "2018"
keywords = ["cardano"]
Expand Down
25 changes: 25 additions & 0 deletions cip25/wasm/json-gen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
macro_rules! gen_json_schema {
($name:ty) => {
let dest_path =
std::path::Path::new(&"schemas").join(&format!("{}.json", stringify!($name)));
std::fs::write(
&dest_path,
serde_json::to_string_pretty(&schemars::schema_for!($name)).unwrap(),
)
.unwrap();
};
}

pub fn export_schemas() {
let schema_path = std::path::Path::new(&"schemas");
if !schema_path.exists() {
std::fs::create_dir(schema_path).unwrap();
}
gen_json_schema!(cml_cip25::CIP25Metadata);
gen_json_schema!(cml_cip25::CIP25Version);
gen_json_schema!(cml_cip25::ChunkableString);
gen_json_schema!(cml_cip25::FilesDetails);
gen_json_schema!(cml_cip25::LabelMetadata);
gen_json_schema!(cml_cip25::MetadataDetails);
gen_json_schema!(cml_cip25::String64);
}
25 changes: 1 addition & 24 deletions cip25/wasm/json-gen/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
use cml_cip25::*;

fn main() {
macro_rules! gen_json_schema {
($name:ident) => {
let dest_path =
std::path::Path::new(&"schemas").join(&format!("{}.json", stringify!($name)));
std::fs::write(
&dest_path,
serde_json::to_string_pretty(&schemars::schema_for!($name)).unwrap(),
)
.unwrap();
};
}
let schema_path = std::path::Path::new(&"schemas");
if !schema_path.exists() {
std::fs::create_dir(schema_path).unwrap();
}
gen_json_schema!(CIP25Metadata);
gen_json_schema!(CIP25Version);
gen_json_schema!(ChunkableString);
gen_json_schema!(FilesDetails);
gen_json_schema!(LabelMetadata);
gen_json_schema!(MetadataDetails);
gen_json_schema!(String64);
cml_cip25_json_schema_gen::export_schemas();
}
10 changes: 10 additions & 0 deletions cip36/wasm/json-gen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "cml-cip36-json-schema-gen"
version = "0.0.1"
edition = "2018"


[dependencies]
serde_json = "1.0.57"
schemars = "0.8.8"
cml-cip36 = { path = "../../rust" }
26 changes: 26 additions & 0 deletions cip36/wasm/json-gen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
macro_rules! gen_json_schema {
($name:ty) => {
let dest_path =
std::path::Path::new(&"schemas").join(&format!("{}.json", stringify!($name)));
std::fs::write(
&dest_path,
serde_json::to_string_pretty(&schemars::schema_for!($name)).unwrap(),
)
.unwrap();
};
}

pub fn export_schemas() {
let schema_path = std::path::Path::new(&"schemas");
if !schema_path.exists() {
std::fs::create_dir(schema_path).unwrap();
}
gen_json_schema!(cml_cip36::Delegation);
gen_json_schema!(cml_cip36::DelegationDistribution);
gen_json_schema!(cml_cip36::DeregistrationCbor);
gen_json_schema!(cml_cip36::DeregistrationWitness);
gen_json_schema!(cml_cip36::KeyDeregistration);
gen_json_schema!(cml_cip36::KeyRegistration);
gen_json_schema!(cml_cip36::RegistrationCbor);
gen_json_schema!(cml_cip36::RegistrationWitness);
}
3 changes: 3 additions & 0 deletions cip36/wasm/json-gen/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
cml_cip36_json_schema_gen::export_schemas();
}
44 changes: 0 additions & 44 deletions cip36/wasm/package.json

This file was deleted.

1 change: 1 addition & 0 deletions cml/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This crate is for the general-purpose WASM package. We don't have WASM packages for every single crate due to shared dependencies not being possible, so using, for example, cml-cip25-wasm + cml-cip36-wasm + cml-chain-wasm together would result in 3 copies of cml-chain-wasm that are not compatible with each other. This crate combines all wasm crates except for cml-multi-era-wasm (due to size reasons) together in one place and as such has no equivalent rust crate.
20 changes: 20 additions & 0 deletions cml/wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "cardano-multiplatform-lib"
version = "4.0.0"
edition = "2018"

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
cml-chain-wasm = { path = "../../chain/wasm" }
cml-cip25-wasm = { path = "../../cip25/wasm" }
cml-cip36-wasm = { path = "../../cip36/wasm" }
cml-crypto-wasm = { path = "../../crypto/wasm" }
cml-core-wasm = { path = "../../core/wasm" }
cbor_event = "2.4.0"
hex = "0.4.0"
linked-hash-map = "0.5.3"
serde_json = "1.0.57"
serde-wasm-bindgen = "0.4.5"
wasm-bindgen = { version = "0.2", features=["serde-serialize"] }
12 changes: 12 additions & 0 deletions cml/wasm/json-gen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "cardano-multiplatform-lib-json-schema-gen"
version = "0.0.1"
edition = "2018"


[dependencies]
serde_json = "1.0.57"
schemars = "0.8.8"
cml-chain-json-schema-gen = { path = "../../../chain/wasm/json-gen" }
cml-cip25-json-schema-gen = { path = "../../../cip25/wasm/json-gen" }
cml-cip36-json-schema-gen = { path = "../../../cip36/wasm/json-gen" }
5 changes: 5 additions & 0 deletions cml/wasm/json-gen/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn main() {
cml_cip25_json_schema_gen::export_schemas();
cml_cip36_json_schema_gen::export_schemas();
cml_chain_json_schema_gen::export_schemas();
}
22 changes: 11 additions & 11 deletions cip25/wasm/package.json → cml/wasm/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cml-cip25",
"version": "1.1.0",
"description": "Cardano Multiplatform SDK for CIP25 (Cardano NFT Metadata)",
"name": "cardano-multiplatform-lib",
"version": "4.0.0",
"description": "Cardano Multiplatform SDK for core Cardano blockchain functionality",
"keywords": [
"cardano"
],
Expand All @@ -15,14 +15,14 @@
"rust:check-warnings": "(RUSTFLAGS=\"-D warnings\" cargo +stable build)",
"rust:test": "cargo test",
"js:prepublish": "npm run rust:test && rimraf ./publish && cp -r ./pkg ./publish && cp README.md publish/ && cp ../../LICENSE publish/",
"js:test-publish": "npm run rust:build-nodejs && npm run js:prepublish && node ../../scripts/publish-helper cip25 -nodejs && cd publish",
"js:publish-nodejs:prod": "npm run rust:build-nodejs && npm run js:prepublish && node ../../scripts/publish-helper cip25 -nodejs && cd publish && npm publish --access public",
"js:publish-nodejs:beta": "npm run rust:build-nodejs && npm run js:prepublish && node ../../scripts/publish-helper cip25 -nodejs && cd publish && npm publish --tag beta --access public",
"js:publish-browser:prod": "npm run rust:build-browser && npm run js:prepublish && node ../../scripts/publish-helper cip25 -browser && cd publish && npm publish --access public",
"js:publish-browser:beta": "npm run rust:build-browser && npm run js:prepublish && node ../../scripts/publish-helper cip25 -browser && cd publish && npm publish --tag beta --access public",
"js:publish-asm:prod": "npm run rust:build-asm && npm run js:prepublish && node ../../scripts/publish-helper cip25 -asmjs && cd publish && npm publish --access public",
"js:publish-asm:beta": "npm run rust:build-asm && npm run js:prepublish && node ../../scripts/publish-helper cip25 -asmjs && cd publish && npm publish --tag beta --access public",
"js:ts-json-gen": "cd json-gen && cargo +stable run && cd .. && node ../../scripts/run-json2ts.js && node ../../scripts/json-ts-types.js cip25"
"js:test-publish": "npm run rust:build-nodejs && npm run js:prepublish && node ../../scripts/publish-helper cml cardano-multiplatform-lib -nodejs && cd publish",
"js:publish-nodejs:prod": "npm run rust:build-nodejs && npm run js:prepublish && node ../../scripts/publish-helper cml cardano-multiplatform-lib -nodejs && cd publish && npm publish --access public",
"js:publish-nodejs:beta": "npm run rust:build-nodejs && npm run js:prepublish && node ../../scripts/publish-helper cml cardano-multiplatform-lib -nodejs && cd publish && npm publish --tag beta --access public",
"js:publish-browser:prod": "npm run rust:build-browser && npm run js:prepublish && node ../../scripts/publish-helper cml cardano-multiplatform-lib -browser && cd publish && npm publish --access public",
"js:publish-browser:beta": "npm run rust:build-browser && npm run js:prepublish && node ../../scripts/publish-helper cml cardano-multiplatform-lib -browser && cd publish && npm publish --tag beta --access public",
"js:publish-asm:prod": "npm run rust:build-asm && npm run js:prepublish && node ../../scripts/publish-helper cml cardano-multiplatform-lib -asmjs && cd publish && npm publish --access public",
"js:publish-asm:beta": "npm run rust:build-asm && npm run js:prepublish && node ../../scripts/publish-helper cml cardano-multiplatform-lib -asmjs && cd publish && npm publish --tag beta --access public",
"js:ts-json-gen": "cd json-gen && cargo +stable run && cd .. && node ../../scripts/run-json2ts.js && node ../../scripts/json-ts-types.js cml cardano-multiplatform-lib"
},
"husky": {
"hooks": {
Expand Down
Loading
Loading