Skip to content

Commit

Permalink
๐Ÿฅ Support indent text config
Browse files Browse the repository at this point in the history
  • Loading branch information
oovm committed Mar 17, 2023
1 parent f55bf1b commit b003677
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 40 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ lto = true
panic = "abort"

[workspace.dependencies.tokio]
version = "1.42.0"
version = "1.43.0"
default-features = true
features = ["macros", "rt"]

[workspace.dependencies.reqwest]
version = "0.12.9"
version = "0.12.12"
default-features = false
features = ["rustls-tls", "json", "socks"]

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"fmt": "cargo fmt --all",
"p": "git push && git push --tags --prune",
"reset": "git reset Head~ --soft",
"u": "cargo upgrade --workspace"
"u": "cargo upgrade --incompatible"
},
"devDependencies": {
"@bytecodealliance/jco": "^1.8.1",
Expand Down
8 changes: 4 additions & 4 deletions projects/legion-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ license = "MPL-2.0"
edition = "2021"

[dependencies]
serde = "1.0.152"
serde_derive = "1.0.152"
serde = "1.0.217"
serde_derive = "1.0.217"
#config = "0.13.3"
semver = { version = "1.0.16", features = ["serde"] }
semver = { version = "1.0.25", features = ["serde"] }
json5 = "0.4.1"
toml = "0.8.19"
globset = "0.4.8"
globset = "0.4.15"

[dependencies.serde-types]
#path = "../serde-types"
Expand Down
2 changes: 1 addition & 1 deletion projects/legion-wasm32-wasi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@valkyrie-language/legion-wasm32-wasi",
"version": "0.0.3",
"version": "0.0.4",
"license": "UNLICENSED",
"repository": {
"type": "git",
Expand Down
10 changes: 5 additions & 5 deletions projects/legion-wit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ license = "MPL-2.0"
edition = "2021"

[dependencies]
anyhow = "1.0.94"
anyhow = "1.0.95"
#url = "2.5.4"
wat = { version = "1.222.0", features = ["component-model", "dwarf"] }
wasmprinter = { version = "0.222.0", features = ["component-model"] }
js-component-bindgen = "1.8.1"
wat = { version = "1.224.0", features = ["component-model", "dwarf"] }
wasmprinter = { version = "0.224.0", features = ["component-model"] }
js-component-bindgen = "1.9.1"
#reqwest = { workspace = true }
wit-bindgen-rt = { version = "0.36.0", features = ["bitflags"] }
wit-bindgen-rt = { version = "0.38.0", features = ["bitflags"] }

[lib]
crate-type = ["cdylib"]
Expand Down
56 changes: 31 additions & 25 deletions projects/legion-wit/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ impl ::core::fmt::Debug for EncodeConfig {
#[derive(Clone)]
pub struct DecodeConfig {
pub skeleton_only: bool,
/// Config the string to use when indenting.
pub indent_text: _rt::String,
pub fold_instructions: bool,
}
Expand All @@ -45,6 +46,7 @@ pub struct PolyfillConfig {
pub name: _rt::String,
pub shim: _rt::Vec<(_rt::String, _rt::String)>,
pub debug: bool,
pub guest: bool,
pub instantiation: bool,
}
impl ::core::fmt::Debug for PolyfillConfig {
Expand All @@ -53,21 +55,22 @@ impl ::core::fmt::Debug for PolyfillConfig {
.field("name", &self.name)
.field("shim", &self.shim)
.field("debug", &self.debug)
.field("guest", &self.guest)
.field("instantiation", &self.instantiation)
.finish()
}
}
#[doc(hidden)]
#[allow(non_snake_case)]
pub unsafe fn _export_wat_encode_cabi<T: Guest>(
pub unsafe fn _export_wast_encode_cabi<T: Guest>(
arg0: *mut u8,
arg1: usize,
arg2: i32,
) -> *mut u8 {
#[cfg(target_arch = "wasm32")] _rt::run_ctors_once();
let len0 = arg1;
let bytes0 = _rt::Vec::from_raw_parts(arg0.cast(), len0, len0);
let result1 = T::wat_encode(
let result1 = T::wast_encode(
_rt::string_lift(bytes0),
EncodeConfig {
generate_dwarf: _rt::bool_lift(arg2 as u8),
Expand Down Expand Up @@ -99,7 +102,7 @@ pub unsafe fn _export_wat_encode_cabi<T: Guest>(
}
#[doc(hidden)]
#[allow(non_snake_case)]
pub unsafe fn __post_return_wat_encode<T: Guest>(arg0: *mut u8) {
pub unsafe fn __post_return_wast_encode<T: Guest>(arg0: *mut u8) {
let l0 = i32::from(*arg0.add(0).cast::<u8>());
match l0 {
0 => {
Expand Down Expand Up @@ -190,6 +193,7 @@ pub unsafe fn _export_wasi_polyfill_cabi<T: Guest>(
arg5: usize,
arg6: i32,
arg7: i32,
arg8: i32,
) -> *mut u8 {
#[cfg(target_arch = "wasm32")] _rt::run_ctors_once();
let len0 = arg1;
Expand Down Expand Up @@ -220,7 +224,8 @@ pub unsafe fn _export_wasi_polyfill_cabi<T: Guest>(
name: _rt::string_lift(bytes1),
shim: result8,
debug: _rt::bool_lift(arg6 as u8),
instantiation: _rt::bool_lift(arg7 as u8),
guest: _rt::bool_lift(arg7 as u8),
instantiation: _rt::bool_lift(arg8 as u8),
},
);
let ptr10 = _RET_AREA.0.as_mut_ptr().cast::<u8>();
Expand Down Expand Up @@ -309,7 +314,7 @@ pub unsafe fn __post_return_wasi_polyfill<T: Guest>(arg0: *mut u8) {
}
}
pub trait Guest {
fn wat_encode(
fn wast_encode(
input: _rt::String,
config: EncodeConfig,
) -> Result<_rt::Vec<u8>, ToolsError>;
Expand All @@ -325,24 +330,24 @@ pub trait Guest {
#[doc(hidden)]
macro_rules! __export_world_tools_cabi {
($ty:ident with_types_in $($path_to_types:tt)*) => {
const _ : () = { #[export_name = "wat-encode"] unsafe extern "C" fn
export_wat_encode(arg0 : * mut u8, arg1 : usize, arg2 : i32,) -> * mut u8 {
$($path_to_types)*:: _export_wat_encode_cabi::<$ty > (arg0, arg1, arg2) }
#[export_name = "cabi_post_wat-encode"] unsafe extern "C" fn
_post_return_wat_encode(arg0 : * mut u8,) { $($path_to_types)*::
__post_return_wat_encode::<$ty > (arg0) } #[export_name = "wasm-decode"] unsafe
const _ : () = { #[export_name = "wast-encode"] unsafe extern "C" fn
export_wast_encode(arg0 : * mut u8, arg1 : usize, arg2 : i32,) -> * mut u8 {
$($path_to_types)*:: _export_wast_encode_cabi::<$ty > (arg0, arg1, arg2) }
#[export_name = "cabi_post_wast-encode"] unsafe extern "C" fn
_post_return_wast_encode(arg0 : * mut u8,) { $($path_to_types)*::
__post_return_wast_encode::<$ty > (arg0) } #[export_name = "wasm-decode"] unsafe
extern "C" fn export_wasm_decode(arg0 : * mut u8, arg1 : usize, arg2 : i32, arg3
: * mut u8, arg4 : usize, arg5 : i32,) -> * mut u8 { $($path_to_types)*::
_export_wasm_decode_cabi::<$ty > (arg0, arg1, arg2, arg3, arg4, arg5) }
#[export_name = "cabi_post_wasm-decode"] unsafe extern "C" fn
_post_return_wasm_decode(arg0 : * mut u8,) { $($path_to_types)*::
__post_return_wasm_decode::<$ty > (arg0) } #[export_name = "wasi-polyfill"]
unsafe extern "C" fn export_wasi_polyfill(arg0 : * mut u8, arg1 : usize, arg2 : *
mut u8, arg3 : usize, arg4 : * mut u8, arg5 : usize, arg6 : i32, arg7 : i32,) ->
* mut u8 { $($path_to_types)*:: _export_wasi_polyfill_cabi::<$ty > (arg0, arg1,
arg2, arg3, arg4, arg5, arg6, arg7) } #[export_name = "cabi_post_wasi-polyfill"]
unsafe extern "C" fn _post_return_wasi_polyfill(arg0 : * mut u8,) {
$($path_to_types)*:: __post_return_wasi_polyfill::<$ty > (arg0) } };
mut u8, arg3 : usize, arg4 : * mut u8, arg5 : usize, arg6 : i32, arg7 : i32, arg8
: i32,) -> * mut u8 { $($path_to_types)*:: _export_wasi_polyfill_cabi::<$ty >
(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) } #[export_name =
"cabi_post_wasi-polyfill"] unsafe extern "C" fn _post_return_wasi_polyfill(arg0 :
* mut u8,) { $($path_to_types)*:: __post_return_wasi_polyfill::<$ty > (arg0) } };
};
}
#[doc(hidden)]
Expand Down Expand Up @@ -417,18 +422,19 @@ pub(crate) use __export_tools_impl as export;
#[cfg(target_arch = "wasm32")]
#[link_section = "component-type:wit-bindgen:0.35.0:legion:tools:tools:encoded world"]
#[doc(hidden)]
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 493] = *b"\
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xf1\x02\x01A\x02\x01\
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 501] = *b"\
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xf9\x02\x01A\x02\x01\
A\x16\x01r\x01\x07messages\x03\0\x0btools-error\x03\0\0\x01r\x01\x0egenerate-dwa\
rf\x7f\x03\0\x0dencode-config\x03\0\x02\x01r\x03\x0dskeleton-only\x7f\x0bindent-\
texts\x11fold-instructions\x7f\x03\0\x0ddecode-config\x03\0\x04\x01o\x02ss\x01p\x06\
\x01r\x04\x04names\x04shim\x07\x05debug\x7f\x0dinstantiation\x7f\x03\0\x0fpolyfi\
ll-config\x03\0\x08\x01p}\x01j\x01\x0a\x01\x01\x01@\x02\x05inputs\x06config\x03\0\
\x0b\x04\0\x0awat-encode\x01\x0c\x01j\x01s\x01\x01\x01@\x02\x05input\x0a\x06conf\
ig\x05\0\x0d\x04\0\x0bwasm-decode\x01\x0e\x01o\x02s\x0a\x01p\x0f\x01j\x01\x10\x01\
\x01\x01@\x02\x05input\x0a\x06config\x09\0\x11\x04\0\x0dwasi-polyfill\x01\x12\x04\
\0\x12legion:tools/tools\x04\0\x0b\x0b\x01\0\x05tools\x03\0\0\0G\x09producers\x01\
\x0cprocessed-by\x02\x0dwit-component\x070.220.0\x10wit-bindgen-rust\x060.35.0";
\x01r\x05\x04names\x04shim\x07\x05debug\x7f\x05guest\x7f\x0dinstantiation\x7f\x03\
\0\x0fpolyfill-config\x03\0\x08\x01p}\x01j\x01\x0a\x01\x01\x01@\x02\x05inputs\x06\
config\x03\0\x0b\x04\0\x0bwast-encode\x01\x0c\x01j\x01s\x01\x01\x01@\x02\x05inpu\
t\x0a\x06config\x05\0\x0d\x04\0\x0bwasm-decode\x01\x0e\x01o\x02s\x0a\x01p\x0f\x01\
j\x01\x10\x01\x01\x01@\x02\x05input\x0a\x06config\x09\0\x11\x04\0\x0dwasi-polyfi\
ll\x01\x12\x04\0\x12legion:tools/tools\x04\0\x0b\x0b\x01\0\x05tools\x03\0\0\0G\x09\
producers\x01\x0cprocessed-by\x02\x0dwit-component\x070.220.0\x10wit-bindgen-rus\
t\x060.35.0";
#[inline(never)]
#[doc(hidden)]
pub fn __link_custom_section_describing_imports() {
Expand Down
4 changes: 3 additions & 1 deletion projects/legion-wit/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export!(ToolsContext with_types_in bindings);
pub struct ToolsContext {}

impl Guest for ToolsContext {
fn wat_encode(input: String, config: EncodeConfig) -> Result<Vec<u8>, ToolsError> {
fn wast_encode(input: String, config: EncodeConfig) -> Result<Vec<u8>, ToolsError> {
let mut parser = wat::Parser::new();
if config.generate_dwarf {
parser.generate_dwarf(GenerateDwarf::Full);
Expand All @@ -22,6 +22,7 @@ impl Guest for ToolsContext {
parser.name_unnamed(true);
parser.print_offsets(false);
parser.print_skeleton(config.skeleton_only);
parser.indent_text(config.indent_text);
// parser.name_unnamed(config.indent_text);
parser.fold_instructions(config.fold_instructions);
let mut dst = String::new();
Expand Down Expand Up @@ -49,6 +50,7 @@ impl Guest for ToolsContext {
tracing: config.debug,
no_namespaced_exports: true,
multi_memory: true,
guest: config.guest,
};
let result = js_component_bindgen::transpile(&input, cfg)?;
Ok(result.files)
Expand Down
21 changes: 21 additions & 0 deletions projects/legion-wit/tests/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,24 @@
```bash
wee test
```

## Emoji Comment

| Emoji | Meaning |
|--------|------------------------------|
| ๐ŸŽ‚ | Project initialized! |
| ๐ŸŽ‰ | Release new version |
| ๐Ÿงช๐Ÿ”ฎ | Experimental code |
| ๐Ÿ”ง๐Ÿ›๐Ÿž | Bug fix |
| ๐Ÿ”’ | Security fix |
| ๐Ÿฃ๐Ÿค๐Ÿฅ | Add feature |
| ๐Ÿ“๐ŸŽ€ | Documentation |
| ๐Ÿš€ | Performance improve! |
| ๐Ÿšง | Work in progress |
| ๐Ÿšจ | Test coverage improve! |
| ๐Ÿšฅ | CI improve! |
| ๐Ÿ”ฅ๐Ÿงจ | Remove code or files |
| ๐Ÿงน | Code refactor |
| ๐Ÿ“ˆ | Add analytics or branch code |
| ๐Ÿค– | Automation fix |
| ๐Ÿ“ฆ | Update dependencies |
4 changes: 3 additions & 1 deletion projects/legion-wit/wit/world.wit
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ world tools {
}
record decode-config {
skeleton-only: bool,
/// Config the string to use when indenting.
indent-text: string,
fold-instructions: bool
}
record polyfill-config {
name: string,
shim: list<tuple<string, string>>,
debug: bool,
guest: bool,
instantiation: bool,
}
export wat-encode: func(input: string, config: encode-config) -> result<list<u8>, tools-error>;
export wast-encode: func(input: string, config: encode-config) -> result<list<u8>, tools-error>;
export wasm-decode: func(input: list<u8>, config: decode-config) -> result<string, tools-error>;
export wasi-polyfill: func(input: list<u8>, config: polyfill-config) -> result<list<tuple<string, list<u8>>>, tools-error>;
}
Expand Down

0 comments on commit b003677

Please sign in to comment.