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

Fix build errors and package cleanup #232

Merged
merged 20 commits into from
Feb 10, 2025
Prev Previous commit
Next Next commit
fix wasm compilation issues
anweiss committed Feb 10, 2025
commit 6d7830c1e1cdaf557e6c193e55ae81ae8f68cdea
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -55,17 +55,18 @@ simplelog = "0.12.1"
[dev-dependencies]
indoc = "2.0.1"
pretty_assertions = "1.2.0"
wasm-bindgen-test = "0.3.34"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
crossterm = { version = "0.27.0", optional = true }
crossterm = { version = "0.28.1", optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1.6"
serde-wasm-bindgen = { version = "0.5.0", optional = true }
serde-wasm-bindgen = { version = "0.6.5", optional = true }
wasm-bindgen = { version = "0.2", optional = true }

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen-test = "0.3.25"
wasm-bindgen-test = "0.3.34"
js-sys = "0.3.64"
web-sys = { version = "0.3.64", features = ["console"] }

[features]
default = [
@@ -76,6 +77,7 @@ default = [
"cbor",
"additional-controls",
"ast-parent",
"wasm-bindgen",
]
std = [
"base16/alloc",
@@ -104,8 +106,6 @@ cbor = ["std"]
name = "cddl"
required-features = ["std", "json", "cbor"]
path = "src/bin/cli.rs"
test = false
target = "cfg(not(target_arch = \"wasm32\"))"

[profile.release]
opt-level = "s"
15 changes: 11 additions & 4 deletions src/bin/cli.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#![cfg(feature = "cbor")]
#![cfg(feature = "json")]
#![cfg(all(feature = "cbor", feature = "json"))]
#![cfg(not(feature = "lsp"))]
#![cfg(not(test))]
#![allow(unused_imports)]
#![allow(unused_macros)]

#[macro_use]
extern crate log;

use cddl::cddl_from_str;
#[cfg(not(target_arch = "wasm32"))]
use cddl::{
cddl_from_str, parser::root_type_name_from_cddl_str, validate_cbor_from_slice,
validate_json_from_str,
parser::root_type_name_from_cddl_str, validate_cbor_from_slice, validate_json_from_str,
};
use clap::{ArgGroup, Args, Parser, Subcommand};

@@ -91,6 +94,7 @@ macro_rules! error {
};
}

#[cfg(not(target_arch = "wasm32"))]
fn main() -> Result<(), Box<dyn Error>> {
TermLogger::init(
LevelFilter::Info,
@@ -282,3 +286,6 @@ fn main() -> Result<(), Box<dyn Error>> {

Ok(())
}

#[cfg(target_arch = "wasm32")]
fn main() {}
21 changes: 14 additions & 7 deletions tests/wasm.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
#![cfg(target_arch = "wasm32")]

use wasm_bindgen_test::*;

use cddl::cddl_from_str;
use indoc::indoc;
use wasm_bindgen_test::*;

#[wasm_bindgen_test]
fn pass() {
let input = indoc!(
r#"
Version = [
major: tstr, ; comment
minor: tstr,
patch: tstr,
]
"#
Version = [
major: tstr, ; comment
minor: tstr,
patch: tstr,
]
"#
);
let _ = cddl_from_str(input).unwrap();
}

#[wasm_bindgen_test]
fn fail() {
let input = "invalid = {";
assert!(cddl_from_str(input).is_err());
}
2 changes: 1 addition & 1 deletion www/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.