From f1a2417dfc4987f3340bcbc3531c216c6dc006c9 Mon Sep 17 00:00:00 2001 From: Taylor Thomas Date: Tue, 3 Sep 2024 16:30:48 -0600 Subject: [PATCH] ref(*)!: Updates all code to use the new publish functionality in wkg This finishes replacing a direct dependency on warg with the newly released published functionality in wasm-pkg-tools. Please note that this removes some warg specific flags and it updates tests. Signed-off-by: Taylor Thomas --- Cargo.lock | 487 ++++++++++++++++------------- Cargo.toml | 16 +- crates/core/Cargo.toml | 3 - crates/core/src/registry.rs | 43 +-- crates/wit/Cargo.toml | 6 +- crates/wit/README.md | 7 - crates/wit/src/commands/publish.rs | 34 +- crates/wit/src/lib.rs | 89 +++--- crates/wit/tests/add.rs | 6 +- crates/wit/tests/publish.rs | 58 ++-- crates/wit/tests/support/mod.rs | 11 +- crates/wit/tests/update.rs | 12 +- src/commands/publish.rs | 53 ++-- src/config.rs | 8 - src/lib.rs | 83 ++--- tests/add.rs | 46 +-- tests/new.rs | 9 +- tests/publish.rs | 94 ++---- tests/support/mod.rs | 62 +--- tests/update.rs | 65 +--- 20 files changed, 462 insertions(+), 730 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7fff07ea..527c3e26 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -617,9 +617,6 @@ dependencies = [ "toml_edit 0.22.14", "unicode-width", "url", - "warg-client", - "warg-crypto", - "warg-protocol", "wasm-pkg-client", "windows-sys 0.52.0", "wit-component 0.208.1", @@ -694,7 +691,7 @@ dependencies = [ "num-traits 0.2.19", "serde 1.0.203", "wasm-bindgen", - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -1206,21 +1203,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -1590,22 +1572,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", + "webpki-roots", ] [[package]] @@ -2178,23 +2145,6 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "defc4c55412d89136f966bbb339008b474350e5e6e78d2714439c386b3137a03" -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "nix" version = "0.26.4" @@ -2351,10 +2301,10 @@ dependencies = [ ] [[package]] -name = "oci-distribution" -version = "0.11.0" +name = "oci-client" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b95a2c51531af0cb93761f66094044ca6ea879320bccd35ab747ff3fcab3f422" +checksum = "0f5098b86f972ac3484f7c9011bbbbd64aaa7e21d10d2c1a91fefb4ad0ba2ad9" dependencies = [ "bytes", "chrono", @@ -2377,19 +2327,19 @@ dependencies = [ [[package]] name = "oci-wasm" -version = "0.0.4" +version = "0.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a91502e5352f927156f2b6a28d2558cc59558b1f441b681df3f706ced6937e07" +checksum = "1d3493d1985a31c5fbd4b37f72a319aab88b55908185a5a799219c6152e9da9b" dependencies = [ "anyhow", "chrono", - "oci-distribution", + "oci-client", "serde 1.0.203", "serde_json", "sha2", "tokio", - "wit-component 0.209.1", - "wit-parser 0.209.1", + "wit-component 0.215.0", + "wit-parser 0.215.0", ] [[package]] @@ -2409,50 +2359,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "openssl" -version = "0.10.64" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" -dependencies = [ - "bitflags 2.5.0", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.66", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.102" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c597637d56fbc83893a35eb0dd04b2b8e7a50c91e64e9493e398b5df4fb45fa2" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "option-ext" version = "0.2.0" @@ -2528,7 +2434,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -2658,12 +2564,6 @@ dependencies = [ "spki", ] -[[package]] -name = "pkg-config" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" - [[package]] name = "polling" version = "2.8.0" @@ -2894,6 +2794,54 @@ dependencies = [ "tint", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2 0.5.7", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2 0.5.7", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -3008,9 +2956,9 @@ checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" [[package]] name = "reqwest" -version = "0.12.5" +version = "0.12.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7d6d2a27d57148378eb5e111173f4276ad26340ecc5c49a4a2152167a2d6a37" +checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" dependencies = [ "base64 0.22.1", "bytes", @@ -3023,24 +2971,25 @@ dependencies = [ "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde 1.0.203", "serde_json", "serde_urlencoded", "sync_wrapper 1.0.1", "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tokio-socks", "tokio-util", "tower-service", @@ -3049,7 +2998,8 @@ dependencies = [ "wasm-bindgen-futures", "wasm-streams", "web-sys", - "winreg", + "webpki-roots", + "windows-registry", ] [[package]] @@ -3110,6 +3060,12 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +[[package]] +name = "rustc-hash" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" + [[package]] name = "rustix" version = "0.37.27" @@ -3144,6 +3100,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05cff451f60db80f490f3c182b77c35260baace73209e9cdbbe526bfe3a4d402" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -3162,9 +3119,9 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" +checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" [[package]] name = "rustls-webpki" @@ -3198,15 +3155,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "schannel" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" -dependencies = [ - "windows-sys 0.52.0", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -3634,6 +3582,9 @@ name = "sync_wrapper" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] [[package]] name = "synstructure" @@ -3648,20 +3599,20 @@ dependencies = [ [[package]] name = "system-configuration" -version = "0.5.1" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.5.0", "core-foundation", "system-configuration-sys", ] [[package]] name = "system-configuration-sys" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" dependencies = [ "core-foundation-sys", "libc", @@ -3819,16 +3770,6 @@ dependencies = [ "syn 2.0.66", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -4141,12 +4082,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.4" @@ -4189,9 +4124,9 @@ dependencies = [ [[package]] name = "warg-api" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a22d3c9026f2f6a628cf386963844cdb7baea3b3419ba090c9096da114f977d" +checksum = "11e958a13d0e3e99acdada1b94d1f5af5380f0eb4699d880ce5a326d2103b0fa" dependencies = [ "indexmap 2.2.6", "itertools 0.12.1", @@ -4204,9 +4139,9 @@ dependencies = [ [[package]] name = "warg-client" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b8b5a2b17e737e1847dbf4642e4ebe49f5df32a574520251ff080ef0a120423" +checksum = "f3a26a25483e385ccdc388c9d51308a2352d9ae9d9b4a1153ad42464fdbea24a" dependencies = [ "anyhow", "async-recursion", @@ -4250,9 +4185,9 @@ dependencies = [ [[package]] name = "warg-crypto" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "834bf58863aa4bc3821732afb0c77e08a5cbf05f63ee93116acae694eab04460" +checksum = "dea87da2d18d20415ad051e6ad90ddbd4dc75180a0cc2a3835538c405ca332c7" dependencies = [ "anyhow", "base64 0.21.7", @@ -4271,9 +4206,9 @@ dependencies = [ [[package]] name = "warg-protobuf" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf8a2dee6b14f5b0b0c461711a81cdef45d45ea94f8460cb6205cada7fec732a" +checksum = "b048cf2d6a96a1642fcdb393e1072bda9323a8c11a8e11a1731c6bb81680b6d9" dependencies = [ "anyhow", "pbjson", @@ -4290,9 +4225,9 @@ dependencies = [ [[package]] name = "warg-protocol" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4053a3276d3fee83645411b1b5f462f72402e70fbf645164274a3a0a2fd72538" +checksum = "1ecc07de013b974e97af83afac2476117e6ee9e9b49bff75b261e961e66c6d0c" dependencies = [ "anyhow", "base64 0.21.7", @@ -4313,9 +4248,9 @@ dependencies = [ [[package]] name = "warg-server" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfffee4ffd0f4d20263fe6fd4705b9ee311f6b482ca354a42cf4e78d55b58c51" +checksum = "36f1905c04c8b77bcde6898936f25af2b13083296334c0192cb57b879f716059" dependencies = [ "anyhow", "axum", @@ -4344,9 +4279,9 @@ dependencies = [ [[package]] name = "warg-transparency" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "513ef81a5bb1ac5d7bd04f90d3c192dad8f590f4c02b3ef68d3ae4fbbb53c1d7" +checksum = "6d915717817f515a9dd723edbb9c0419d1d0c408d0f586719614a80ed3c7a6f8" dependencies = [ "anyhow", "indexmap 2.2.6", @@ -4476,20 +4411,31 @@ dependencies = [ [[package]] name = "wasm-encoder" -version = "0.209.1" +version = "0.210.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7e3764d9d6edabd8c9e16195e177be0d20f6ab942ad18af52860f12f82bc59a" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasm-encoder" +version = "0.215.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b4a05336882dae732ce6bd48b7e11fe597293cb72c13da4f35d7d5f8d53b2a7" +checksum = "4fb56df3e06b8e6b77e37d2969a50ba51281029a9aeb3855e76b7f49b6418847" dependencies = [ "leb128", + "wasmparser 0.215.0", ] [[package]] name = "wasm-encoder" -version = "0.210.0" +version = "0.216.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7e3764d9d6edabd8c9e16195e177be0d20f6ab942ad18af52860f12f82bc59a" +checksum = "04c23aebea22c8a75833ae08ed31ccc020835b12a41999e58c31464271b94a88" dependencies = [ "leb128", + "wasmparser 0.216.0", ] [[package]] @@ -4510,9 +4456,9 @@ dependencies = [ [[package]] name = "wasm-metadata" -version = "0.209.1" +version = "0.215.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d32029ce424f6d3c2b39b4419fb45a0e2d84fb0751e0c0a32b7ce8bd5d97f46" +checksum = "0c6bb07c5576b608f7a2a9baa2294c1a3584a249965d695a9814a496cb6d232f" dependencies = [ "anyhow", "indexmap 2.2.6", @@ -4520,14 +4466,30 @@ dependencies = [ "serde_derive", "serde_json", "spdx", - "wasm-encoder 0.209.1", - "wasmparser 0.209.1", + "wasm-encoder 0.215.0", + "wasmparser 0.215.0", +] + +[[package]] +name = "wasm-metadata" +version = "0.216.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47c8154d703a6b0e45acf6bd172fa002fc3c7058a9f7615e517220aeca27c638" +dependencies = [ + "anyhow", + "indexmap 2.2.6", + "serde 1.0.203", + "serde_derive", + "serde_json", + "spdx", + "wasm-encoder 0.216.0", + "wasmparser 0.216.0", ] [[package]] name = "wasm-pkg-client" version = "0.4.1" -source = "git+https://github.com/bytecodealliance/wasm-pkg-tools.git?rev=c48006aa1bcff1e69f4f8fc6689249b314985ab1#c48006aa1bcff1e69f4f8fc6689249b314985ab1" +source = "git+https://github.com/bytecodealliance/wasm-pkg-tools.git?rev=75d76192c30e718d5b76123720c79153083ed3e6#75d76192c30e718d5b76123720c79153083ed3e6" dependencies = [ "anyhow", "async-trait", @@ -4536,7 +4498,7 @@ dependencies = [ "dirs", "docker_credential", "futures-util", - "oci-distribution", + "oci-client", "oci-wasm", "secrecy", "serde 1.0.203", @@ -4550,14 +4512,16 @@ dependencies = [ "tracing-subscriber", "url", "warg-client", + "warg-crypto", "warg-protocol", "wasm-pkg-common", + "wit-component 0.216.0", ] [[package]] name = "wasm-pkg-common" version = "0.4.1" -source = "git+https://github.com/bytecodealliance/wasm-pkg-tools.git?rev=c48006aa1bcff1e69f4f8fc6689249b314985ab1#c48006aa1bcff1e69f4f8fc6689249b314985ab1" +source = "git+https://github.com/bytecodealliance/wasm-pkg-tools.git?rev=75d76192c30e718d5b76123720c79153083ed3e6#75d76192c30e718d5b76123720c79153083ed3e6" dependencies = [ "anyhow", "bytes", @@ -4615,9 +4579,22 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.209.1" +version = "0.215.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53fbde0881f24199b81cf49b6ff8f9c145ac8eb1b7fc439adb5c099734f7d90e" +dependencies = [ + "ahash", + "bitflags 2.5.0", + "hashbrown 0.14.5", + "indexmap 2.2.6", + "semver", +] + +[[package]] +name = "wasmparser" +version = "0.216.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07035cc9a9b41e62d3bb3a3815a66ab87c993c06fe1cf6b2a3f2a18499d937db" +checksum = "bcdee6bea3619d311fb4b299721e89a986c3470f804b6d534340e412589028e3" dependencies = [ "ahash", "bitflags 2.5.0", @@ -4678,6 +4655,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bd24728e5af82c6c4ec1b66ac4844bdf8156257fccda846ec58b42cd0cdbe6a" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "which" version = "6.0.1" @@ -4727,7 +4713,37 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.5", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", ] [[package]] @@ -4745,7 +4761,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -4765,18 +4781,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] [[package]] @@ -4787,9 +4803,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" @@ -4799,9 +4815,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" @@ -4811,15 +4827,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" @@ -4829,9 +4845,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" @@ -4841,9 +4857,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" @@ -4853,9 +4869,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" @@ -4865,9 +4881,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" @@ -4887,16 +4903,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "winreg" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a277a57398d4bfa075df44f501a17cfdf8542d224f0d36095a2adc7aee4ef0a5" -dependencies = [ - "cfg-if", - "windows-sys 0.48.0", -] - [[package]] name = "winsafe" version = "0.0.19" @@ -4984,9 +4990,28 @@ dependencies = [ [[package]] name = "wit-component" -version = "0.209.1" +version = "0.215.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f725e3885fc5890648be5c5cbc1353b755dc932aa5f1aa7de968b912a3280743" +dependencies = [ + "anyhow", + "bitflags 2.5.0", + "indexmap 2.2.6", + "log", + "serde 1.0.203", + "serde_derive", + "serde_json", + "wasm-encoder 0.215.0", + "wasm-metadata 0.215.0", + "wasmparser 0.215.0", + "wit-parser 0.215.0", +] + +[[package]] +name = "wit-component" +version = "0.216.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a2bb5b039f9cb03425e1d5a6e54b441ca4ca1b1d4fa6a0924db67a55168f99" +checksum = "7e2ca3ece38ea2447a9069b43074ba73d96dde1944cba276c54e41371745f9dc" dependencies = [ "anyhow", "bitflags 2.5.0", @@ -4995,10 +5020,10 @@ dependencies = [ "serde 1.0.203", "serde_derive", "serde_json", - "wasm-encoder 0.209.1", - "wasm-metadata 0.209.1", - "wasmparser 0.209.1", - "wit-parser 0.209.1", + "wasm-encoder 0.216.0", + "wasm-metadata 0.216.0", + "wasmparser 0.216.0", + "wit-parser 0.216.0", ] [[package]] @@ -5021,9 +5046,27 @@ dependencies = [ [[package]] name = "wit-parser" -version = "0.209.1" +version = "0.215.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "935a97eaffd57c3b413aa510f8f0b550a4a9fe7d59e79cd8b89a83dcb860321f" +dependencies = [ + "anyhow", + "id-arena", + "indexmap 2.2.6", + "log", + "semver", + "serde 1.0.203", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser 0.215.0", +] + +[[package]] +name = "wit-parser" +version = "0.216.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e79b9e3c0b6bb589dec46317e645851e0db2734c44e2be5e251b03ff4a51269" +checksum = "a4d108165c1167a4ccc8a803dcf5c28e0a51d6739fd228cc7adce768632c764c" dependencies = [ "anyhow", "id-arena", @@ -5034,7 +5077,7 @@ dependencies = [ "serde_derive", "serde_json", "unicode-xid", - "wasmparser 0.209.1", + "wasmparser 0.216.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 47457592..9b157348 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,9 +43,6 @@ tokio = { workspace = true } tokio-util = { workspace = true } toml_edit = { workspace = true } url = { workspace = true } -warg-client = { workspace = true } -warg-crypto = { workspace = true } -warg-protocol = { workspace = true } wasi-preview1-component-adapter-provider = { workspace = true } wasm-metadata = { workspace = true } wasm-pkg-client = { workspace = true } @@ -60,6 +57,9 @@ wit-parser = { workspace = true } assert_cmd = { workspace = true } predicates = { workspace = true } tempfile = { workspace = true } +warg-client = { workspace = true } +warg-crypto = { workspace = true } +warg-protocol = { workspace = true } warg-server = { workspace = true } wasmprinter = { workspace = true } wat = { workspace = true } @@ -101,13 +101,13 @@ tokio-util = "0.7.10" toml_edit = { version = "0.22.9", features = ["serde"] } unicode-width = "0.1.11" url = { version = "2.5.0", features = ["serde"] } -warg-client = "0.7.0" -warg-crypto = "0.7.0" -warg-protocol = "0.7.0" -warg-server = "0.7.0" +warg-client = "0.8" +warg-crypto = "0.8" +warg-protocol = "0.8" +warg-server = "0.8" wasi-preview1-component-adapter-provider = "23.0.1" wasm-metadata = "0.208.1" -wasm-pkg-client = { git = "https://github.com/bytecodealliance/wasm-pkg-tools.git", rev = "c48006aa1bcff1e69f4f8fc6689249b314985ab1" } +wasm-pkg-client = { git = "https://github.com/bytecodealliance/wasm-pkg-tools.git", rev = "75d76192c30e718d5b76123720c79153083ed3e6" } wasmparser = "0.208.1" wasmprinter = "0.208.1" wat = "1.208.1" diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index 7bc43a47..302ef994 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -25,9 +25,6 @@ tokio-util = { workspace = true, features = ["io"] } toml_edit = { workspace = true } unicode-width = { workspace = true } url = { workspace = true } -warg-client = { workspace = true } -warg-crypto = { workspace = true } -warg-protocol = { workspace = true } wasm-pkg-client = { workspace = true } wit-component = { workspace = true } wit-parser = { workspace = true } diff --git a/crates/core/src/registry.rs b/crates/core/src/registry.rs index 70b6c3d7..73b39c98 100644 --- a/crates/core/src/registry.rs +++ b/crates/core/src/registry.rs @@ -17,8 +17,6 @@ use serde::{ }; use tokio::io::AsyncReadExt; -use url::Url; -use warg_client::{Config as WargConfig, FileSystemClient, StorageLockResult}; use wasm_pkg_client::{ caching::{CachingClient, FileCache}, Client, Config, ContentDigest, Error as WasmPkgError, PackageRef, Release, VersionInfo, @@ -26,50 +24,11 @@ use wasm_pkg_client::{ use wit_component::DecodedWasm; use wit_parser::{PackageId, PackageName, Resolve, UnresolvedPackage, WorldId}; -use crate::{ - lock::{LockFileResolver, LockedPackageVersion}, - terminal::{Colors, Terminal}, -}; +use crate::lock::{LockFileResolver, LockedPackageVersion}; /// The name of the default registry. pub const DEFAULT_REGISTRY_NAME: &str = "default"; -/// Finds the URL for the given registry name. -pub fn find_url<'a>( - name: Option<&str>, - urls: &'a HashMap, - default: Option<&'a str>, -) -> Result<&'a str> { - let name = name.unwrap_or(DEFAULT_REGISTRY_NAME); - match urls.get(name) { - Some(url) => Ok(url.as_str()), - None if name != DEFAULT_REGISTRY_NAME => { - bail!("component registry `{name}` does not exist in the configuration") - } - None => default.context("a default component registry has not been set"), - } -} - -/// Creates a registry client with the given warg configuration. -pub async fn create_client( - config: &WargConfig, - url: &str, - terminal: &Terminal, -) -> Result { - match FileSystemClient::try_new_with_config(Some(url), config, None).await? { - StorageLockResult::Acquired(client) => Ok(client), - StorageLockResult::NotAcquired(path) => { - terminal.status_with_color( - "Blocking", - format!("waiting for file lock on `{path}`", path = path.display()), - Colors::Cyan, - )?; - - Ok(FileSystemClient::new_with_config(Some(url), config, None).await?) - } - } -} - /// Represents a WIT package dependency. #[derive(Debug, Clone)] pub enum Dependency { diff --git a/crates/wit/Cargo.toml b/crates/wit/Cargo.toml index da1b91bf..c5f0cd46 100644 --- a/crates/wit/Cargo.toml +++ b/crates/wit/Cargo.toml @@ -29,9 +29,6 @@ tokio = { workspace = true } toml_edit = { workspace = true } url = { workspace = true } wasm-pkg-client = { workspace = true } -warg-client = { workspace = true } -warg-crypto = { workspace = true } -warg-protocol = { workspace = true } wasm-metadata = { workspace = true } wit-component = { workspace = true } wit-parser = { workspace = true } @@ -39,6 +36,9 @@ wit-parser = { workspace = true } [dev-dependencies] assert_cmd = { workspace = true } predicates = { workspace = true } +warg-client = { workspace = true } +warg-crypto = { workspace = true } +warg-protocol = { workspace = true } warg-server = { workspace = true } tokio-util = { workspace = true } wasmparser = { workspace = true } diff --git a/crates/wit/README.md b/crates/wit/README.md index a60568bb..6b66c35b 100644 --- a/crates/wit/README.md +++ b/crates/wit/README.md @@ -118,13 +118,6 @@ To publish the WIT package to a registry, use the `publish` command: wit publish ``` -For new packages, the `--init` option must be used to initialize a new package -log for the package being published: - -``` -wit publish --init -``` - The command will publish the package to the default registry using the default signing key. diff --git a/crates/wit/src/commands/publish.rs b/crates/wit/src/commands/publish.rs index 58d2cd01..2b43f088 100644 --- a/crates/wit/src/commands/publish.rs +++ b/crates/wit/src/commands/publish.rs @@ -1,9 +1,7 @@ use anyhow::{Context, Result}; -use cargo_component_core::{cache_dir, command::CommonOptions, registry::find_url}; +use cargo_component_core::{cache_dir, command::CommonOptions}; use clap::Args; -use warg_crypto::signing::PrivateKey; -use warg_protocol::registry::PackageName; -use wasm_pkg_client::caching::FileCache; +use wasm_pkg_client::{caching::FileCache, PackageRef, Registry}; use crate::{ config::{Config, CONFIG_FILE_NAME}, @@ -22,17 +20,13 @@ pub struct PublishCommand { #[clap(long = "dry-run")] pub dry_run: bool, - /// Initialize a new package in the registry. - #[clap(long = "init")] - pub init: bool, - /// Use the specified registry name when publishing the package. #[clap(long = "registry", value_name = "REGISTRY")] - pub registry: Option, + pub registry: Option, /// Override the package name to publish. #[clap(long, value_name = "NAME")] - pub package: Option, + pub package: Option, } impl PublishCommand { @@ -44,7 +38,6 @@ impl PublishCommand { .with_context(|| format!("failed to find configuration file `{CONFIG_FILE_NAME}`"))?; let terminal = self.common.new_terminal(); - let warg_config = warg_client::Config::from_default_file()?.unwrap_or_default(); let pkg_config = if let Some(config_file) = self.common.config { wasm_pkg_client::Config::from_file(&config_file).context(format!( "failed to load configuration file from {}", @@ -55,31 +48,14 @@ impl PublishCommand { }; let file_cache = FileCache::new(cache_dir(self.common.cache_dir)?).await?; - let url = find_url( - self.registry.as_deref(), - &config.registries, - warg_config.home_url.as_deref(), - )?; - - let signing_key = if let Ok(key) = std::env::var("WIT_PUBLISH_KEY") { - Some(PrivateKey::decode(key).context( - "failed to parse signing key from `WIT_PUBLISH_KEY` environment variable", - )?) - } else { - None - }; - publish_wit_package( PublishOptions { config: &config, config_path: &config_path, - warg_config: &warg_config, pkg_config, cache: file_cache, - url, - signing_key, + url: self.registry.as_ref(), package: self.package.as_ref(), - init: self.init, dry_run: self.dry_run, }, &terminal, diff --git a/crates/wit/src/lib.rs b/crates/wit/src/lib.rs index e3f1eb9b..bbb4ac2d 100644 --- a/crates/wit/src/lib.rs +++ b/crates/wit/src/lib.rs @@ -2,22 +2,21 @@ #![deny(missing_docs)] +use std::{collections::HashSet, path::Path, sync::Arc}; + use anyhow::{bail, Context, Result}; -use bytes::Bytes; use cargo_component_core::{ lock::{LockFile, LockFileResolver, LockedPackage, LockedPackageVersion}, - registry::{create_client, DecodedDependency, DependencyResolutionMap, DependencyResolver}, + registry::{DecodedDependency, DependencyResolutionMap, DependencyResolver}, terminal::{Colors, Terminal}, }; use config::Config; use indexmap::{IndexMap, IndexSet}; use lock::{acquire_lock_file_ro, acquire_lock_file_rw, to_lock_file}; -use std::{collections::HashSet, path::Path, time::Duration}; -use warg_client::storage::{ContentStorage, PublishEntry, PublishInfo}; -use warg_crypto::signing::PrivateKey; -use warg_protocol::registry; use wasm_metadata::{Link, LinkType, RegistryMetadata}; -use wasm_pkg_client::caching::FileCache; +use wasm_pkg_client::{ + caching::FileCache, warg::WargRegistryConfig, Client, PackageRef, PublishOpts, Registry, +}; use wit_component::DecodedWasm; use wit_parser::{PackageId, PackageName, Resolve, UnresolvedPackage}; @@ -225,7 +224,7 @@ async fn build_wit_package( pkg_config: wasm_pkg_client::Config, terminal: &Terminal, file_cache: FileCache, -) -> Result<(registry::PackageName, Vec)> { +) -> Result<(PackageRef, Vec)> { let dependencies = resolve_dependencies(config, config_path, pkg_config, terminal, true, file_cache).await?; @@ -255,12 +254,9 @@ async fn build_wit_package( struct PublishOptions<'a> { config: &'a Config, config_path: &'a Path, - warg_config: &'a warg_client::Config, pkg_config: wasm_pkg_client::Config, - url: &'a str, - signing_key: Option, - package: Option<&'a registry::PackageName>, - init: bool, + url: Option<&'a Registry>, + package: Option<&'a PackageRef>, dry_run: bool, cache: FileCache, } @@ -315,11 +311,11 @@ fn add_registry_metadata(config: &Config, bytes: &[u8]) -> Result> { .context("failed to add registry metadata to component") } -async fn publish_wit_package(options: PublishOptions<'_>, terminal: &Terminal) -> Result<()> { +async fn publish_wit_package(mut options: PublishOptions<'_>, terminal: &Terminal) -> Result<()> { let (name, bytes) = build_wit_package( options.config, options.config_path, - options.pkg_config, + options.pkg_config.clone(), terminal, options.cache, ) @@ -332,53 +328,40 @@ async fn publish_wit_package(options: PublishOptions<'_>, terminal: &Terminal) - let bytes = add_registry_metadata(options.config, &bytes)?; let name = options.package.unwrap_or(&name); - let client = create_client(options.warg_config, options.url, terminal).await?; - - let content = client - .content() - .store_content( - Box::pin(futures::stream::once(async { Ok(Bytes::from(bytes)) })), - None, - ) - .await?; - - terminal.status("Publishing", format!("package `{name}` ({content})"))?; - - let mut info = PublishInfo { - name: name.clone(), - head: None, - entries: Default::default(), - }; - if options.init { - info.entries.push(PublishEntry::Init); + if let Ok(key) = std::env::var("WIT_PUBLISH_KEY") { + let registry = options.pkg_config.resolve_registry(name).ok_or_else(|| anyhow::anyhow!("Tried to set a signing key, but registry was not set and no default registry was found. Try setting the `--registry` option."))?.to_owned(); + // NOTE(thomastaylor312): If config doesn't already exist, this will essentially force warg + // usage because we'll be creating a config for warg, which means it will default to that + // protocol. So for all intents and purposes, setting a publish key forces warg usage. + let reg_config = options + .pkg_config + .get_or_insert_registry_config_mut(®istry); + let mut warg_conf = WargRegistryConfig::try_from(&*reg_config).unwrap_or_default(); + warg_conf.signing_key = Some(Arc::new( + key.try_into().context("Failed to parse signing key")?, + )); + reg_config.set_backend_config("warg", warg_conf)?; } - info.entries.push(PublishEntry::Release { - version: options.config.version.clone(), - content, - }); + terminal.status("Publishing", format!("package `{name}`"))?; - let record_id = if let Some(signing_key) = &options.signing_key { - client.publish_with_info(signing_key, info).await? - } else { - client.sign_with_keyring_and_publish(Some(info)).await? - }; - client - .wait_for_publish(name, &record_id, Duration::from_secs(1)) + let client = Client::new(options.pkg_config); + + let (name, version) = client + .publish_release_data( + Box::pin(std::io::Cursor::new(bytes)), + PublishOpts { + package: Some((name.to_owned(), options.config.version.to_owned())), + registry: options.url.cloned(), + }, + ) .await?; - terminal.status( - "Published", - format!( - "package `{name}` v{version}", - version = options.config.version - ), - )?; + terminal.status("Published", format!("package `{name}` v{version}",))?; Ok(()) } - /// Update the dependencies in the lock file. pub async fn update_lockfile( config: &Config, diff --git a/crates/wit/tests/add.rs b/crates/wit/tests/add.rs index c040f95d..6daa1813 100644 --- a/crates/wit/tests/add.rs +++ b/crates/wit/tests/add.rs @@ -61,7 +61,7 @@ async fn validate_the_version_exists() -> Result<()> { let project = server.project("foo", Vec::::new())?; project.file("foo.wit", "package test:bar;\n")?; project - .wit(["publish", "--init"]) + .wit(["publish"]) .env("WIT_PUBLISH_KEY", test_signing_key()) .assert() .stderr(contains("Published package `test:bar` v0.1.0")) @@ -95,7 +95,7 @@ async fn checks_for_duplicate_dependencies() -> Result<()> { let project = server.project("foo", Vec::::new())?; project.file("foo.wit", "package test:bar;\n")?; project - .wit(["publish", "--init"]) + .wit(["publish"]) .env("WIT_PUBLISH_KEY", test_signing_key()) .assert() .stderr(contains("Published package `test:bar` v0.1.0")) @@ -129,7 +129,7 @@ async fn does_not_modify_manifest_for_dry_run() -> Result<()> { let project = server.project("foo", Vec::::new())?; project.file("foo.wit", "package test:bar;\n")?; project - .wit(["publish", "--init"]) + .wit(["publish"]) .env("WIT_PUBLISH_KEY", test_signing_key()) .assert() .stderr(contains("Published package `test:bar` v0.1.0")) diff --git a/crates/wit/tests/publish.rs b/crates/wit/tests/publish.rs index 83203385..7b3400e4 100644 --- a/crates/wit/tests/publish.rs +++ b/crates/wit/tests/publish.rs @@ -1,14 +1,10 @@ -use std::fs; - use anyhow::{Context, Result}; use assert_cmd::prelude::*; +use futures::TryStreamExt; use predicates::str::contains; -use semver::Version; use toml_edit::{value, Array}; -use warg_client::{Client, FileSystemClient}; -use warg_protocol::registry::PackageName; use wasm_metadata::LinkType; -use wasm_pkg_client::warg::WargRegistryConfig; +use wasm_pkg_client::{Client, Error}; use crate::support::*; @@ -42,7 +38,7 @@ async fn it_publishes_a_wit_package() -> Result<()> { let project = server.project("foo", Vec::::new())?; project.file("baz.wit", "package test:qux;\n")?; project - .wit(["publish", "--init"]) + .wit(["publish"]) .env("WIT_PUBLISH_KEY", test_signing_key()) .assert() .stderr(contains("Published package `test:qux` v0.1.0")) @@ -53,14 +49,12 @@ async fn it_publishes_a_wit_package() -> Result<()> { #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn it_does_a_dry_run_publish() -> Result<()> { - let (server, config, registry) = spawn_server(Vec::::new()).await?; - let warg_config = - WargRegistryConfig::try_from(config.registry_config(®istry).unwrap()).unwrap(); + let (server, config, _) = spawn_server(Vec::::new()).await?; let project = server.project("foo", Vec::::new())?; project.file("baz.wit", "package test:qux;\n")?; project - .wit(["publish", "--init", "--dry-run"]) + .wit(["publish", "--dry-run"]) .env("WIT_PUBLISH_KEY", test_signing_key()) .assert() .stderr(contains( @@ -68,23 +62,23 @@ async fn it_does_a_dry_run_publish() -> Result<()> { )) .success(); - let client = FileSystemClient::new_with_config(None, &warg_config.client_config, None).await?; + let client = Client::new(config); - assert!(client - .download(&"test:qux".parse().unwrap(), &"0.1.0".parse().unwrap()) + let err = client + .get_release(&"test:qux".parse().unwrap(), &"0.1.0".parse().unwrap()) .await - .unwrap_err() - .to_string() - .contains("package `test:qux` does not exist")); + .expect_err("Should not be able to get release after dry run"); + assert!( + matches!(err, Error::PackageNotFound), + "Expected PackageNotFound" + ); Ok(()) } #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn it_publishes_with_registry_metadata() -> Result<()> { - let (server, config, registry) = spawn_server(Vec::::new()).await?; - let warg_config = - WargRegistryConfig::try_from(config.registry_config(®istry).unwrap()).unwrap(); + let (server, config, _) = spawn_server(Vec::::new()).await?; let project = server.project("foo", Vec::::new())?; @@ -110,31 +104,23 @@ async fn it_publishes_with_registry_metadata() -> Result<()> { })?; project - .wit(["publish", "--init"]) + .wit(["publish"]) .env("WIT_PUBLISH_KEY", test_signing_key()) .assert() .stderr(contains("Published package `test:qux` v0.1.0")) .success(); - let client = Client::new_with_config(None, &warg_config.client_config, None).await?; - let download = client - .download_exact(&PackageName::new("test:qux")?, &Version::parse("0.1.0")?) + let client = Client::new(config); + let package_ref = "test:qux".parse().unwrap(); + let release = client + .get_release(&package_ref, &"0.1.0".parse().unwrap()) .await?; + let stream = client.stream_content(&package_ref, &release).await?; - let bytes = fs::read(&download.path).with_context(|| { - format!( - "failed to read downloaded package `{path}`", - path = download.path.display() - ) - })?; + let bytes = stream.map_ok(Vec::from).try_concat().await?; let metadata = wasm_metadata::RegistryMetadata::from_wasm(&bytes) - .with_context(|| { - format!( - "failed to parse registry metadata from `{path}`", - path = download.path.display() - ) - })? + .context("failed to parse registry metadata from bytes")? .expect("missing registry metadata"); assert_eq!( diff --git a/crates/wit/tests/support/mod.rs b/crates/wit/tests/support/mod.rs index 62dad4d5..de875177 100644 --- a/crates/wit/tests/support/mod.rs +++ b/crates/wit/tests/support/mod.rs @@ -1,9 +1,5 @@ #![allow(dead_code)] -use anyhow::{bail, Context, Result}; -use assert_cmd::prelude::OutputAssertExt; -use cargo_component_core::command::{CACHE_DIR_ENV_VAR, CONFIG_FILE_ENV_VAR}; -use indexmap::IndexSet; use std::{ env, ffi::OsStr, @@ -11,8 +7,14 @@ use std::{ path::{Path, PathBuf}, process::Command, rc::Rc, + sync::Arc, time::Duration, }; + +use anyhow::{bail, Context, Result}; +use assert_cmd::prelude::OutputAssertExt; +use cargo_component_core::command::{CACHE_DIR_ENV_VAR, CONFIG_FILE_ENV_VAR}; +use indexmap::IndexSet; use tempfile::TempDir; use tokio::task::JoinHandle; use tokio_util::sync::CancellationToken; @@ -178,6 +180,7 @@ where wasm_pkg_client::warg::WargRegistryConfig { client_config: warg_config, auth_token: None, + signing_key: Some(Arc::new(test_signing_key().to_string().try_into()?)), config_file: Some(config_file), }, ) diff --git a/crates/wit/tests/update.rs b/crates/wit/tests/update.rs index f415d654..1e2f51bf 100644 --- a/crates/wit/tests/update.rs +++ b/crates/wit/tests/update.rs @@ -36,7 +36,7 @@ async fn update_without_changes_is_a_noop() -> Result<()> { let project = server.project("bar", Vec::::new())?; project.file("bar.wit", "package test:bar;\n")?; project - .wit(["publish", "--init"]) + .wit(["publish"]) .env("WIT_PUBLISH_KEY", test_signing_key()) .assert() .stderr(contains("Published package `test:bar` v0.1.0")) @@ -73,7 +73,7 @@ async fn test_update_without_compatible_changes_is_a_noop() -> Result<()> { project1.file("bar.wit", "package test:bar;\n")?; project1 - .wit(["publish", "--init"]) + .wit(["publish"]) .env("WIT_PUBLISH_KEY", test_signing_key()) .assert() .stderr(contains("Published package `test:bar` v0.1.0")) @@ -126,7 +126,7 @@ async fn update_with_compatible_changes() -> Result<()> { )?; project1 - .wit(["publish", "--init"]) + .wit(["publish"]) .env("WIT_PUBLISH_KEY", test_signing_key()) .assert() .stderr(contains("Published package `test:bar` v1.0.0")) @@ -182,7 +182,7 @@ async fn update_with_compatible_changes_is_noop_for_dryrun() -> Result<()> { )?; project1 - .wit(["publish", "--init"]) + .wit(["publish"]) .env("WIT_PUBLISH_KEY", test_signing_key()) .assert() .stderr(contains("Published package `test:bar` v1.0.0")) @@ -242,7 +242,7 @@ async fn update_with_changed_dependencies() -> Result<()> { )?; project - .wit(["publish", "--init"]) + .wit(["publish"]) .env("WIT_PUBLISH_KEY", test_signing_key()) .assert() .stderr(contains("Published package `test:bar` v1.0.0")) @@ -256,7 +256,7 @@ async fn update_with_changed_dependencies() -> Result<()> { )?; project - .wit(["publish", "--init"]) + .wit(["publish"]) .env("WIT_PUBLISH_KEY", test_signing_key()) .assert() .stderr(contains("Published package `test:baz` v1.0.0")) diff --git a/src/commands/publish.rs b/src/commands/publish.rs index 6f97cd58..0981b135 100644 --- a/src/commands/publish.rs +++ b/src/commands/publish.rs @@ -1,10 +1,9 @@ -use std::path::PathBuf; +use std::{path::PathBuf, sync::Arc}; use anyhow::{bail, Context, Result}; -use cargo_component_core::{command::CommonOptions, registry::find_url}; +use cargo_component_core::command::CommonOptions; use clap::Args; -use warg_crypto::signing::PrivateKey; -use warg_protocol::registry::PackageName; +use wasm_pkg_client::{warg::WargRegistryConfig, Registry}; use crate::{ config::{CargoArguments, CargoPackageSpec, Config}, @@ -70,11 +69,7 @@ pub struct PublishCommand { /// The registry to publish to. #[clap(long = "registry", value_name = "REGISTRY")] - pub registry: Option, - - /// Initialize a new package in the registry. - #[clap(long = "init")] - pub init: bool, + pub registry: Option, } impl PublishCommand { @@ -82,7 +77,7 @@ impl PublishCommand { pub async fn exec(self) -> Result<()> { log::debug!("executing publish command"); - let config = Config::new(self.common.new_terminal(), self.common.config.clone())?; + let mut config = Config::new(self.common.new_terminal(), self.common.config.clone())?; let client = config.client(self.common.cache_dir.clone(), false).await?; if let Some(target) = &self.target { @@ -127,17 +122,20 @@ impl PublishCommand { ) })?; - let registry_url = find_url( - self.registry.as_deref(), - &component_metadata.section.registries, - config.warg().home_url.as_deref(), - )?; - - let signing_key = if let Ok(key) = std::env::var("CARGO_COMPONENT_PUBLISH_KEY") { - Some(PrivateKey::decode(key).context("failed to parse signing key from `CARGO_COMPONENT_PUBLISH_KEY` environment variable")?) - } else { - None - }; + if let Ok(key) = std::env::var("CARGO_COMPONENT_PUBLISH_KEY") { + let registry = config.pkg_config.resolve_registry(name).ok_or_else(|| anyhow::anyhow!("Tried to set a signing key, but registry was not set and no default registry was found. Try setting the `--registry` option."))?.to_owned(); + // NOTE(thomastaylor312): If config doesn't already exist, this will essentially force warg + // usage because we'll be creating a config for warg, which means it will default to that + // protocol. So for all intents and purposes, setting a publish key forces warg usage. + let reg_config = config + .pkg_config + .get_or_insert_registry_config_mut(®istry); + let mut warg_conf = WargRegistryConfig::try_from(&*reg_config).unwrap_or_default(); + warg_conf.signing_key = Some(Arc::new( + key.try_into().context("Failed to parse signing key")?, + )); + reg_config.set_backend_config("warg", warg_conf)?; + } let cargo_build_args = CargoArguments { color: self.common.color, @@ -157,7 +155,7 @@ impl PublishCommand { let spawn_args = self.build_args()?; let outputs = run_cargo_command( - client, + client.clone(), &config, &metadata, &packages, @@ -172,20 +170,17 @@ impl PublishCommand { len = outputs.len() ); } - // Safe to unwrap here because we already know a PackageRef is valid - let package_name = PackageName::new(name.to_string()).unwrap(); + let options = PublishOptions { package, - registry_url, - init: self.init, - name: &package_name, + name, + registry_url: self.registry.as_ref(), version: &component_metadata.version, path: &outputs[0], - signing_key, dry_run: self.dry_run, }; - publish(&config, &options).await + publish(&config, client, &options).await } fn build_args(&self) -> Result> { diff --git a/src/config.rs b/src/config.rs index 7da45950..26a6134d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -491,8 +491,6 @@ impl CargoArguments { /// This is used to configure the behavior of cargo-component. #[derive(Debug)] pub struct Config { - /// The warg client configuration. - pub warg: warg_client::Config, /// The package configuration to use pub pkg_config: wasm_pkg_client::Config, /// The terminal to use. @@ -507,17 +505,11 @@ impl Config { None => wasm_pkg_client::Config::global_defaults()?, }; Ok(Self { - warg: warg_client::Config::from_default_file()?.unwrap_or_default(), pkg_config, terminal, }) } - /// Gets the warg client configuration. - pub fn warg(&self) -> &warg_client::Config { - &self.warg - } - /// Gets the package configuration. pub fn pkg_config(&self) -> &wasm_pkg_client::Config { &self.pkg_config diff --git a/src/lib.rs b/src/lib.rs index 5035cfb1..24cdf80d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,15 +12,13 @@ use std::{ path::{Path, PathBuf}, process::{Command, Stdio}, sync::Arc, - time::{Duration, SystemTime}, + time::SystemTime, }; use anyhow::{bail, Context, Result}; use bindings::BindingsGenerator; -use bytes::Bytes; use cargo_component_core::{ lock::{LockFile, LockFileResolver, LockedPackage, LockedPackageVersion}, - registry::create_client, terminal::Colors, }; use cargo_config2::{PathAndArgs, TargetTripleRef}; @@ -28,11 +26,11 @@ use cargo_metadata::{Artifact, Message, Metadata, MetadataCommand, Package}; use semver::Version; use shell_escape::escape; use tempfile::NamedTempFile; -use warg_client::storage::{ContentStorage, PublishEntry, PublishInfo}; -use warg_crypto::signing::PrivateKey; -use warg_protocol::registry::PackageName; use wasm_metadata::{Link, LinkType, RegistryMetadata}; -use wasm_pkg_client::caching::{CachingClient, FileCache}; +use wasm_pkg_client::{ + caching::{CachingClient, FileCache}, + PackageRef, PublishOpts, Registry, +}; use wasmparser::{Parser, Payload}; use wit_component::ComponentEncoder; @@ -1013,17 +1011,13 @@ pub struct PublishOptions<'a> { /// The package to publish. pub package: &'a Package, /// The registry URL to publish to. - pub registry_url: &'a str, - /// Whether to initialize the package or not. - pub init: bool, + pub registry_url: Option<&'a Registry>, /// The name of the package being published. - pub name: &'a PackageName, + pub name: &'a PackageRef, /// The version of the package being published. pub version: &'a Version, /// The path to the package being published. pub path: &'a Path, - /// The signing key to use for the publish operation. - pub signing_key: Option, /// Whether to perform a dry run or not. pub dry_run: bool, } @@ -1082,7 +1076,11 @@ fn add_registry_metadata(package: &Package, bytes: &[u8], path: &Path) -> Result } /// Publish a component for the given workspace and publish options. -pub async fn publish(config: &Config, options: &PublishOptions<'_>) -> Result<()> { +pub async fn publish( + config: &Config, + client: Arc>, + options: &PublishOptions<'_>, +) -> Result<()> { if options.dry_run { config .terminal() @@ -1090,8 +1088,6 @@ pub async fn publish(config: &Config, options: &PublishOptions<'_>) -> Result<() return Ok(()); } - let client = create_client(config.warg(), options.registry_url, config.terminal()).await?; - let bytes = fs::read(options.path).with_context(|| { format!( "failed to read component `{path}`", @@ -1101,54 +1097,25 @@ pub async fn publish(config: &Config, options: &PublishOptions<'_>) -> Result<() let bytes = add_registry_metadata(options.package, &bytes, options.path)?; - let content = client - .content() - .store_content( - Box::pin(futures::stream::once(async { Ok(Bytes::from(bytes)) })), - None, - ) - .await?; - config.terminal().status( "Publishing", - format!( - "component {path} ({content})", - path = options.path.display() - ), + format!("component {path}", path = options.path.display()), )?; - let mut info = PublishInfo { - name: options.name.clone(), - head: None, - entries: Default::default(), - }; - - if options.init { - info.entries.push(PublishEntry::Init); - } - - info.entries.push(PublishEntry::Release { - version: options.version.clone(), - content, - }); - - let record_id = if let Some(signing_key) = &options.signing_key { - client.publish_with_info(signing_key, info).await? - } else { - client.sign_with_keyring_and_publish(Some(info)).await? - }; - client - .wait_for_publish(options.name, &record_id, Duration::from_secs(1)) + let (name, version) = client + .client()? + .publish_release_data( + Box::pin(std::io::Cursor::new(bytes)), + PublishOpts { + package: Some((options.name.to_owned(), options.version.to_owned())), + registry: options.registry_url.cloned(), + }, + ) .await?; - config.terminal().status( - "Published", - format!( - "package `{name}` v{version}", - name = options.name, - version = options.version - ), - )?; + config + .terminal() + .status("Published", format!("package `{name}` v{version}"))?; Ok(()) } diff --git a/tests/add.rs b/tests/add.rs index 12d917e9..cde27fde 100644 --- a/tests/add.rs +++ b/tests/add.rs @@ -5,7 +5,6 @@ use assert_cmd::prelude::*; use predicates::{prelude::*, str::contains}; use tempfile::TempDir; use toml_edit::value; -use wasm_pkg_client::warg::WargRegistryConfig; use crate::support::*; @@ -46,20 +45,9 @@ async fn validate_the_package_exists() -> Result<()> { #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn validate_the_version_exists() -> Result<()> { - let (server, config, registry) = spawn_server(Vec::::new()).await?; - - // NOTE(thomastaylor312): Once we have publishing in wasm_pkg_client, we won't need to get the config directly like this - let warg_config = - WargRegistryConfig::try_from(config.registry_config(®istry).unwrap()).unwrap(); - - publish_component( - &warg_config.client_config, - "test:bar", - "1.1.0", - "(component)", - true, - ) - .await?; + let (server, config, _) = spawn_server(Vec::::new()).await?; + + publish_component(config, "test:bar", "1.1.0", "(component)").await?; let project = server.project("foo", true, Vec::::new())?; @@ -85,19 +73,9 @@ async fn validate_the_version_exists() -> Result<()> { #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn adds_dependencies_to_target_component() -> Result<()> { - let (server, config, registry) = spawn_server(Vec::::new()).await?; - - let warg_config = - WargRegistryConfig::try_from(config.registry_config(®istry).unwrap()).unwrap(); + let (server, config, _) = spawn_server(Vec::::new()).await?; - publish_component( - &warg_config.client_config, - "test:bar", - "1.1.0", - "(component)", - true, - ) - .await?; + publish_component(config, "test:bar", "1.1.0", "(component)").await?; let project = server.project("foo_target", true, Vec::::new())?; @@ -144,19 +122,9 @@ fn checks_for_duplicate_dependencies() -> Result<()> { #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn prints_modified_manifest_for_dry_run() -> Result<()> { - let (server, config, registry) = spawn_server(Vec::::new()).await?; - - let warg_config = - WargRegistryConfig::try_from(config.registry_config(®istry).unwrap()).unwrap(); + let (server, config, _) = spawn_server(Vec::::new()).await?; - publish_component( - &warg_config.client_config, - "test:bar", - "1.2.3", - "(component)", - true, - ) - .await?; + publish_component(config, "test:bar", "1.2.3", "(component)").await?; let project = server.project("foo", true, Vec::::new())?; diff --git a/tests/new.rs b/tests/new.rs index 95edfddb..7017aeae 100644 --- a/tests/new.rs +++ b/tests/new.rs @@ -4,7 +4,6 @@ use anyhow::Result; use assert_cmd::prelude::*; use predicates::{str::contains, Predicate}; use tempfile::TempDir; -use wasm_pkg_client::warg::WargRegistryConfig; use crate::support::*; @@ -135,13 +134,10 @@ fn it_rejects_rust_keywords() -> Result<()> { #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn it_targets_a_world() -> Result<()> { - let (server, config, registry) = spawn_server(Vec::::new()).await?; - - let warg_config = - WargRegistryConfig::try_from(config.registry_config(®istry).unwrap()).unwrap(); + let (server, config, _) = spawn_server(Vec::::new()).await?; publish_wit( - &warg_config.client_config, + config, "test:bar", "1.2.3", r#"package test:bar@1.2.3; @@ -241,7 +237,6 @@ world foo { export another-func: func(yet: borrow) -> result; export another-func-empty: func(empty: borrow) -> result; }"#, - true, ) .await?; diff --git a/tests/publish.rs b/tests/publish.rs index 4ddd875b..0c5b5566 100644 --- a/tests/publish.rs +++ b/tests/publish.rs @@ -2,13 +2,11 @@ use std::fs; use anyhow::{Context, Result}; use assert_cmd::prelude::*; +use futures::stream::TryStreamExt; use predicates::str::contains; -use semver::Version; use toml_edit::{value, Array}; -use warg_client::Client; -use warg_protocol::registry::PackageName; use wasm_metadata::LinkType; -use wasm_pkg_client::warg::WargRegistryConfig; +use wasm_pkg_client::Client; use crate::support::*; @@ -26,13 +24,10 @@ fn help() { #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn it_publishes_a_component() -> Result<()> { - let (server, config, registry) = spawn_server(Vec::::new()).await?; - - let warg_config = - WargRegistryConfig::try_from(config.registry_config(®istry).unwrap()).unwrap(); + let (server, config, _) = spawn_server(Vec::::new()).await?; publish_wit( - &warg_config.client_config, + config, "test:world", "1.0.0", r#"package test:%world@1.0.0; @@ -40,7 +35,6 @@ world foo { import foo: func() -> string; export bar: func() -> string; }"#, - true, ) .await?; @@ -55,7 +49,7 @@ world foo { assert!(source.contains("use bindings::Guest;")); project - .cargo_component(["publish", "--init"]) + .cargo_component(["publish"]) .env("CARGO_COMPONENT_PUBLISH_KEY", test_signing_key()) .assert() .stderr(contains("Published package `test:foo` v0.1.0")) @@ -72,59 +66,18 @@ world foo { Ok(()) } -#[tokio::test(flavor = "multi_thread", worker_threads = 1)] -async fn it_fails_if_package_does_not_exist() -> Result<()> { - let (server, config, registry) = spawn_server(Vec::::new()).await?; - - let warg_config = - WargRegistryConfig::try_from(config.registry_config(®istry).unwrap()).unwrap(); - - publish_wit( - &warg_config.client_config, - "test:world", - "1.0.0", - r#"package test:%world@1.0.0; -world foo { - import foo: func() -> string; - export bar: func() -> string; -}"#, - true, - ) - .await?; - - let project = server.project( - "foo", - true, - ["--namespace", "test", "--target", "test:world"], - )?; - project - .cargo_component(["publish"]) - .env("CARGO_COMPONENT_PUBLISH_KEY", test_signing_key()) - .assert() - .stderr(contains( - "package `test:foo` must be initialized before publishing", - )) - .failure(); - - Ok(()) -} - #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn it_publishes_a_dependency() -> Result<()> { - let (server, config, registry) = spawn_server(Vec::::new()).await?; - - let warg_config = - WargRegistryConfig::try_from(config.registry_config(®istry).unwrap()).unwrap(); + let (server, config, _) = spawn_server(Vec::::new()).await?; publish_wit( - &warg_config.client_config, + config, "test:world", "1.0.0", r#"package test:%world@1.0.0; world foo { export bar: func() -> string; }"#, - true, ) .await?; @@ -135,7 +88,7 @@ world foo { )?; project - .cargo_component(["publish", "--init"]) + .cargo_component(["publish"]) .env("CARGO_COMPONENT_PUBLISH_KEY", test_signing_key()) .assert() .stderr(contains("Published package `test:foo` v0.1.0")) @@ -171,7 +124,7 @@ bindings::export!(Component with_types_in bindings); fs::write(project.root().join("src/lib.rs"), source)?; project - .cargo_component(["publish", "--init"]) + .cargo_component(["publish"]) .env("CARGO_COMPONENT_PUBLISH_KEY", test_signing_key()) .assert() .stderr(contains("Published package `test:bar` v0.1.0")) @@ -184,10 +137,7 @@ bindings::export!(Component with_types_in bindings); #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn it_publishes_with_registry_metadata() -> Result<()> { - let (server, config, registry) = spawn_server(Vec::::new()).await?; - - let warg_config = - WargRegistryConfig::try_from(config.registry_config(®istry).unwrap()).unwrap(); + let (server, config, _) = spawn_server(Vec::::new()).await?; let authors = ["Jane Doe "]; let categories = ["wasm"]; @@ -211,7 +161,7 @@ async fn it_publishes_with_registry_metadata() -> Result<()> { })?; project - .cargo_component(["publish", "--init"]) + .cargo_component(["publish"]) .env("CARGO_COMPONENT_PUBLISH_KEY", test_signing_key()) .assert() .stderr(contains("Published package `test:foo` v0.1.0")) @@ -219,25 +169,17 @@ async fn it_publishes_with_registry_metadata() -> Result<()> { validate_component(&project.release_wasm("foo"))?; - let client = Client::new_with_config(None, &warg_config.client_config, None).await?; - let download = client - .download_exact(&PackageName::new("test:foo")?, &Version::parse("0.1.0")?) + let client = Client::new(config); + let package_ref = "test:foo".parse().unwrap(); + let release = client + .get_release(&package_ref, &"0.1.0".parse().unwrap()) .await?; + let stream = client.stream_content(&package_ref, &release).await?; - let bytes = fs::read(&download.path).with_context(|| { - format!( - "failed to read downloaded package `{path}`", - path = download.path.display() - ) - })?; + let bytes = stream.map_ok(Vec::from).try_concat().await?; let metadata = wasm_metadata::RegistryMetadata::from_wasm(&bytes) - .with_context(|| { - format!( - "failed to parse registry metadata from `{path}`", - path = download.path.display() - ) - })? + .context("failed to parse registry metadata from data")? .expect("missing registry metadata"); assert_eq!( diff --git a/tests/support/mod.rs b/tests/support/mod.rs index f645e4af..e5d11098 100644 --- a/tests/support/mod.rs +++ b/tests/support/mod.rs @@ -5,6 +5,7 @@ use std::{ path::{Path, PathBuf}, process::Command, rc::Rc, + sync::Arc, time::Duration, }; @@ -16,14 +17,10 @@ use tempfile::TempDir; use tokio::task::JoinHandle; use tokio_util::sync::CancellationToken; use toml_edit::DocumentMut; -use warg_client::{ - storage::{ContentStorage, PublishEntry, PublishInfo}, - FileSystemClient, -}; use warg_crypto::signing::PrivateKey; -use warg_protocol::{operator::NamespaceState, registry::PackageName}; +use warg_protocol::operator::NamespaceState; use warg_server::{policy::content::WasmContentPolicy, Config, Server}; -use wasm_pkg_client::Registry; +use wasm_pkg_client::{Client, PackageRef, PublishOpts, Registry}; use wasmparser::{Chunk, Encoding, Parser, Payload, Validator}; use wit_parser::{Resolve, UnresolvedPackage}; @@ -57,74 +54,46 @@ where } pub async fn publish( - config: &warg_client::Config, - name: &PackageName, + config: wasm_pkg_client::Config, + name: &PackageRef, version: &str, content: Vec, - init: bool, ) -> Result<()> { - let client = FileSystemClient::new_with_config(None, config, None).await?; - - let digest = client - .content() - .store_content( - Box::pin(futures::stream::once(async move { Ok(content.into()) })), - None, - ) - .await - .context("failed to store component for publishing")?; + let client = Client::new(config); - let mut entries = Vec::with_capacity(2); - if init { - entries.push(PublishEntry::Init); - } - entries.push(PublishEntry::Release { - version: version.parse().unwrap(), - content: digest, - }); - - let record_id = client - .publish_with_info( - &PrivateKey::decode(test_signing_key().to_string()).unwrap(), - PublishInfo { - name: name.clone(), - head: None, - entries, + client + .publish_release_data( + Box::pin(std::io::Cursor::new(content)), + PublishOpts { + package: Some((name.to_owned(), version.parse().unwrap())), + ..Default::default() }, ) - .await - .context("failed to publish component")?; - - client - .wait_for_publish(name, &record_id, Duration::from_secs(1)) .await?; Ok(()) } pub async fn publish_component( - config: &warg_client::Config, + config: wasm_pkg_client::Config, id: &str, version: &str, wat: &str, - init: bool, ) -> Result<()> { publish( config, &id.parse()?, version, wat::parse_str(wat).context("failed to parse component for publishing")?, - init, ) .await } pub async fn publish_wit( - config: &warg_client::Config, + config: wasm_pkg_client::Config, id: &str, version: &str, wit: &str, - init: bool, ) -> Result<()> { let mut resolve = Resolve::new(); let pkg = resolve @@ -137,7 +106,7 @@ pub async fn publish_wit( let bytes = wit_component::encode(Some(true), &resolve, pkg) .context("failed to encode wit for publishing")?; - publish(config, &id.parse()?, version, bytes, init).await + publish(config, &id.parse()?, version, bytes).await } pub struct ServerInstance { @@ -237,6 +206,7 @@ where wasm_pkg_client::warg::WargRegistryConfig { client_config: warg_config, auth_token: None, + signing_key: Some(Arc::new(test_signing_key().to_string().try_into()?)), config_file: Some(config_file), }, ) diff --git a/tests/update.rs b/tests/update.rs index e439009c..4023b7e0 100644 --- a/tests/update.rs +++ b/tests/update.rs @@ -4,7 +4,6 @@ use anyhow::{Context, Result}; use assert_cmd::prelude::*; use predicates::{prelude::PredicateBooleanExt, str::contains}; use toml_edit::value; -use wasm_pkg_client::warg::WargRegistryConfig; use crate::support::*; @@ -24,13 +23,10 @@ fn help() { #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn update_without_changes_is_a_noop() -> Result<()> { - let (server, config, registry) = spawn_server(Vec::::new()).await?; - - let warg_config = - WargRegistryConfig::try_from(config.registry_config(®istry).unwrap()).unwrap(); + let (server, config, _) = spawn_server(Vec::::new()).await?; publish_wit( - &warg_config.client_config, + config, "test:bar", "1.0.0", r#"package test:bar@1.0.0; @@ -38,7 +34,6 @@ world foo { import foo: func() -> string; export bar: func() -> string; }"#, - true, ) .await?; @@ -63,13 +58,10 @@ world foo { #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn update_without_compatible_changes_is_a_noop() -> Result<()> { - let (server, config, registry) = spawn_server(Vec::::new()).await?; - - let warg_config = - WargRegistryConfig::try_from(config.registry_config(®istry).unwrap()).unwrap(); + let (server, config, _) = spawn_server(Vec::::new()).await?; publish_wit( - &warg_config.client_config, + config.clone(), "test:bar", "1.0.0", r#"package test:bar@1.0.0; @@ -77,7 +69,6 @@ world foo { import foo: func() -> string; export bar: func() -> string; }"#, - true, ) .await?; @@ -92,14 +83,13 @@ world foo { validate_component(&project.debug_wasm("component"))?; publish_wit( - &warg_config.client_config, + config, "test:bar", "2.0.0", r#"package test:bar@2.0.0; world foo { export bar: func() -> string; }"#, - false, ) .await?; @@ -123,13 +113,10 @@ world foo { #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn update_with_compatible_changes() -> Result<()> { - let (server, config, registry) = spawn_server(Vec::::new()).await?; - - let warg_config = - WargRegistryConfig::try_from(config.registry_config(®istry).unwrap()).unwrap(); + let (server, config, _) = spawn_server(Vec::::new()).await?; publish_wit( - &warg_config.client_config, + config.clone(), "test:bar", "1.0.0", r#"package test:bar@1.0.0; @@ -137,7 +124,6 @@ world foo { import foo: func() -> string; export bar: func() -> string; }"#, - true, ) .await?; @@ -152,7 +138,7 @@ world foo { validate_component(&project.debug_wasm("component"))?; publish_wit( - &warg_config.client_config, + config, "test:bar", "1.1.0", r#"package test:bar@1.1.0; @@ -161,7 +147,6 @@ world foo { import baz: func() -> string; export bar: func() -> string; }"#, - false, ) .await?; @@ -201,13 +186,10 @@ bindings::export!(Component with_types_in bindings); #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn update_with_compatible_changes_is_noop_for_dryrun() -> Result<()> { - let (server, config, registry) = spawn_server(Vec::::new()).await?; - - let warg_config = - WargRegistryConfig::try_from(config.registry_config(®istry).unwrap()).unwrap(); + let (server, config, _) = spawn_server(Vec::::new()).await?; publish_wit( - &warg_config.client_config, + config.clone(), "test:bar", "1.0.0", r#"package test:bar@1.0.0; @@ -215,7 +197,6 @@ world foo { import foo: func() -> string; export bar: func() -> string; }"#, - true, ) .await?; @@ -230,7 +211,7 @@ world foo { validate_component(&project.debug_wasm("component"))?; publish_wit( - &warg_config.client_config, + config.clone(), "test:bar", "1.1.0", r#"package test:bar@1.1.0; @@ -239,7 +220,6 @@ world foo { import baz: func() -> string; export bar: func() -> string; }"#, - false, ) .await?; @@ -266,27 +246,10 @@ world foo { #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn update_with_changed_dependencies() -> Result<()> { - let (server, config, registry) = spawn_server(Vec::::new()).await?; - - let warg_config = - WargRegistryConfig::try_from(config.registry_config(®istry).unwrap()).unwrap(); + let (server, config, _) = spawn_server(Vec::::new()).await?; - publish_component( - &warg_config.client_config, - "test:bar", - "1.0.0", - "(component)", - true, - ) - .await?; - publish_component( - &warg_config.client_config, - "test:baz", - "1.0.0", - "(component)", - true, - ) - .await?; + publish_component(config.clone(), "test:bar", "1.0.0", "(component)").await?; + publish_component(config, "test:baz", "1.0.0", "(component)").await?; let project = server.project("foo", true, Vec::::new())?;