From e1c42b5f90361b709f81354f16a4268b9e3eb693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 16 Dec 2022 23:40:17 +0100 Subject: [PATCH 01/25] Revert "Revert "Implement wasmer init and wasmer publish"" This reverts commit 250ebff4e8ce250e40c61d273e5627adf3c0f90d. --- .gitignore | 1 + Cargo.lock | 331 ++++++++- Cargo.toml | 1 + Makefile | 3 +- .../assets/{qjs-wapm.toml => qjs-wasmer.toml} | 0 lib/cli/Cargo.toml | 17 +- lib/cli/sql/migrations/0000.sql | 27 + lib/cli/sql/migrations/0001.sql | 9 + lib/cli/sql/migrations/0002.sql | 26 + lib/cli/src/cli.rs | 19 +- lib/cli/src/commands.rs | 6 +- lib/cli/src/commands/init.rs | 503 +++++++++++++ lib/cli/src/commands/publish.rs | 679 ++++++++++++++++++ lib/cli/src/commands/sql/get_interface.sql | 4 + lib/cli/src/commands/sql/insert_interface.sql | 3 + .../sql/wasm_interface_existence_check.sql | 5 + lib/cli/src/commands/whoami.rs | 2 +- lib/registry/Cargo.toml | 5 +- .../queries/get_interface_version.graphql | 9 + .../graphql/queries/get_signed_url.graphql | 5 + .../queries/publish_package_chunked.graphql | 22 + lib/registry/src/config.rs | 11 + lib/registry/src/graphql.rs | 54 ++ lib/registry/src/interface.rs | 47 ++ lib/registry/src/lib.rs | 18 +- lib/registry/src/package.rs | 19 +- lib/registry/src/publish.rs | 243 +++++++ lib/wasm-interface/Cargo.toml | 24 + lib/wasm-interface/README.md | 88 +++ lib/wasm-interface/src/interface.rs | 205 ++++++ lib/wasm-interface/src/interface_matcher.rs | 29 + lib/wasm-interface/src/lib.rs | 13 + lib/wasm-interface/src/parser.rs | 596 +++++++++++++++ lib/wasm-interface/src/validate.rs | 465 ++++++++++++ tests/integration/cli/Cargo.toml | 1 + .../integration/cli/tests/fixtures/init1.toml | 20 + .../integration/cli/tests/fixtures/init2.toml | 6 + .../integration/cli/tests/fixtures/init3.toml | 8 + .../integration/cli/tests/fixtures/init4.toml | 20 + .../integration/cli/tests/fixtures/init5.toml | 7 + .../integration/cli/tests/fixtures/init6.toml | 13 + tests/integration/cli/tests/init.rs | 127 ++++ tests/integration/cli/tests/publish.rs | 148 ++++ tests/integration/cli/tests/run.rs | 6 +- 44 files changed, 3791 insertions(+), 54 deletions(-) rename lib/c-api/examples/assets/{qjs-wapm.toml => qjs-wasmer.toml} (100%) create mode 100644 lib/cli/sql/migrations/0000.sql create mode 100644 lib/cli/sql/migrations/0001.sql create mode 100644 lib/cli/sql/migrations/0002.sql create mode 100644 lib/cli/src/commands/init.rs create mode 100644 lib/cli/src/commands/publish.rs create mode 100644 lib/cli/src/commands/sql/get_interface.sql create mode 100644 lib/cli/src/commands/sql/insert_interface.sql create mode 100644 lib/cli/src/commands/sql/wasm_interface_existence_check.sql create mode 100644 lib/registry/graphql/queries/get_interface_version.graphql create mode 100644 lib/registry/graphql/queries/get_signed_url.graphql create mode 100644 lib/registry/graphql/queries/publish_package_chunked.graphql create mode 100644 lib/registry/src/interface.rs create mode 100644 lib/registry/src/publish.rs create mode 100644 lib/wasm-interface/Cargo.toml create mode 100644 lib/wasm-interface/README.md create mode 100644 lib/wasm-interface/src/interface.rs create mode 100644 lib/wasm-interface/src/interface_matcher.rs create mode 100644 lib/wasm-interface/src/lib.rs create mode 100644 lib/wasm-interface/src/parser.rs create mode 100644 lib/wasm-interface/src/validate.rs create mode 100644 tests/integration/cli/tests/fixtures/init1.toml create mode 100644 tests/integration/cli/tests/fixtures/init2.toml create mode 100644 tests/integration/cli/tests/fixtures/init3.toml create mode 100644 tests/integration/cli/tests/fixtures/init4.toml create mode 100644 tests/integration/cli/tests/fixtures/init5.toml create mode 100644 tests/integration/cli/tests/fixtures/init6.toml create mode 100644 tests/integration/cli/tests/init.rs create mode 100644 tests/integration/cli/tests/publish.rs diff --git a/.gitignore b/.gitignore index 24affcea4df..da8d8e39bb9 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ api-docs-repo/ /src/windows-installer/WasmerInstaller.exe /lib/c-api/wasmer.h .xwin-cache +wapm.toml # Generated by tests on Android /avd /core diff --git a/Cargo.lock b/Cargo.lock index 068b0c26887..98a7ef9d558 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -73,6 +73,12 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" +[[package]] +name = "arrayvec" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" + [[package]] name = "arrayvec" version = "0.7.2" @@ -176,7 +182,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ae2468a89544a466886840aa467a25b766499f4f04bf7d9fcd10ecee9fccef" dependencies = [ "arrayref", - "arrayvec", + "arrayvec 0.7.2", "cc", "cfg-if 1.0.0", "constant_time_eq", @@ -264,6 +270,38 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c58ec36aac5066d5ca17df51b3e70279f5670a72102f5752cb7e7c856adfc70" +[[package]] +name = "camino" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ad0e1e3e88dd237a156ab9f571021b8a158caa0ae44b1968a241efb5144c1e" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo-platform" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbdb825da8a5df079a43676dbe042702f1707b1109f713a01420fbb4cc71fa27" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo_metadata" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "982a0cf6a99c350d7246035613882e376d58cebe571785abc5da4f648d53ac0a" +dependencies = [ + "camino", + "cargo-platform", + "semver 1.0.14", + "serde", + "serde_json", + "thiserror", +] + [[package]] name = "cast" version = "0.3.0" @@ -324,6 +362,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "cipher" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1873270f8f7942c191139cb8a40fd228da6c3fd2fc376d7e92d47aa14aeb59e" +dependencies = [ + "crypto-common", + "inout", +] + [[package]] name = "clap" version = "2.34.0" @@ -1055,6 +1103,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" +[[package]] +name = "fallible-streaming-iterator" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" + [[package]] name = "fastrand" version = "1.8.0" @@ -1431,6 +1485,15 @@ dependencies = [ "ahash", ] +[[package]] +name = "hashlink" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69fe1fcf8b4278d860ad0548329f892a3631fb63f82574df68275f34cdbe0ffa" +dependencies = [ + "hashbrown 0.12.3", +] + [[package]] name = "heck" version = "0.3.3" @@ -1461,6 +1524,15 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + [[package]] name = "http" version = "0.2.8" @@ -1612,6 +1684,18 @@ dependencies = [ "serde", ] +[[package]] +name = "indicatif" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4295cbb7573c16d310e99e713cf9e75101eb190ab31fccd35f2d2691b4352b19" +dependencies = [ + "console", + "number_prefix", + "portable-atomic", + "unicode-width", +] + [[package]] name = "inkwell" version = "0.1.0-beta.4" @@ -1666,6 +1750,15 @@ dependencies = [ "rustc_version 0.3.3", ] +[[package]] +name = "inout" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" +dependencies = [ + "generic-array", +] + [[package]] name = "instant" version = "0.1.12" @@ -1757,6 +1850,19 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" +[[package]] +name = "lexical-core" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6607c62aa161d23d17a9072cc5da0be67cdfc89d3afb1e8d9c842bebc2525ffe" +dependencies = [ + "arrayvec 0.5.2", + "bitflags", + "cfg-if 1.0.0", + "ryu", + "static_assertions", +] + [[package]] name = "lexical-sort" version = "0.3.1" @@ -1794,19 +1900,24 @@ dependencies = [ ] [[package]] -name = "link-cplusplus" -version = "1.0.7" +name = "libsqlite3-sys" +version = "0.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9272ab7b96c9046fbc5bc56c06c117cb639fe2d509df0c421cad82d2915cf369" +checksum = "29f835d03d717946d28b1d1ed632eb6f0e24a299388ee623d0c23118d3e8a7fa" dependencies = [ "cc", + "pkg-config", + "vcpkg", ] [[package]] -name = "linked-hash-map" -version = "0.5.6" +name = "link-cplusplus" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" +checksum = "9272ab7b96c9046fbc5bc56c06c117cb639fe2d509df0c421cad82d2915cf369" +dependencies = [ + "cc", +] [[package]] name = "llvm-sys" @@ -1971,6 +2082,17 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" +[[package]] +name = "minisign" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce49953dd06a44e1034590bb619bfe8900c29500053c0c0f83e9260a34466aa5" +dependencies = [ + "getrandom", + "rpassword", + "scrypt", +] + [[package]] name = "miniz_oxide" version = "0.5.4" @@ -2042,6 +2164,17 @@ dependencies = [ "pin-utils", ] +[[package]] +name = "nom" +version = "5.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af" +dependencies = [ + "lexical-core", + "memchr", + "version_check", +] + [[package]] name = "nom" version = "7.1.1" @@ -2093,6 +2226,12 @@ dependencies = [ "libc", ] +[[package]] +name = "number_prefix" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" + [[package]] name = "object" version = "0.28.4" @@ -2194,6 +2333,15 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ecba01bf2678719532c5e3059e0b5f0811273d94b397088b82e3bd0a78c78fdd" +[[package]] +name = "pbkdf2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" +dependencies = [ + "digest", +] + [[package]] name = "percent-encoding" version = "2.2.0" @@ -2256,6 +2404,12 @@ dependencies = [ "plotters-backend", ] +[[package]] +name = "portable-atomic" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac662b3a6490de378b0ee15cf2dfff7127aebfe0b19acc65e7fbca3d299c3788" + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -2711,6 +2865,41 @@ dependencies = [ "syn", ] +[[package]] +name = "rpassword" +version = "7.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6678cf63ab3491898c0d021b493c94c9b221d91295294a2a5746eacbe5928322" +dependencies = [ + "libc", + "rtoolbox", + "winapi", +] + +[[package]] +name = "rtoolbox" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "034e22c514f5c0cb8a10ff341b9b048b5ceb21591f31c8f44c43b960f9b3524a" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "rusqlite" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01e213bc3ecb39ac32e81e51ebe31fd888a940515173e3a18a35f8c6e896422a" +dependencies = [ + "bitflags", + "fallible-iterator", + "fallible-streaming-iterator", + "hashlink", + "libsqlite3-sys", + "smallvec", +] + [[package]] name = "rustc-demangle" version = "0.1.21" @@ -2802,6 +2991,15 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" +[[package]] +name = "salsa20" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97a22f5af31f73a954c10289c93e8a50cc23d971e80ee446f1f6f7137a088213" +dependencies = [ + "cipher", +] + [[package]] name = "same-file" version = "1.0.6" @@ -2829,6 +3027,18 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" +[[package]] +name = "scrypt" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f9e24d2b632954ded8ab2ef9fea0a0c769ea56ea98bddbafbad22caeeadf45d" +dependencies = [ + "hmac", + "pbkdf2", + "salsa20", + "sha2", +] + [[package]] name = "sct" version = "0.6.1" @@ -2997,14 +3207,15 @@ dependencies = [ [[package]] name = "serde_yaml" -version = "0.8.26" +version = "0.9.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578a7433b776b56a35785ed5ce9a7e777ac0598aac5a6dd1b4b18a307c7fc71b" +checksum = "6d232d893b10de3eb7258ff01974d6ee20663d8e833263c99409d4b13a0209da" dependencies = [ "indexmap", + "itoa 1.0.4", "ryu", "serde", - "yaml-rust", + "unsafe-libyaml", ] [[package]] @@ -3128,6 +3339,12 @@ dependencies = [ "version_check", ] +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "stdweb" version = "0.4.20" @@ -3391,11 +3608,29 @@ dependencies = [ "libc", "standback", "stdweb", - "time-macros", + "time-macros 0.1.1", "version_check", "winapi", ] +[[package]] +name = "time" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376" +dependencies = [ + "itoa 1.0.4", + "serde", + "time-core", + "time-macros 0.2.6", +] + +[[package]] +name = "time-core" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" + [[package]] name = "time-macros" version = "0.1.1" @@ -3406,6 +3641,15 @@ dependencies = [ "time-macros-impl", ] +[[package]] +name = "time-macros" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d967f99f534ca7e495c575c62638eebc2898a8c84c119b89e250477bc4ba16b2" +dependencies = [ + "time-core", +] + [[package]] name = "time-macros-impl" version = "0.1.2" @@ -3694,6 +3938,12 @@ dependencies = [ "void", ] +[[package]] +name = "unsafe-libyaml" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1e5fa573d8ac5f1a856f8d7be41d390ee973daf97c806b2c1a465e4e1406e68" + [[package]] name = "untrusted" version = "0.7.1" @@ -3712,6 +3962,12 @@ dependencies = [ "serde", ] +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "version-compare" version = "0.1.1" @@ -3762,15 +4018,14 @@ dependencies = [ [[package]] name = "wapm-toml" -version = "0.2.2" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a61b6d3b6a2fc171198e6378b3a9b38650e114298775a9e63401613abb6a10b3" +checksum = "994ef26447f3158955d2e3fca96021d1f1c47b830e2053569177673dca1447a9" dependencies = [ "anyhow", "semver 1.0.14", "serde", "serde_cbor", - "serde_derive", "serde_json", "serde_yaml", "thiserror", @@ -4056,6 +4311,7 @@ dependencies = [ "anyhow", "atty", "bytesize", + "cargo_metadata", "cfg-if 1.0.0", "chrono", "clap 3.2.23", @@ -4064,21 +4320,29 @@ dependencies = [ "dirs", "distance", "fern", + "flate2", "hex", "http_req", "isatty", "libc", "log", + "minisign", "nuke-dir", "prettytable-rs", "regex", "reqwest", + "rpassword", + "rusqlite", + "semver 1.0.14", "serde", "serde_json", "spinoff", + "tar", "target-lexicon 0.12.5", "tempdir", "tempfile", + "thiserror", + "time 0.3.17", "tldextract", "toml", "unix_mode", @@ -4099,7 +4363,9 @@ dependencies = [ "wasmer-vm", "wasmer-wasi", "wasmer-wasi-experimental-io-devices", + "wasmer-wasm-interface", "wasmer-wast", + "wasmparser 0.51.4", "webc", ] @@ -4232,7 +4498,7 @@ dependencies = [ "lazy_static", "libc", "log", - "time", + "time 0.2.27", "wasmer", "wasmer-types", ] @@ -4271,6 +4537,7 @@ version = "3.1.0" dependencies = [ "anyhow", "flate2", + "pretty_assertions", "rand 0.8.5", "tar", "target-lexicon 0.12.5", @@ -4304,6 +4571,7 @@ name = "wasmer-registry" version = "3.1.0" dependencies = [ "anyhow", + "console", "dirs", "filetime", "flate2", @@ -4311,6 +4579,8 @@ dependencies = [ "futures-util", "graphql_client", "hex", + "indicatif", + "lazy_static", "log", "lzma-rs", "rand 0.8.5", @@ -4463,7 +4733,7 @@ dependencies = [ "byteorder", "pretty_assertions", "serde", - "time", + "time 0.2.27", "wasmer", "wasmer-derive", "wasmer-types", @@ -4473,6 +4743,18 @@ dependencies = [ "wasmer-wit-parser", ] +[[package]] +name = "wasmer-wasm-interface" +version = "3.1.0" +dependencies = [ + "bincode", + "either", + "nom 5.1.2", + "serde", + "wasmparser 0.51.4", + "wat", +] + [[package]] name = "wasmer-wast" version = "3.1.0" @@ -4586,6 +4868,12 @@ dependencies = [ "wasmer-wast", ] +[[package]] +name = "wasmparser" +version = "0.51.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aeb1956b19469d1c5e63e459d29e7b5aa0f558d9f16fcef09736f8a265e6c10a" + [[package]] name = "wasmparser" version = "0.83.0" @@ -4972,7 +5260,7 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "463705a63313cd4301184381c5e8042f0a7e9b4bb63653f216311d4ae74690b7" dependencies = [ - "nom", + "nom 7.1.1", ] [[package]] @@ -4981,15 +5269,6 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2d7d3948613f75c98fd9328cfdcc45acc4d360655289d0a7d4ec931392200a3" -[[package]] -name = "yaml-rust" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" -dependencies = [ - "linked-hash-map", -] - [[package]] name = "yansi" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index 931d979465e..25dbdf20a83 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,6 +47,7 @@ members = [ "lib/wasi-types", "lib/wasi-experimental-io-devices", "lib/wasi-local-networking", + "lib/wasm-interface", "lib/c-api/tests/wasmer-c-api-test-runner", "lib/c-api/examples/wasmer-capi-examples-runner", "lib/types", diff --git a/Makefile b/Makefile index 0123ebf7c97..55a2bc43234 100644 --- a/Makefile +++ b/Makefile @@ -401,7 +401,7 @@ else strip --strip-unneeded target/$(HOST_TARGET)/release/wasmer-headless endif -WAPM_VERSION = v0.5.3 +WAPM_VERSION = v0.5.9 get-wapm: [ -d "wapm-cli" ] || git clone --branch $(WAPM_VERSION) https://github.com/wasmerio/wapm-cli.git @@ -549,6 +549,7 @@ test-examples: $(CARGO_BINARY) test $(CARGO_TARGET) --release $(compiler_features) --features wasi --examples test-integration-cli: + rustup target add wasm32-wasi $(CARGO_BINARY) test $(CARGO_TARGET) --features webc_runner --no-fail-fast -p wasmer-integration-tests-cli -- --nocapture --test-threads=1 test-integration-ios: diff --git a/lib/c-api/examples/assets/qjs-wapm.toml b/lib/c-api/examples/assets/qjs-wasmer.toml similarity index 100% rename from lib/c-api/examples/assets/qjs-wapm.toml rename to lib/c-api/examples/assets/qjs-wasmer.toml diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index ac8a1d9b639..6a827438197 100644 --- a/lib/cli/Cargo.toml +++ b/lib/cli/Cargo.toml @@ -40,6 +40,8 @@ wasmer-types = { version = "=3.1.0", path = "../types" } wasmer-registry = { version = "=3.1.0", path = "../registry" } wasmer-object = { version = "=3.1.0", path = "../object", optional = true } wasmer-vfs = { version = "=3.1.0", path = "../vfs", default-features = false, features = ["host-fs"] } +wasmer-wasm-interface = { version = "3.1.0", path = "../wasm-interface" } +wasmparser = "0.51.4" atty = "0.2" colored = "2.0" anyhow = "1.0" @@ -52,7 +54,6 @@ bytesize = "1.0" cfg-if = "1.0" # For debug feature fern = { version = "0.6", features = ["colored"], optional = true } -log = { version = "0.4", optional = true } tempfile = "3" tempdir = "0.3.7" http_req = { version="^0.8", default-features = false, features = ["rust-tls"] } @@ -62,7 +63,7 @@ dirs = { version = "4.0" } serde_json = { version = "1.0" } target-lexicon = { version = "0.12", features = ["std"] } prettytable-rs = "0.9.0" -wapm-toml = "0.2.0" +wapm-toml = "0.4.0" walkdir = "2.3.2" regex = "1.6.0" toml = "0.5.9" @@ -74,6 +75,16 @@ isatty = "0.1.9" dialoguer = "0.10.2" tldextract = "0.6.0" hex = "0.4.3" +flate2 = "1.0.25" +cargo_metadata = "0.15.2" +rusqlite = { version = "0.28.0", features = ["bundled"] } +tar = "0.4.38" +thiserror = "1.0.37" +time = { version = "0.3.17", default-features = false, features = ["parsing", "std", "formatting"] } +log = "0.4.17" +minisign = "0.7.2" +semver = "1.0.14" +rpassword = "7.2.0" [build-dependencies] chrono = { version = "^0.4", default-features = false, features = [ "std", "clock" ] } @@ -144,7 +155,7 @@ llvm = [ "wasmer-compiler-llvm", "compiler", ] -debug = ["fern", "log", "wasmer-wasi/logging"] +debug = ["fern", "wasmer-wasi/logging"] disable-all-logging = ["wasmer-wasi/disable-all-logging"] headless = [] headless-minimal = ["headless", "disable-all-logging", "wasi"] diff --git a/lib/cli/sql/migrations/0000.sql b/lib/cli/sql/migrations/0000.sql new file mode 100644 index 00000000000..a527dbc4f29 --- /dev/null +++ b/lib/cli/sql/migrations/0000.sql @@ -0,0 +1,27 @@ +CREATE TABLE personal_keys +( + id integer primary key, + active integer not null, + public_key_id text not null UNIQUE, + public_key_value text not null UNIQUE, + private_key_location text UNIQUE, + key_type_identifier text not null, + date_added text not null +); + +CREATE TABLE wapm_users +( + id integer primary key, + name text not null UNIQUE +); + +CREATE TABLE wapm_public_keys +( + id integer primary key, + public_key_id text not null UNIQUE, + user_key integer not null, + public_key_value text not null UNIQUE, + key_type_identifier text not null, + date_added text not null, + FOREIGN KEY(user_key) REFERENCES wapm_users(id) +); diff --git a/lib/cli/sql/migrations/0001.sql b/lib/cli/sql/migrations/0001.sql new file mode 100644 index 00000000000..42587319156 --- /dev/null +++ b/lib/cli/sql/migrations/0001.sql @@ -0,0 +1,9 @@ +CREATE TABLE wasm_contracts +( + id integer primary key, + contract_name text not null, + version text not null, + date_added text not null, + content text not null, + CONSTRAINT name_version_unique UNIQUE (contract_name, version) +); diff --git a/lib/cli/sql/migrations/0002.sql b/lib/cli/sql/migrations/0002.sql new file mode 100644 index 00000000000..cc57ff9b8ee --- /dev/null +++ b/lib/cli/sql/migrations/0002.sql @@ -0,0 +1,26 @@ +PRAGMA foreign_keys=off; + +CREATE TABLE wasm_interfaces +( + id integer primary key, + interface_name text not null, + version text not null, + date_added text not null, + content text not null, + CONSTRAINT name_version_unique UNIQUE (interface_name, version) +); + +INSERT INTO wasm_interfaces +( + id, + interface_name, + version, + date_added, + content +) + SELECT id, contract_name, version, date_added, content + FROM wasm_contracts; + +DROP TABLE wasm_contracts; + +PRAGMA foreign_keys=on; diff --git a/lib/cli/src/cli.rs b/lib/cli/src/cli.rs index 3b9b8cea6f3..b9f6a55ab51 100644 --- a/lib/cli/src/cli.rs +++ b/lib/cli/src/cli.rs @@ -11,7 +11,7 @@ use crate::commands::CreateObj; #[cfg(feature = "wast")] use crate::commands::Wast; use crate::commands::{ - Add, Cache, Config, Inspect, List, Login, Run, SelfUpdate, Validate, Whoami, + Add, Cache, Config, Init, Inspect, List, Login, Publish, Run, SelfUpdate, Validate, Whoami, }; use crate::error::PrettyError; use clap::{CommandFactory, ErrorKind, Parser}; @@ -46,6 +46,10 @@ enum WasmerCLIOptions { /// Login into a wapm.io-like registry Login(Login), + /// Login into a wapm.io-like registry + #[clap(name = "publish")] + Publish(Publish), + /// Wasmer cache #[clap(subcommand)] Cache(Cache), @@ -135,6 +139,10 @@ enum WasmerCLIOptions { /// Inspect a WebAssembly file Inspect(Inspect), + /// Initializes a new wapm.toml file + #[clap(name = "init")] + Init(Init), + /// Run spec testsuite #[cfg(feature = "wast")] Wast(Wast), @@ -165,8 +173,10 @@ impl WasmerCLIOptions { Self::CreateObj(create_obj) => create_obj.execute(), Self::Config(config) => config.execute(), Self::Inspect(inspect) => inspect.execute(), + Self::Init(init) => init.execute(), Self::List(list) => list.execute(), Self::Login(login) => login.execute(), + Self::Publish(publish) => publish.execute(), #[cfg(feature = "wast")] Self::Wast(wast) => wast.execute(), #[cfg(target_os = "linux")] @@ -224,10 +234,9 @@ fn wasmer_main_inner() -> Result<(), anyhow::Error> { WasmerCLIOptions::Run(Run::from_binfmt_args()) } else { match command.unwrap_or(&"".to_string()).as_ref() { - "add" | "cache" | "compile" | "config" | "create-exe" | "help" | "inspect" | "run" - | "self-update" | "validate" | "wast" | "binfmt" | "list" | "login" => { - WasmerCLIOptions::parse() - } + "add" | "cache" | "compile" | "config" | "create-exe" | "help" | "inspect" | "init" + | "run" | "self-update" | "validate" | "wast" | "binfmt" | "list" | "login" + | "publish" => WasmerCLIOptions::parse(), _ => { WasmerCLIOptions::try_parse_from(args.iter()).unwrap_or_else(|e| { match e.kind() { diff --git a/lib/cli/src/commands.rs b/lib/cli/src/commands.rs index d59d5c78cf4..00b814d4df5 100644 --- a/lib/cli/src/commands.rs +++ b/lib/cli/src/commands.rs @@ -10,9 +10,11 @@ mod config; mod create_exe; #[cfg(feature = "static-artifact-create")] mod create_obj; +mod init; mod inspect; mod list; mod login; +mod publish; mod run; mod self_update; mod validate; @@ -31,8 +33,8 @@ pub use create_obj::*; #[cfg(feature = "wast")] pub use wast::*; pub use { - add::*, cache::*, config::*, inspect::*, list::*, login::*, run::*, self_update::*, - validate::*, whoami::*, + add::*, cache::*, config::*, init::*, inspect::*, list::*, login::*, publish::*, run::*, + self_update::*, validate::*, whoami::*, }; /// The kind of object format to emit. diff --git a/lib/cli/src/commands/init.rs b/lib/cli/src/commands/init.rs new file mode 100644 index 00000000000..7b1a206c3e2 --- /dev/null +++ b/lib/cli/src/commands/init.rs @@ -0,0 +1,503 @@ +use anyhow::Context; +use cargo_metadata::{CargoOpt, MetadataCommand}; +use clap::Parser; +use std::collections::HashMap; +use std::path::Path; +use std::path::PathBuf; + +static NOTE: &str = + "# See more keys and definitions at https://docs.wasmer.io/ecosystem/wapm/manifest"; + +const NEWLINE: &str = if cfg!(windows) { "\r\n" } else { "\n" }; + +/// CLI args for the `wasmer init` command +#[derive(Debug, Parser)] +pub struct Init { + /// Initialize wapm.toml for a library package + #[clap(long, group = "crate-type")] + pub lib: bool, + /// Initialize wapm.toml for a binary package + #[clap(long, group = "crate-type")] + pub bin: bool, + /// Initialize an empty wapm.toml + #[clap(long, group = "crate-type")] + pub empty: bool, + /// Force overwriting the wapm.toml, even if it already exists + #[clap(long)] + pub overwrite: bool, + /// Don't display debug output + #[clap(long)] + pub quiet: bool, + /// Namespace to init with, default = current logged in user or _ + #[clap(long)] + pub namespace: Option, + /// Package name to init with, default = Cargo.toml name or current directory name + #[clap(long)] + pub package_name: Option, + /// Version of the initialized package + #[clap(long)] + pub version: Option, + /// If the `manifest-path` is a Cargo.toml, use that file to initialize the wapm.toml + #[clap(long)] + pub manifest_path: Option, + /// Add default dependencies for common packages + #[clap(long, value_enum)] + pub template: Option