diff --git a/Cargo.lock b/Cargo.lock index 1205f903867..61090b362c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21,6 +21,15 @@ dependencies = [ "gimli 0.26.2", ] +[[package]] +name = "addr2line" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97" +dependencies = [ + "gimli 0.27.3", +] + [[package]] name = "addr2line" version = "0.20.0" @@ -1314,6 +1323,15 @@ dependencies = [ "cranelift-entity 0.82.3", ] +[[package]] +name = "cranelift-bforest" +version = "0.91.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a2ab4512dfd3a6f4be184403a195f76e81a8a9f9e6c898e19d2dc3ce20e0115" +dependencies = [ + "cranelift-entity 0.91.1", +] + [[package]] name = "cranelift-bforest" version = "0.93.2" @@ -1323,6 +1341,15 @@ dependencies = [ "cranelift-entity 0.93.2", ] +[[package]] +name = "cranelift-bforest" +version = "0.98.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1380172556902242d32f78ed08c98aac4f5952aef22d3684aed5c66a5db0a6fc" +dependencies = [ + "cranelift-entity 0.98.1", +] + [[package]] name = "cranelift-codegen" version = "0.82.3" @@ -1340,6 +1367,27 @@ dependencies = [ "target-lexicon", ] +[[package]] +name = "cranelift-codegen" +version = "0.91.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98b022ed2a5913a38839dfbafe6cf135342661293b08049843362df4301261dc" +dependencies = [ + "arrayvec 0.7.4", + "bumpalo", + "cranelift-bforest 0.91.1", + "cranelift-codegen-meta 0.91.1", + "cranelift-codegen-shared 0.91.1", + "cranelift-egraph", + "cranelift-entity 0.91.1", + "cranelift-isle 0.91.1", + "gimli 0.26.2", + "log", + "regalloc2 0.5.1", + "smallvec", + "target-lexicon", +] + [[package]] name = "cranelift-codegen" version = "0.93.2" @@ -1352,11 +1400,32 @@ dependencies = [ "cranelift-codegen-meta 0.93.2", "cranelift-codegen-shared 0.93.2", "cranelift-entity 0.93.2", - "cranelift-isle", + "cranelift-isle 0.93.2", "gimli 0.26.2", "hashbrown 0.12.3", "log", - "regalloc2", + "regalloc2 0.5.1", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-codegen" +version = "0.98.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037cca234e1ad0766fdfe43b527ec14e100414b4ccf4bb614977aa9754958f57" +dependencies = [ + "bumpalo", + "cranelift-bforest 0.98.1", + "cranelift-codegen-meta 0.98.1", + "cranelift-codegen-shared 0.98.1", + "cranelift-control", + "cranelift-entity 0.98.1", + "cranelift-isle 0.98.1", + "gimli 0.27.3", + "hashbrown 0.13.2", + "log", + "regalloc2 0.9.2", "smallvec", "target-lexicon", ] @@ -1370,6 +1439,15 @@ dependencies = [ "cranelift-codegen-shared 0.82.3", ] +[[package]] +name = "cranelift-codegen-meta" +version = "0.91.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "639307b45434ad112a98f8300c0f0ab085cbefcd767efcdef9ef19d4c0756e74" +dependencies = [ + "cranelift-codegen-shared 0.91.1", +] + [[package]] name = "cranelift-codegen-meta" version = "0.93.2" @@ -1379,24 +1457,74 @@ dependencies = [ "cranelift-codegen-shared 0.93.2", ] +[[package]] +name = "cranelift-codegen-meta" +version = "0.98.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d375e6afa8b9a304999ea8cf58424414b8e55e004571265a4f0826eba8b74f18" +dependencies = [ + "cranelift-codegen-shared 0.98.1", +] + [[package]] name = "cranelift-codegen-shared" version = "0.82.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01fd0d9f288cc1b42d9333b7a776b17e278fc888c28e6a0f09b5573d45a150bc" +[[package]] +name = "cranelift-codegen-shared" +version = "0.91.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "278e52e29c53fcf32431ef08406c295699a70306d05a0715c5b1bf50e33a9ab7" + [[package]] name = "cranelift-codegen-shared" version = "0.93.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "687e14e3f5775248930e0d5a84195abef8b829958e9794bf8d525104993612b4" +[[package]] +name = "cranelift-codegen-shared" +version = "0.98.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca590e72ccb8da963def6e36460cce4412032b1f03c31d1a601838d305abdc39" + +[[package]] +name = "cranelift-control" +version = "0.98.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d2d38eea4373639f4b6236a40f69820fed16c5511093cd3783bf8491a93d9cf" +dependencies = [ + "arbitrary", +] + +[[package]] +name = "cranelift-egraph" +version = "0.91.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624b54323b06e675293939311943ba82d323bb340468ce1889be5da7932c8d73" +dependencies = [ + "cranelift-entity 0.91.1", + "fxhash", + "hashbrown 0.12.3", + "indexmap 1.9.3", + "log", + "smallvec", +] + [[package]] name = "cranelift-entity" version = "0.82.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e3bfe172b83167604601faf9dc60453e0d0a93415b57a9c4d1a7ae6849185cf" +[[package]] +name = "cranelift-entity" +version = "0.91.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a59bcbca89c3f1b70b93ab3cbba5e5e0cbf3e63dadb23c7525cb142e21a9d4c" + [[package]] name = "cranelift-entity" version = "0.93.2" @@ -1406,6 +1534,15 @@ dependencies = [ "serde", ] +[[package]] +name = "cranelift-entity" +version = "0.98.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e3173c1434af23c00e4964722cf93ca8f0e6287289bf5d52110597c3ba2ea09" +dependencies = [ + "serde", +] + [[package]] name = "cranelift-frontend" version = "0.82.3" @@ -1418,6 +1555,18 @@ dependencies = [ "target-lexicon", ] +[[package]] +name = "cranelift-frontend" +version = "0.91.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d70abacb8cfef3dc8ff7e8836e9c1d70f7967dfdac824a4cd5e30223415aca6" +dependencies = [ + "cranelift-codegen 0.91.1", + "log", + "smallvec", + "target-lexicon", +] + [[package]] name = "cranelift-frontend" version = "0.93.2" @@ -1430,12 +1579,36 @@ dependencies = [ "target-lexicon", ] +[[package]] +name = "cranelift-frontend" +version = "0.98.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aec4a3a33825062eccf6eec73e852c8773220f6e4798925e19696562948beb1f" +dependencies = [ + "cranelift-codegen 0.98.1", + "log", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-isle" +version = "0.91.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "393bc73c451830ff8dbb3a07f61843d6cb41a084f9996319917c0b291ed785bb" + [[package]] name = "cranelift-isle" version = "0.93.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e9793158837678902446c411741d87b43f57dadfb944f2440db4287cda8cbd59" +[[package]] +name = "cranelift-isle" +version = "0.98.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5146b5cea4b21095a021d964b0174cf6ff5530f83e8d0a822683c7559e360b66" + [[package]] name = "cranelift-native" version = "0.93.2" @@ -1447,6 +1620,17 @@ dependencies = [ "target-lexicon", ] +[[package]] +name = "cranelift-native" +version = "0.98.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21cec3717ce554d3936b2101aa8eae1a2a410bd6da0f4df698a4b008fe9cf1e9" +dependencies = [ + "cranelift-codegen 0.98.1", + "libc", + "target-lexicon", +] + [[package]] name = "cranelift-wasm" version = "0.93.2" @@ -1460,7 +1644,23 @@ dependencies = [ "log", "smallvec", "wasmparser 0.100.0", - "wasmtime-types", + "wasmtime-types 6.0.2", +] + +[[package]] +name = "cranelift-wasm" +version = "0.98.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7fd2f9f1bf29ce6639ae2f477a2fe20bad0bd09289df13efeb890e8e4b9f807" +dependencies = [ + "cranelift-codegen 0.98.1", + "cranelift-entity 0.98.1", + "cranelift-frontend 0.98.1", + "itertools", + "log", + "smallvec", + "wasmparser 0.107.0", + "wasmtime-types 11.0.1", ] [[package]] @@ -1751,6 +1951,19 @@ dependencies = [ "syn 2.0.25", ] +[[package]] +name = "dashmap" +version = "5.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6943ae99c34386c84a470c499d3414f66502a41340aa895406e0d2e4a207b91d" +dependencies = [ + "cfg-if", + "hashbrown 0.14.0", + "lock_api", + "once_cell", + "parking_lot_core 0.9.8", +] + [[package]] name = "data-encoding" version = "2.4.0" @@ -1777,6 +1990,15 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "debugid" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef552e6f588e446098f6ba40d89ac146c8c7b64aade83c051ee00bb5d2bc18d" +dependencies = [ + "uuid", +] + [[package]] name = "demo-async" version = "0.1.0" @@ -2994,6 +3216,16 @@ dependencies = [ "log", ] +[[package]] +name = "file-per-thread-logger" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a3cc21c33af89af0930c8cae4ade5e6fdc17b5d2c97b3d2e2edb67a1cf683f3" +dependencies = [ + "env_logger", + "log", +] + [[package]] name = "filetime" version = "0.2.21" @@ -3570,11 +3802,25 @@ dependencies = [ "byteorder", ] +[[package]] +name = "fxprof-processed-profile" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27d12c0aed7f1e24276a241aadc4cb8ea9f83000f34bc062b7cc2d51e3b0fabd" +dependencies = [ + "bitflags 2.3.3", + "debugid", + "fxhash", + "serde", + "serde_json", +] + [[package]] name = "galloc" version = "0.2.2" dependencies = [ "dlmalloc", + "gwasm", ] [[package]] @@ -3667,7 +3913,6 @@ dependencies = [ name = "gcore" version = "0.2.2" dependencies = [ - "galloc", "gear-core-errors", "gsys", "hex-literal 0.3.4", @@ -4188,6 +4433,7 @@ version = "0.1.0" dependencies = [ "environmental", "gear-sandbox-env", + "gwasm-processor", "log", "once_cell", "parity-scale-codec", @@ -4195,7 +4441,7 @@ dependencies = [ "sp-wasm-interface 7.0.0 (git+https://github.com/gear-tech/substrate.git?branch=gear-polkadot-v0.9.41-canary-no-sandbox)", "tempfile", "thiserror", - "wasmer", + "wasmer 2.3.0", "wasmer-cache", "wasmi 0.13.2", ] @@ -4482,6 +4728,11 @@ name = "gimli" version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" +dependencies = [ + "fallible-iterator", + "indexmap 1.9.3", + "stable_deref_trait", +] [[package]] name = "git2" @@ -4679,6 +4930,21 @@ dependencies = [ "rand 0.8.5", ] +[[package]] +name = "gwasm" +version = "0.0.0" + +[[package]] +name = "gwasm-processor" +version = "0.1.0" +dependencies = [ + "anyhow", + "gear-wasm-builder", + "wasm-compose", + "wasmer 4.1.0", + "wasmtime 11.0.1", +] + [[package]] name = "h2" version = "0.3.20" @@ -4992,6 +5258,12 @@ dependencies = [ "cc", ] +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + [[package]] name = "ident_case" version = "1.0.1" @@ -5102,6 +5374,7 @@ checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" dependencies = [ "equivalent", "hashbrown 0.14.0", + "serde", ] [[package]] @@ -5230,6 +5503,26 @@ version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62b02a5381cc465bd3041d84623d0fa3b66738b52b8e2fc3bab8ad63ab032f4a" +[[package]] +name = "ittapi" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41e0d0b7b3b53d92a7e8b80ede3400112a6b8b4c98d1f5b8b16bb787c780582c" +dependencies = [ + "anyhow", + "ittapi-sys", + "log", +] + +[[package]] +name = "ittapi-sys" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f8763c96e54e6d6a0dccc2990d8b5e33e3313aaeae6185921a3f4c1614a77c" +dependencies = [ + "cc", +] + [[package]] name = "jobserver" version = "0.1.26" @@ -6307,6 +6600,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "memoffset" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" +dependencies = [ + "autocfg", +] + [[package]] name = "memoffset" version = "0.9.0" @@ -6894,6 +7196,18 @@ dependencies = [ "memchr", ] +[[package]] +name = "object" +version = "0.30.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03b4680b86d9cfafba8fc491dc9b6df26b68cf40e9e6cd73909194759a63c385" +dependencies = [ + "crc32fast", + "hashbrown 0.13.2", + "indexmap 1.9.3", + "memchr", +] + [[package]] name = "object" version = "0.31.1" @@ -8554,6 +8868,17 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "pulldown-cmark" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffade02495f22453cd593159ea2f59827aae7f53fa8323f756799b670881dcf8" +dependencies = [ + "bitflags 1.3.2", + "memchr", + "unicase", +] + [[package]] name = "pwasm-utils" version = "0.19.0" @@ -8858,6 +9183,19 @@ dependencies = [ "smallvec", ] +[[package]] +name = "regalloc2" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b4dcbd3a2ae7fb94b5813fa0e957c6ab51bf5d0a8ee1b69e0c2d0f1e6eb8485" +dependencies = [ + "hashbrown 0.13.2", + "log", + "rustc-hash", + "slice-group-by", + "smallvec", +] + [[package]] name = "regex" version = "1.9.1" @@ -9023,6 +9361,7 @@ dependencies = [ "bitvec", "bytecheck", "hashbrown 0.12.3", + "indexmap 1.9.3", "ptr_meta", "rend", "rkyv_derive", @@ -9768,7 +10107,7 @@ dependencies = [ "sp-allocator", "sp-runtime-interface 7.0.0 (git+https://github.com/gear-tech/substrate.git?branch=gear-polkadot-v0.9.41-canary-no-sandbox)", "sp-wasm-interface 7.0.0 (git+https://github.com/gear-tech/substrate.git?branch=gear-polkadot-v0.9.41-canary-no-sandbox)", - "wasmtime", + "wasmtime 6.0.2", ] [[package]] @@ -10704,6 +11043,17 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde-wasm-bindgen" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3b4c031cd0d9014307d82b8abf653c0290fbdaeb4c02d00c63cf52f728628bf" +dependencies = [ + "js-sys", + "serde", + "wasm-bindgen", +] + [[package]] name = "serde_bytes" version = "0.11.11" @@ -10768,12 +11118,25 @@ dependencies = [ ] [[package]] -name = "sha-1" -version = "0.9.8" +name = "serde_yaml" +version = "0.9.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6" +checksum = "1a49e178e4452f45cb61d0cd8cebc1b0fafd3e41929e996cef79aa3aca91f574" dependencies = [ - "block-buffer 0.9.0", + "indexmap 2.0.0", + "itoa", + "ryu", + "serde", + "unsafe-libyaml", +] + +[[package]] +name = "sha-1" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6" +dependencies = [ + "block-buffer 0.9.0", "cfg-if", "cpufeatures", "digest 0.9.0", @@ -11934,7 +12297,7 @@ dependencies = [ "parity-scale-codec", "sp-std 5.0.0 (git+https://github.com/gear-tech/substrate.git?branch=gear-polkadot-v0.9.41-canary)", "wasmi 0.13.2", - "wasmtime", + "wasmtime 6.0.2", ] [[package]] @@ -11949,7 +12312,7 @@ dependencies = [ "sp-allocator", "sp-std 5.0.0 (git+https://github.com/gear-tech/substrate.git?branch=gear-polkadot-v0.9.41-canary-no-sandbox)", "sp-wasm-interface-common", - "wasmtime", + "wasmtime 6.0.2", ] [[package]] @@ -12014,6 +12377,12 @@ dependencies = [ "der", ] +[[package]] +name = "sptr" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b9b39299b249ad65f3b7e96443bad61c02ca5cd3589f46cb6d610a0fd6c0d6a" + [[package]] name = "ss58-registry" version = "1.41.0" @@ -13131,6 +13500,15 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" +[[package]] +name = "unicase" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +dependencies = [ + "version_check", +] + [[package]] name = "unicode-bidi" version = "0.3.13" @@ -13184,6 +13562,12 @@ dependencies = [ "subtle", ] +[[package]] +name = "unsafe-libyaml" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28467d3e1d3c6586d8f25fa243f544f5800fec42d97032474e17222c2b75cfa" + [[package]] name = "unsigned-varint" version = "0.7.1" @@ -13443,6 +13827,29 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-downcast" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dac026d43bcca6e7ce1c0956ba68f59edf6403e8e930a5d891be72c31a44340" +dependencies = [ + "js-sys", + "once_cell", + "wasm-bindgen", + "wasm-bindgen-downcast-macros", +] + +[[package]] +name = "wasm-bindgen-downcast-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5020cfa87c7cecefef118055d44e3c1fc122c7ec25701d528ee458a0b45f38f" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "wasm-bindgen-futures" version = "0.4.37" @@ -13484,6 +13891,25 @@ version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" +[[package]] +name = "wasm-compose" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5870984fe7c7f455130f2d1a1af2f0655f13bb0076ff0462866106045c2e67c5" +dependencies = [ + "anyhow", + "heck", + "indexmap 2.0.0", + "log", + "petgraph", + "serde", + "serde_yaml", + "smallvec", + "wasm-encoder 0.31.1", + "wasmparser 0.110.0", + "wat", +] + [[package]] name = "wasm-encoder" version = "0.16.0" @@ -13494,9 +13920,9 @@ dependencies = [ [[package]] name = "wasm-encoder" -version = "0.30.0" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2f8e9778e04cbf44f58acc301372577375a666b966c50b03ef46144f80436a8" +checksum = "41763f20eafed1399fff1afb466496d3a959f58241436cfdc17e3f5ca954de16" dependencies = [ "leb128", ] @@ -13622,15 +14048,44 @@ dependencies = [ "thiserror", "wasm-bindgen", "wasmer-artifact", - "wasmer-compiler", - "wasmer-compiler-cranelift", - "wasmer-compiler-singlepass", - "wasmer-derive", + "wasmer-compiler 2.3.0", + "wasmer-compiler-cranelift 2.3.0", + "wasmer-compiler-singlepass 2.3.0", + "wasmer-derive 2.3.0", "wasmer-engine", "wasmer-engine-dylib", "wasmer-engine-universal", - "wasmer-types", - "wasmer-vm", + "wasmer-types 2.3.0", + "wasmer-vm 2.3.0", + "wat", + "winapi", +] + +[[package]] +name = "wasmer" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3849811ec23a31369ad40a07fcf4a6d259f2b05debdb6b21726c47a6a62f618f" +dependencies = [ + "bytes", + "cfg-if", + "derivative", + "indexmap 1.9.3", + "js-sys", + "more-asserts", + "rustc-demangle", + "serde", + "serde-wasm-bindgen", + "target-lexicon", + "thiserror", + "wasm-bindgen", + "wasm-bindgen-downcast", + "wasmer-compiler 4.1.0", + "wasmer-compiler-cranelift 4.1.0", + "wasmer-compiler-singlepass 4.1.0", + "wasmer-derive 4.1.0", + "wasmer-types 4.1.0", + "wasmer-vm 4.1.0", "wat", "winapi", ] @@ -13644,8 +14099,8 @@ dependencies = [ "enumset", "loupe", "thiserror", - "wasmer-compiler", - "wasmer-types", + "wasmer-compiler 2.3.0", + "wasmer-types 2.3.0", ] [[package]] @@ -13657,7 +14112,7 @@ dependencies = [ "blake3", "hex", "thiserror", - "wasmer", + "wasmer 2.3.0", ] [[package]] @@ -13674,10 +14129,33 @@ dependencies = [ "smallvec", "target-lexicon", "thiserror", - "wasmer-types", + "wasmer-types 2.3.0", "wasmparser 0.83.0", ] +[[package]] +name = "wasmer-compiler" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "860db1e73e4a088a0636aabff2f89735eb9b4c4927e25c49da3aba561c8f26f4" +dependencies = [ + "backtrace", + "cfg-if", + "enum-iterator 0.7.0", + "enumset", + "lazy_static", + "leb128", + "memmap2", + "more-asserts", + "region", + "smallvec", + "thiserror", + "wasmer-types 4.1.0", + "wasmer-vm 4.1.0", + "wasmparser 0.95.0", + "winapi", +] + [[package]] name = "wasmer-compiler-cranelift" version = "2.3.0" @@ -13694,8 +14172,27 @@ dependencies = [ "smallvec", "target-lexicon", "tracing", - "wasmer-compiler", - "wasmer-types", + "wasmer-compiler 2.3.0", + "wasmer-types 2.3.0", +] + +[[package]] +name = "wasmer-compiler-cranelift" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5e01da3c6832c0f5b54dda23279e99b4aa82544c90ae0b0d4ebc584b8f6f4ef" +dependencies = [ + "cranelift-codegen 0.91.1", + "cranelift-entity 0.91.1", + "cranelift-frontend 0.91.1", + "gimli 0.26.2", + "more-asserts", + "rayon", + "smallvec", + "target-lexicon", + "tracing", + "wasmer-compiler 4.1.0", + "wasmer-types 4.1.0", ] [[package]] @@ -13713,8 +14210,27 @@ dependencies = [ "more-asserts", "rayon", "smallvec", - "wasmer-compiler", - "wasmer-types", + "wasmer-compiler 2.3.0", + "wasmer-types 2.3.0", +] + +[[package]] +name = "wasmer-compiler-singlepass" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e856957b7173bbd15da77833e4db3d1ca5aeff35dd2f88e69f7d36cfeaf822d6" +dependencies = [ + "byteorder", + "dynasm", + "dynasmrt", + "enumset", + "gimli 0.26.2", + "lazy_static", + "more-asserts", + "rayon", + "smallvec", + "wasmer-compiler 4.1.0", + "wasmer-types 4.1.0", ] [[package]] @@ -13729,6 +14245,18 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "wasmer-derive" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34a2a51c07a1e476ceece72c8a09ab777e4832f104bf62fa454e8ea8db3ac7c9" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "wasmer-engine" version = "2.3.0" @@ -13747,9 +14275,9 @@ dependencies = [ "target-lexicon", "thiserror", "wasmer-artifact", - "wasmer-compiler", - "wasmer-types", - "wasmer-vm", + "wasmer-compiler 2.3.0", + "wasmer-types 2.3.0", + "wasmer-vm 2.3.0", ] [[package]] @@ -13770,11 +14298,11 @@ dependencies = [ "tempfile", "tracing", "wasmer-artifact", - "wasmer-compiler", + "wasmer-compiler 2.3.0", "wasmer-engine", "wasmer-object", - "wasmer-types", - "wasmer-vm", + "wasmer-types 2.3.0", + "wasmer-vm 2.3.0", "which", ] @@ -13790,11 +14318,11 @@ dependencies = [ "loupe", "region", "rkyv", - "wasmer-compiler", + "wasmer-compiler 2.3.0", "wasmer-engine", "wasmer-engine-universal-artifact", - "wasmer-types", - "wasmer-vm", + "wasmer-types 2.3.0", + "wasmer-vm 2.3.0", "winapi", ] @@ -13810,8 +14338,8 @@ dependencies = [ "rkyv", "thiserror", "wasmer-artifact", - "wasmer-compiler", - "wasmer-types", + "wasmer-compiler 2.3.0", + "wasmer-types 2.3.0", ] [[package]] @@ -13822,8 +14350,8 @@ checksum = "8d831335ff3a44ecf451303f6f891175c642488036b92ceceb24ac8623a8fa8b" dependencies = [ "object 0.28.4", "thiserror", - "wasmer-compiler", - "wasmer-types", + "wasmer-compiler 2.3.0", + "wasmer-types 2.3.0", ] [[package]] @@ -13842,6 +14370,22 @@ dependencies = [ "thiserror", ] +[[package]] +name = "wasmer-types" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b2274b2b4d931e77fcae9f90d4a1af6d72f6c3a3e38cc19277c5dc72a2fc5a5" +dependencies = [ + "bytecheck", + "enum-iterator 0.7.0", + "enumset", + "indexmap 1.9.3", + "more-asserts", + "rkyv", + "target-lexicon", + "thiserror", +] + [[package]] name = "wasmer-vm" version = "2.3.0" @@ -13866,7 +14410,34 @@ dependencies = [ "serde", "thiserror", "wasmer-artifact", - "wasmer-types", + "wasmer-types 2.3.0", + "winapi", +] + +[[package]] +name = "wasmer-vm" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58112eb6257d4fc293814d155ad296d3ddbdf88536784f493984cc56c3e3a0e2" +dependencies = [ + "backtrace", + "cc", + "cfg-if", + "corosensei", + "dashmap", + "derivative", + "enum-iterator 0.7.0", + "fnv", + "indexmap 1.9.3", + "lazy_static", + "libc", + "mach", + "memoffset 0.8.0", + "more-asserts", + "region", + "scopeguard", + "thiserror", + "wasmer-types 4.1.0", "winapi", ] @@ -13940,6 +14511,16 @@ dependencies = [ "indexmap 1.9.3", ] +[[package]] +name = "wasmparser" +version = "0.95.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2ea896273ea99b15132414be1da01ab0d8836415083298ecaffbe308eaac87a" +dependencies = [ + "indexmap 1.9.3", + "url", +] + [[package]] name = "wasmparser" version = "0.100.0" @@ -13950,6 +14531,16 @@ dependencies = [ "url", ] +[[package]] +name = "wasmparser" +version = "0.107.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29e3ac9b780c7dda0cac7a52a5d6d2d6707cc6e3451c9db209b6c758f40d7acb" +dependencies = [ + "indexmap 1.9.3", + "semver 1.0.17", +] + [[package]] name = "wasmparser" version = "0.108.0" @@ -13960,6 +14551,16 @@ dependencies = [ "semver 1.0.17", ] +[[package]] +name = "wasmparser" +version = "0.110.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dfcdb72d96f01e6c85b6bf20102e7423bdbaad5c337301bab2bbf253d26413c" +dependencies = [ + "indexmap 2.0.0", + "semver 1.0.17", +] + [[package]] name = "wasmparser-nostd" version = "0.83.0" @@ -14005,14 +14606,49 @@ dependencies = [ "serde", "target-lexicon", "wasmparser 0.100.0", - "wasmtime-cache", - "wasmtime-cranelift", - "wasmtime-environ", - "wasmtime-jit", - "wasmtime-runtime", + "wasmtime-cache 6.0.2", + "wasmtime-cranelift 6.0.2", + "wasmtime-environ 6.0.2", + "wasmtime-jit 6.0.2", + "wasmtime-runtime 6.0.2", "windows-sys 0.42.0", ] +[[package]] +name = "wasmtime" +version = "11.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b1f817f2ca5070983c71f1205fbab5848c9073df7f4e1af9fdceb4cc4a1b8e5" +dependencies = [ + "anyhow", + "async-trait", + "bincode", + "bumpalo", + "cfg-if", + "fxprof-processed-profile", + "indexmap 1.9.3", + "libc", + "log", + "object 0.30.4", + "once_cell", + "paste", + "psm", + "rayon", + "serde", + "serde_json", + "target-lexicon", + "wasmparser 0.107.0", + "wasmtime-cache 11.0.1", + "wasmtime-component-macro", + "wasmtime-cranelift 11.0.1", + "wasmtime-environ 11.0.1", + "wasmtime-fiber", + "wasmtime-jit 11.0.1", + "wasmtime-runtime 11.0.1", + "wat", + "windows-sys 0.48.0", +] + [[package]] name = "wasmtime-asm-macros" version = "6.0.2" @@ -14022,6 +14658,15 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "wasmtime-asm-macros" +version = "11.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f82fbfda4610e9225238c62574ecded8e9d6ad3a12f387ac45819ecad5c3f9b" +dependencies = [ + "cfg-if", +] + [[package]] name = "wasmtime-cache" version = "6.0.2" @@ -14032,7 +14677,7 @@ dependencies = [ "base64 0.13.1", "bincode", "directories-next", - "file-per-thread-logger", + "file-per-thread-logger 0.1.6", "log", "rustix 0.36.15", "serde", @@ -14042,6 +14687,47 @@ dependencies = [ "zstd", ] +[[package]] +name = "wasmtime-cache" +version = "11.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4f5b87f1ed383d6c219c04467ab6ae87990d6c2815d5a990138990a7fcbab95" +dependencies = [ + "anyhow", + "base64 0.21.2", + "bincode", + "directories-next", + "file-per-thread-logger 0.2.0", + "log", + "rustix 0.37.23", + "serde", + "sha2 0.10.7", + "toml 0.5.11", + "windows-sys 0.48.0", + "zstd", +] + +[[package]] +name = "wasmtime-component-macro" +version = "11.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e27b96c540c78e12b60025fcbc0ba8a55bff1b32885a5e8eae2df765a6bc97ac" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn 1.0.109", + "wasmtime-component-util", + "wasmtime-wit-bindgen", + "wit-parser", +] + +[[package]] +name = "wasmtime-component-util" +version = "11.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0928fe66c22bf8887e2fb524b7647308b8ce836a333af8504e4f1d80b8ea849f" + [[package]] name = "wasmtime-cranelift" version = "6.0.2" @@ -14052,15 +14738,54 @@ dependencies = [ "cranelift-codegen 0.93.2", "cranelift-entity 0.93.2", "cranelift-frontend 0.93.2", - "cranelift-native", - "cranelift-wasm", + "cranelift-native 0.93.2", + "cranelift-wasm 0.93.2", "gimli 0.26.2", "log", "object 0.29.0", "target-lexicon", "thiserror", "wasmparser 0.100.0", - "wasmtime-environ", + "wasmtime-environ 6.0.2", +] + +[[package]] +name = "wasmtime-cranelift" +version = "11.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b659f6e58662d1131f250339acd03aa49377f9351474282699985b79ca4d4a7c" +dependencies = [ + "anyhow", + "cranelift-codegen 0.98.1", + "cranelift-control", + "cranelift-entity 0.98.1", + "cranelift-frontend 0.98.1", + "cranelift-native 0.98.1", + "cranelift-wasm 0.98.1", + "gimli 0.27.3", + "log", + "object 0.30.4", + "target-lexicon", + "thiserror", + "wasmparser 0.107.0", + "wasmtime-cranelift-shared", + "wasmtime-environ 11.0.1", +] + +[[package]] +name = "wasmtime-cranelift-shared" +version = "11.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74171de083bf2ecb716c507900f825e2b858346c714fbf48f4763ea760f998a8" +dependencies = [ + "anyhow", + "cranelift-codegen 0.98.1", + "cranelift-control", + "cranelift-native 0.98.1", + "gimli 0.27.3", + "object 0.30.4", + "target-lexicon", + "wasmtime-environ 11.0.1", ] [[package]] @@ -14079,7 +14804,39 @@ dependencies = [ "target-lexicon", "thiserror", "wasmparser 0.100.0", - "wasmtime-types", + "wasmtime-types 6.0.2", +] + +[[package]] +name = "wasmtime-environ" +version = "11.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b124cbac1a3e04a744c76b3f77919343ef16dc4c818a2406dd7b689b16a54639" +dependencies = [ + "anyhow", + "cranelift-entity 0.98.1", + "gimli 0.27.3", + "indexmap 1.9.3", + "log", + "object 0.30.4", + "serde", + "target-lexicon", + "thiserror", + "wasmparser 0.107.0", + "wasmtime-types 11.0.1", +] + +[[package]] +name = "wasmtime-fiber" +version = "11.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f92ffb8869395c63100ffefbd71cf9489e7e9218e63a3798dcfe93fa8945f9cf" +dependencies = [ + "cc", + "cfg-if", + "rustix 0.37.23", + "wasmtime-asm-macros 11.0.1", + "windows-sys 0.48.0", ] [[package]] @@ -14099,13 +14856,39 @@ dependencies = [ "rustc-demangle", "serde", "target-lexicon", - "wasmtime-environ", - "wasmtime-jit-debug", - "wasmtime-jit-icache-coherence", - "wasmtime-runtime", + "wasmtime-environ 6.0.2", + "wasmtime-jit-debug 6.0.2", + "wasmtime-jit-icache-coherence 6.0.2", + "wasmtime-runtime 6.0.2", "windows-sys 0.42.0", ] +[[package]] +name = "wasmtime-jit" +version = "11.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ff15f426c2378f32ffb6d9b4370e3504231492e93f6968e8b5102c3256bbc4" +dependencies = [ + "addr2line 0.19.0", + "anyhow", + "bincode", + "cfg-if", + "cpp_demangle", + "gimli 0.27.3", + "ittapi", + "log", + "object 0.30.4", + "rustc-demangle", + "rustix 0.37.23", + "serde", + "target-lexicon", + "wasmtime-environ 11.0.1", + "wasmtime-jit-debug 11.0.1", + "wasmtime-jit-icache-coherence 11.0.1", + "wasmtime-runtime 11.0.1", + "windows-sys 0.48.0", +] + [[package]] name = "wasmtime-jit-debug" version = "6.0.2" @@ -14117,6 +14900,17 @@ dependencies = [ "rustix 0.36.15", ] +[[package]] +name = "wasmtime-jit-debug" +version = "11.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c549e219102426aa1f90bd18e56a3195ed1e696c318abb3f501c1f4924b530ac" +dependencies = [ + "object 0.30.4", + "once_cell", + "rustix 0.37.23", +] + [[package]] name = "wasmtime-jit-icache-coherence" version = "6.0.2" @@ -14128,6 +14922,17 @@ dependencies = [ "windows-sys 0.42.0", ] +[[package]] +name = "wasmtime-jit-icache-coherence" +version = "11.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cf02fedda287a409cff80ad40a7c6c0f0771e99b0cd5e2b79d9cb7ecdc1b2f4" +dependencies = [ + "cfg-if", + "libc", + "windows-sys 0.48.0", +] + [[package]] name = "wasmtime-runtime" version = "6.0.2" @@ -14146,12 +14951,38 @@ dependencies = [ "paste", "rand 0.8.5", "rustix 0.36.15", - "wasmtime-asm-macros", - "wasmtime-environ", - "wasmtime-jit-debug", + "wasmtime-asm-macros 6.0.2", + "wasmtime-environ 6.0.2", + "wasmtime-jit-debug 6.0.2", "windows-sys 0.42.0", ] +[[package]] +name = "wasmtime-runtime" +version = "11.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc38c6229a5d3b8a2528eb33eb11d3e7ebf570259c7cd2f01e8668fe783ea443" +dependencies = [ + "anyhow", + "cc", + "cfg-if", + "indexmap 1.9.3", + "libc", + "log", + "mach", + "memfd", + "memoffset 0.8.0", + "paste", + "rand 0.8.5", + "rustix 0.37.23", + "sptr", + "wasmtime-asm-macros 11.0.1", + "wasmtime-environ 11.0.1", + "wasmtime-fiber", + "wasmtime-jit-debug 11.0.1", + "windows-sys 0.48.0", +] + [[package]] name = "wasmtime-types" version = "6.0.2" @@ -14164,23 +14995,46 @@ dependencies = [ "wasmparser 0.100.0", ] +[[package]] +name = "wasmtime-types" +version = "11.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "768f6c5e7afc3a02eff2753196741db8e5ac5faf26a1e2204d7341b30a637c6f" +dependencies = [ + "cranelift-entity 0.98.1", + "serde", + "thiserror", + "wasmparser 0.107.0", +] + +[[package]] +name = "wasmtime-wit-bindgen" +version = "11.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84a4a005a6a2d5faa7cd953d389da8ae979cb571fe40edec7769649d8c98d874" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + [[package]] name = "wast" -version = "61.0.0" +version = "62.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc6b347851b52fd500657d301155c79e8c67595501d179cef87b6f04ebd25ac4" +checksum = "b8ae06f09dbe377b889fbd620ff8fa21e1d49d1d9d364983c0cdbf9870cb9f1f" dependencies = [ "leb128", "memchr", "unicode-width", - "wasm-encoder 0.30.0", + "wasm-encoder 0.31.1", ] [[package]] name = "wat" -version = "1.0.67" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "459e764d27c3ab7beba1ebd617cc025c7e76dea6e7c5ce3189989a970aea3491" +checksum = "842e15861d203fb4a96d314b0751cdeaf0f6f8b35e8d81d2953af2af5e44e637" dependencies = [ "wast", ] @@ -14771,6 +15625,22 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "wit-parser" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6daec9f093dbaea0e94043eeb92ece327bbbe70c86b1f41aca9bbfefd7f050f0" +dependencies = [ + "anyhow", + "id-arena", + "indexmap 1.9.3", + "log", + "pulldown-cmark", + "semver 1.0.17", + "unicode-xid", + "url", +] + [[package]] name = "wyz" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index f176f24afb2..a91709bd280 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,6 +74,9 @@ members = [ "gcli", "gclient", "gcore", + "gwasm", + # "gwasm/[!.cargo|!src]*", + "gwasm/processor", "gmeta", "gsdk", "gsdk/codegen", @@ -196,6 +199,8 @@ gstd = { path = "gstd" } gsys = { path = "gsys" } gtest = { path = "gtest" } gmeta = { path = "gmeta" } +gwasm = { path = "gwasm" } +gwasm-processor = { path = "gwasm/processor" } gear-authorship = { path = "node/authorship" } gear-backend-codegen = { path = "core-backend/codegen" } gear-backend-common = { path = "core-backend/common" } @@ -449,6 +454,7 @@ scale-value = "^0.10" # gsdk heck = "0.4.1" # gsdk-api-gen etc = "0.1.16" # gcli scale-decode = "0.7.0" # gsdk +rustc-demangle = "0.1.23" # gwasm/builder [profile.release] panic = "unwind" diff --git a/core-backend/sandbox/Cargo.toml b/core-backend/sandbox/Cargo.toml index 796413827ec..b7f8dfab445 100644 --- a/core-backend/sandbox/Cargo.toml +++ b/core-backend/sandbox/Cargo.toml @@ -21,3 +21,4 @@ codec.workspace = true [features] default = ["std"] std = ["gear-sandbox/std", "gear-wasm-instrument/std", "log/std"] +experimental-features = ["gear-sandbox/experimental-features"] diff --git a/examples/ping/Cargo.toml b/examples/ping/Cargo.toml index fa79445e23f..713f37c8117 100644 --- a/examples/ping/Cargo.toml +++ b/examples/ping/Cargo.toml @@ -13,6 +13,7 @@ gstd.workspace = true gear-wasm-builder.workspace = true [features] +gwasm = ["gstd/gwasm"] debug = ["gstd/debug"] default = ["std"] std = [] diff --git a/galloc/Cargo.toml b/galloc/Cargo.toml index 3f08c572dd3..c10f6fca7b9 100644 --- a/galloc/Cargo.toml +++ b/galloc/Cargo.toml @@ -8,6 +8,8 @@ license.workspace = true [dependencies] # add "checks" feature to enable hard checks in allocator dlmalloc = { workspace = true, features = ["global"] } +gwasm = { workspace = true, optional = true } [features] debug = ["dlmalloc/debug"] +gwasm = ["dep:gwasm"] diff --git a/galloc/src/lib.rs b/galloc/src/lib.rs index dd3c6638f3f..f11639ee5cd 100644 --- a/galloc/src/lib.rs +++ b/galloc/src/lib.rs @@ -21,8 +21,12 @@ #![doc(html_logo_url = "https://docs.gear.rs/logo.svg")] // until https://github.com/alexcrichton/dlmalloc-rs/pull/26 is merged -#[cfg(not(windows))] +#[cfg(not(any(windows, feature = "gwasm")))] #[global_allocator] pub static ALLOC: dlmalloc::GlobalDlmalloc = dlmalloc::GlobalDlmalloc; +#[cfg(all(not(windows), feature = "gwasm"))] +#[global_allocator] +pub static ALLOC: gwasm::Allocator = gwasm::Allocator; + pub mod prelude; diff --git a/gcore/Cargo.toml b/gcore/Cargo.toml index 5693f14552f..4e44163361e 100644 --- a/gcore/Cargo.toml +++ b/gcore/Cargo.toml @@ -13,7 +13,6 @@ static_assertions.workspace = true [dev-dependencies] hex-literal.workspace = true -galloc.workspace = true [features] codec = ["dep:codec", "gear-core-errors/codec"] diff --git a/gcore/src/lib.rs b/gcore/src/lib.rs index 161fe14dd39..787e169a397 100644 --- a/gcore/src/lib.rs +++ b/gcore/src/lib.rs @@ -32,8 +32,6 @@ //! ``` //! #![no_std] //! -//! extern crate galloc; -//! //! use gcore::msg; //! //! #[no_mangle] diff --git a/gstd/Cargo.toml b/gstd/Cargo.toml index 70c6033af9c..50695d0891e 100644 --- a/gstd/Cargo.toml +++ b/gstd/Cargo.toml @@ -24,3 +24,4 @@ static_assertions.workspace = true default = ["panic-handler"] panic-handler = [] debug = ["galloc/debug", "gcore/debug"] +gwasm = ["galloc/gwasm"] diff --git a/gwasm/Cargo.toml b/gwasm/Cargo.toml new file mode 100644 index 00000000000..54b537c2b4a --- /dev/null +++ b/gwasm/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "gwasm" +version = "0.0.0" +edition = "2021" +description = "Gear WASM libraries" + diff --git a/gwasm/lib/.cargo/config.toml b/gwasm/lib/.cargo/config.toml new file mode 100644 index 00000000000..f4e8c002fc2 --- /dev/null +++ b/gwasm/lib/.cargo/config.toml @@ -0,0 +1,2 @@ +[build] +target = "wasm32-unknown-unknown" diff --git a/gwasm/lib/.gitignore b/gwasm/lib/.gitignore new file mode 100644 index 00000000000..eb5a316cbd1 --- /dev/null +++ b/gwasm/lib/.gitignore @@ -0,0 +1 @@ +target diff --git a/gwasm/lib/Cargo.lock b/gwasm/lib/Cargo.lock new file mode 100644 index 00000000000..35d8e0186dd --- /dev/null +++ b/gwasm/lib/Cargo.lock @@ -0,0 +1,25 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "dlmalloc" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "203540e710bfadb90e5e29930baf5d10270cec1f43ab34f46f78b147b2de715a" +dependencies = [ + "libc", +] + +[[package]] +name = "gwasm-dlmalloc" +version = "0.0.1" +dependencies = [ + "dlmalloc", +] + +[[package]] +name = "libc" +version = "0.2.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" diff --git a/gwasm/lib/Cargo.toml b/gwasm/lib/Cargo.toml new file mode 100644 index 00000000000..398033150b5 --- /dev/null +++ b/gwasm/lib/Cargo.toml @@ -0,0 +1,7 @@ +[workspace] +members = [ + "dlmalloc" +] + +[workspace.dependencies] +dlmalloc = "0.2.4" diff --git a/gwasm/lib/dlmalloc/Cargo.toml b/gwasm/lib/dlmalloc/Cargo.toml new file mode 100644 index 00000000000..5e8957be6b1 --- /dev/null +++ b/gwasm/lib/dlmalloc/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "gwasm-dlmalloc" +version = "0.0.1" +edition = "2021" + +[lib] +crate-type = [ "cdylib" ] + +[dependencies] +dlmalloc.workspace = true diff --git a/gwasm/lib/dlmalloc/src/lib.rs b/gwasm/lib/dlmalloc/src/lib.rs new file mode 100644 index 00000000000..cc3b8138840 --- /dev/null +++ b/gwasm/lib/dlmalloc/src/lib.rs @@ -0,0 +1,44 @@ +//! Dummy library for exporting dlmalloc-rs as wasm module. +#![no_std] +// #![feature(wasm_import_memory)] +// #![wasm_import_memory] + +use dlmalloc::Dlmalloc; + +static mut DLMALLOC: Dlmalloc = Dlmalloc::new(); + +/// Allocate memory as described by the given `layout`. +#[no_mangle] +pub unsafe extern "C" fn alloc(size: usize, align: usize) -> *mut u8 { + DLMALLOC.malloc(size, align) +} + +/// Deallocate the block of memory at the given `ptr` pointer with the given `layout`. +#[no_mangle] +pub unsafe extern "C" fn dealloc(ptr: *mut u8, size: usize, align: usize) { + DLMALLOC.free(ptr, size, align) +} + +/// Behaves like `alloc`, but also ensures that the contents +/// are set to zero before being returned. +#[no_mangle] +pub unsafe extern "C" fn alloc_zeroed(size: usize, align: usize) -> *mut u8 { + DLMALLOC.calloc(size, align) +} + +/// Shrink or grow a block of memory to the given `new_size` in bytes. +/// The block is described by the given `ptr` pointer and `layout`. +#[no_mangle] +pub unsafe extern "C" fn realloc( + ptr: *mut u8, + size: usize, + align: usize, + new_size: usize, +) -> *mut u8 { + DLMALLOC.realloc(ptr, size, align, new_size) +} + +#[panic_handler] +fn panic(_: &core::panic::PanicInfo) -> ! { + loop {} +} diff --git a/gwasm/processor/Cargo.toml b/gwasm/processor/Cargo.toml new file mode 100644 index 00000000000..91777e6953c --- /dev/null +++ b/gwasm/processor/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "gwasm-processor" +version = "0.1.0" +edition = "2021" + +[dependencies] +wasm-compose = "0.4.0" + +[dev-dependencies] +anyhow.workspace = true +gear-wasm-builder.workspace = true +wasmer = { version = "4.1.0", features = ["singlepass"]} +wasmtime = "11.0.1" + +[build-dependencies] +anyhow.workspace = true +gear-wasm-builder.workspace = true diff --git a/gwasm/processor/benches/module-linking.rs b/gwasm/processor/benches/module-linking.rs new file mode 100644 index 00000000000..2c607465fc2 --- /dev/null +++ b/gwasm/processor/benches/module-linking.rs @@ -0,0 +1,120 @@ +//! Benches for wasm module-linking. +#![feature(test)] + +extern crate test; + +use anyhow::Result; +use gear_wasm_builder::optimize; +use std::{path::PathBuf, process::Command}; +use test::bench::Bencher; + +const DEMO_MEMOP_RELATIVE_PATH: &str = "memop"; +const DEMO_MEMOP_WASM_RELATIVE_PATH: &str = + "memop/target/wasm32-unknown-unknown/release/memop.wasm"; + +/// Build demo memop with different features. +fn build_demo(gwasm: bool) -> Result> { + let demo = PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join(DEMO_MEMOP_RELATIVE_PATH) + .canonicalize()?; + let mut args = vec!["build", "--release", "--no-default-features"]; + + if gwasm { + args.push("--features"); + args.push("gwasm"); + } + + Command::new("cargo") + .env("RUSTFLAGS", "-C link-arg=--import-memory") + .args(&args) + .current_dir(demo) + .status()?; + + optimize::optimize_wasm( + DEMO_MEMOP_WASM_RELATIVE_PATH.into(), + DEMO_MEMOP_WASM_RELATIVE_PATH.into(), + "z", + false, + )?; + std::fs::read(DEMO_MEMOP_WASM_RELATIVE_PATH).map_err(Into::into) +} + +// #[bench] +// fn bench_galloc_memop(b: &mut Bencher) -> Result<()> { +// let wasm = build_demo(false)?; +// b.iter(|| execute(&wasm).expect("Failed to execute")); +// +// Ok(()) +// } + +mod wasmtime { + use crate::{build_demo, Bencher, Result}; + + fn execute(wasm: &[u8]) -> Result<()> { + use ::wasmtime::{Engine, Linker, Memory, MemoryType, Module, Store}; + + let engine = Engine::default(); + let mut linker = Linker::<()>::new(&engine); + let mut store = Store::new(&engine, ()); + + // TODO: calculate this memory. + let memory = Memory::new(&mut store, MemoryType::new(0xffff, None))?; + linker.define(&mut store, "env", "memory", memory)?; + + let memop = Module::from_binary(&engine, wasm)?; + let dlmalloc = Module::from_binary(&engine, &gwasm_processor::DLMALLOC)?; + + let dlmalloc = linker.instantiate(&mut store, &dlmalloc)?; + linker.instance(&mut store, "gwasm-dlmalloc", dlmalloc)?; + + let memop = linker.instantiate(&mut store, &memop)?; + let run = memop.get_typed_func::<(), i64>(&mut store, "memop")?; + let res = run.call(&mut store, ())?; + + assert_eq!(res, 1); + + Ok(()) + } + + #[bench] + fn bench_gwasm_memop(b: &mut Bencher) -> Result<()> { + let wasm = build_demo(true)?; + b.iter(|| execute(&wasm).expect("Failed to execute")); + + Ok(()) + } +} + +mod wasmer { + use crate::{build_demo, Bencher, Result}; + + fn execute(wasm: &[u8]) -> Result<()> { + use ::wasmer::{Imports, Instance, Memory, MemoryType, Module, Store, Value}; + + let mut store = Store::default(); + let dlmalloc = Module::new(&store.engine(), &gwasm_processor::DLMALLOC)?; + let memop = Module::new(&store.engine(), &wasm)?; + + let memory = Memory::new(&mut store, MemoryType::new(0xffff, None, false))?; + let mut imports = Imports::new(); + imports.define("env", "memory", memory); + + let dlmalloc = Instance::new(&mut store, &dlmalloc, &Default::default())?; + imports.register_namespace("gwasm-dlmalloc", dlmalloc.exports); + + let memop = Instance::new(&mut store, &memop, &imports)?; + let res = memop.exports.get_function("memop")?.call(&mut store, &[])?; + + assert_eq!(res[0], Value::I64(1)); + + Ok(()) + } + + #[bench] + fn bench_gwasm_memop(b: &mut Bencher) -> Result<()> { + let wasm = build_demo(true)?; + b.iter(|| execute(&wasm).expect("Failed to execute")); + + Ok(()) + } +} diff --git a/gwasm/processor/build.rs b/gwasm/processor/build.rs new file mode 100644 index 00000000000..a20770e98b5 --- /dev/null +++ b/gwasm/processor/build.rs @@ -0,0 +1,97 @@ +//! Build and import WASM libraries + +use anyhow::Result; +use gear_wasm_builder::optimize::optimize_wasm; +use std::{collections::BTreeMap, env, fs, path::PathBuf, process::Command}; + +const LIBS_RS: &str = "libs.rs"; +const LIBRARY_RELATIVE_DIR: &str = "../lib"; +const LIBRARIES: [&str; 1] = ["dlmalloc"]; +const OPT_LEVEL: &str = "z"; + +// Inject WASM libraries to `OUT_DIR/libs.rs` +// +// TODO: use `syn` and `proc-macro2` to generate code. +fn main() -> Result<()> { + build()?; + let mut libs_rs = String::new(); + + // Inject WASM libraries. + for (lib, path) in libs()? { + let bytes = fs::read(path)?; + + libs_rs.push_str(&format!("/// GWASM library: {}\n", lib)); + // NOTE: consider using `hex`? + libs_rs.push_str(&format!( + "pub const {}: [u8; {}] = {:?};\n\n", + lib.to_uppercase(), + bytes.len(), + bytes + )); + } + + // Inject helper iterator. + { + libs_rs.push_str("/// Count of gwasm libraries.\n"); + libs_rs.push_str(&format!( + "pub const LIBS_LEN: usize = {};\n\n", + LIBRARIES.len() + )); + + libs_rs.push_str("/// GWASM libraries\n"); + libs_rs.push_str("pub const LIBS: [(&str, &[u8]); LIBS_LEN] = ["); + libs_rs.push_str( + &LIBRARIES + .iter() + .map(|lib| format!("(\"{}\", &{}),", lib, lib.to_uppercase())) + .collect::(), + ); + libs_rs.push_str("];\n"); + } + + fs::write( + env::var("OUT_DIR").map(PathBuf::from)?.join(LIBS_RS), + libs_rs, + )?; + + Ok(()) +} + +// Build libraries. +fn build() -> Result<()> { + Command::new("cargo") + .env("RUSTFLAGS", "-C link-arg=--import-memory") + .args(&["build", "--release", "--target", "wasm32-unknown-unknown"]) + .current_dir(PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(LIBRARY_RELATIVE_DIR)) + .status()?; + + Ok(()) +} + +// Get built libraries. +// +// NOTE: ALWAYS use release builds. +fn libs() -> Result> { + let target = { + let mut target = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + target.push(format!( + "{}/target/wasm32-unknown-unknown/release", + LIBRARY_RELATIVE_DIR + )); + target.canonicalize()? + }; + + let libs = LIBRARIES + .into_iter() + .map(|lib| { + let [src, dest] = + ["wasm", "opt.wasm"].map(|ext| target.join(format!("gwasm_{lib}.{ext}"))); + + optimize_wasm(src, dest.clone(), OPT_LEVEL, false)?; + + Ok((lib, dest)) + }) + .collect::>()?; + + Ok(libs) +} diff --git a/gwasm/processor/memop/.cargo/config.toml b/gwasm/processor/memop/.cargo/config.toml new file mode 100644 index 00000000000..24cde140b0e --- /dev/null +++ b/gwasm/processor/memop/.cargo/config.toml @@ -0,0 +1,5 @@ +[build] +target = "wasm32-unknown-unknown" + +[target.'cfg(target_family = \"wasm\")'] +rustflags = "-C --import-memory" diff --git a/gwasm/processor/memop/Cargo.lock b/gwasm/processor/memop/Cargo.lock new file mode 100644 index 00000000000..7d9c7040f7e --- /dev/null +++ b/gwasm/processor/memop/Cargo.lock @@ -0,0 +1,92 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "dlmalloc" +version = "0.1.4" +source = "git+https://github.com/gear-tech/dlmalloc-rust.git?rev=9135baa#9135baa728ef9a9a04a887998e019733c4b093af" +dependencies = [ + "libc", + "libc_print", + "page_size", + "static_assertions", + "str-buf", +] + +[[package]] +name = "galloc" +version = "0.2.2" +dependencies = [ + "dlmalloc", + "gwasm", +] + +[[package]] +name = "gwasm" +version = "0.0.0" + +[[package]] +name = "libc" +version = "0.2.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" + +[[package]] +name = "libc_print" +version = "0.1.16" +source = "git+https://github.com/grishasobol/rust-libc-print.git#b300804809e7a5f1c8fab4d2d11bcea29217bc70" +dependencies = [ + "libc", +] + +[[package]] +name = "memop" +version = "0.1.0" +dependencies = [ + "galloc", +] + +[[package]] +name = "page_size" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eebde548fbbf1ea81a99b128872779c437752fb99f217c45245e1a61dcd9edcd" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "str-buf" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0873cb29201126440dcc78d0b1f5a13d917e78831778429a7920ca9c7f3dae1e" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/gwasm/processor/memop/Cargo.toml b/gwasm/processor/memop/Cargo.toml new file mode 100644 index 00000000000..ecd57f751ee --- /dev/null +++ b/gwasm/processor/memop/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "memop" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["cdylib"] + +[dependencies] +galloc = { path = "../../../galloc" } + +[features] +gwasm = ["galloc/gwasm"] + +[workspace] diff --git a/gwasm/processor/memop/src/lib.rs b/gwasm/processor/memop/src/lib.rs new file mode 100644 index 00000000000..d65799019b8 --- /dev/null +++ b/gwasm/processor/memop/src/lib.rs @@ -0,0 +1,24 @@ +#![no_std] + +extern crate alloc; +extern crate galloc; + +use alloc::vec::Vec; + +#[no_mangle] +pub extern "C" fn memop() -> i64 { + let mut arr = Vec::new(); + + arr.push(42); + // for i in 0..42 { + // arr.push(i); + // } + + arr.len() as i64 +} + +#[cfg(not(test))] +#[panic_handler] +fn panic(_info: &core::panic::PanicInfo) -> ! { + loop {} +} diff --git a/gwasm/processor/src/lib.rs b/gwasm/processor/src/lib.rs new file mode 100644 index 00000000000..8a86e3ae2ae --- /dev/null +++ b/gwasm/processor/src/lib.rs @@ -0,0 +1,22 @@ +//! GWASM processor + +pub use libs::*; + +/// GWASM Libraries +/// +/// - pub const LIBS: list of libraries. +/// - pub const LIBS_LEN: count of libraries. +mod libs { + include!(concat!(env!("OUT_DIR"), "/libs.rs")); +} + +/// Process wasm libraries to linker. +pub fn process(mut link: L) -> Result<(), E> +where + L: FnMut(String, Vec) -> Result<(), E>, +{ + libs::LIBS + .iter() + .map(|(lib, bin)| link(lib.to_string(), bin.to_vec())) + .collect::>() +} diff --git a/gwasm/src/allocator.rs b/gwasm/src/allocator.rs new file mode 100644 index 00000000000..56933983c7e --- /dev/null +++ b/gwasm/src/allocator.rs @@ -0,0 +1,31 @@ +use core::alloc::{GlobalAlloc, Layout}; + +#[link(wasm_import_module = "gwasm-dlmalloc")] +extern "C" { + fn alloc(size: usize, align: usize) -> *mut u8; + fn dealloc(ptr: *mut u8, size: usize, align: usize); + fn alloc_zeroed(size: usize, align: usize) -> *mut u8; + fn realloc(ptr: *mut u8, align: usize, size: usize, new_size: usize) -> *mut u8; +} + +/// A global allocator for the wasm32-unknown-unknown target that +/// uses the dlmalloc library. +pub struct Allocator; + +unsafe impl GlobalAlloc for Allocator { + unsafe fn alloc(&self, layout: Layout) -> *mut u8 { + alloc(layout.size(), layout.align()) + } + + unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { + dealloc(ptr, layout.size(), layout.align()) + } + + unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { + alloc_zeroed(layout.size(), layout.align()) + } + + unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { + realloc(ptr, layout.align(), layout.size(), new_size) + } +} diff --git a/gwasm/src/lib.rs b/gwasm/src/lib.rs new file mode 100644 index 00000000000..170f378766f --- /dev/null +++ b/gwasm/src/lib.rs @@ -0,0 +1,6 @@ +//! Gear wasm libraries. +#![no_std] +#![deny(missing_docs)] +mod allocator; + +pub use allocator::Allocator; diff --git a/runtime-interface/Cargo.toml b/runtime-interface/Cargo.toml index 861e339545b..d302c81da20 100644 --- a/runtime-interface/Cargo.toml +++ b/runtime-interface/Cargo.toml @@ -41,3 +41,4 @@ std = [ "gear-sandbox-host", ] host-sandbox = ["gear-sandbox-host?/host-sandbox"] +experimental-features = ["gear-sandbox-host?/experimental-features"] diff --git a/sandbox/host/Cargo.toml b/sandbox/host/Cargo.toml index 4d5ecdf98cb..d5b5c9bbe08 100644 --- a/sandbox/host/Cargo.toml +++ b/sandbox/host/Cargo.toml @@ -25,10 +25,14 @@ gear-sandbox-env = { workspace = true, features = ["std"] } wasmer-cache = { version = "2.2.1", optional = true } once_cell = "1.17.1" tempfile = "3.5.0" +gwasm-processor = { workspace = true, optional = true } [features] default = ["host-sandbox"] host-sandbox = [ "wasmer", - "wasmer-cache", + "wasmer-cache" +] +experimental-features = [ + "gwasm-processor" ] diff --git a/sandbox/host/src/sandbox/wasmer_backend.rs b/sandbox/host/src/sandbox/wasmer_backend.rs index 27c92864aef..698304adc82 100644 --- a/sandbox/host/src/sandbox/wasmer_backend.rs +++ b/sandbox/host/src/sandbox/wasmer_backend.rs @@ -256,6 +256,24 @@ pub fn instantiate( import_object.register(module_name, exports); } + // Register linking modules + // + // TODO: refactor this after #2990 + #[cfg(feature = "experimental-features")] + { + let link = |name, code| -> std::result::Result<(), InstantiationError> { + let module = Module::new(&context.store, code) + .map_err(|_| InstantiationError::ModuleDecoding)?; + let instance = wasmer::Instance::new(&module, &import_object) + .map_err(|_| InstantiationError::Instantiation)?; + import_object.register(name, instance.exports); + + Ok(()) + }; + + gwasm_processor::process(link).map_err(|_| InstantiationError::ModuleDecoding)?; + } + let instance = SandboxContextStore::using(sandbox_context, || { wasmer::Instance::new(&module, &import_object).map_err(|error| match error { wasmer::InstantiationError::Link(_) => InstantiationError::Instantiation, diff --git a/sandbox/host/src/util.rs b/sandbox/host/src/util.rs index b890e088e2d..4050025c18a 100644 --- a/sandbox/host/src/util.rs +++ b/sandbox/host/src/util.rs @@ -49,3 +49,11 @@ pub trait MemoryTransfer { /// Returns host pointer to the wasm memory buffer. fn get_buff(&mut self) -> *mut u8; } + +/// Enabled libraries +/// +/// TODO: refactor this in #2990 +pub trait Libraries { + /// Enable libraries. + fn enable(&mut self, libraries: &[&str]) -> Result<()>; +} diff --git a/sandbox/sandbox/Cargo.toml b/sandbox/sandbox/Cargo.toml index 36dbf5ddaed..c85e361ca33 100644 --- a/sandbox/sandbox/Cargo.toml +++ b/sandbox/sandbox/Cargo.toml @@ -41,3 +41,4 @@ std = [ ] strict = [] host-sandbox = ["gear-runtime-interface/host-sandbox"] +experimental-features = ["gear-runtime-interface/experimental-features"]