From f684a9689093be0e129f3ab09c2af57fd197e825 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Fri, 8 Sep 2023 11:49:10 -0700 Subject: [PATCH] new: Use python-build. --- Cargo.lock | 134 ++++++++++++++++++++++++++++++++++++++++----------- Cargo.toml | 6 +-- README.md | 4 +- src/proto.rs | 40 ++++++++++++--- 4 files changed, 144 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7ee6d8d..c7cfcee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -280,7 +280,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b48814962d2fd604c50d2b9433c2a41a0ab567779ee2c02f7fba6eca1221f082" dependencies = [ "cached_proc_macro_types", - "darling", + "darling 0.14.4", "proc-macro2", "quote", "syn 1.0.109", @@ -667,8 +667,18 @@ version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850" dependencies = [ - "darling_core", - "darling_macro", + "darling_core 0.14.4", + "darling_macro 0.14.4", +] + +[[package]] +name = "darling" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0209d94da627ab5605dcccf08bb18afa5009cfbef48d8a8b7d7bdbc79be25c5e" +dependencies = [ + "darling_core 0.20.3", + "darling_macro 0.20.3", ] [[package]] @@ -685,17 +695,42 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "darling_core" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "177e3443818124b357d8e76f53be906d60937f0d3a90773a664fa63fa253e621" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.31", +] + [[package]] name = "darling_macro" version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e" dependencies = [ - "darling_core", + "darling_core 0.14.4", "quote", "syn 1.0.109", ] +[[package]] +name = "darling_macro" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" +dependencies = [ + "darling_core 0.20.3", + "quote", + "syn 2.0.31", +] + [[package]] name = "debugid" version = "0.8.0" @@ -2021,8 +2056,6 @@ dependencies = [ [[package]] name = "proto_core" version = "0.16.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13a58df3e529b4c61e437c3f5041c35e4e922eccdea8b54775383d90d09aa3a7" dependencies = [ "cached", "extism", @@ -2038,6 +2071,7 @@ dependencies = [ "serde_json", "sha2", "starbase_archive", + "starbase_events", "starbase_styles", "starbase_utils", "thiserror", @@ -2050,8 +2084,6 @@ dependencies = [ [[package]] name = "proto_pdk" version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a5e20d9949449269eaef10ecc2b05f3bdf6397939084d6d6f0574f979fc1340" dependencies = [ "anyhow", "extism-pdk", @@ -2064,8 +2096,6 @@ dependencies = [ [[package]] name = "proto_pdk_api" version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20f1e58f726b5e8c8c92c567f682bdbb2b44f859a108d852a5bdcc94f8fd3452" dependencies = [ "anyhow", "semver", @@ -2078,8 +2108,6 @@ dependencies = [ [[package]] name = "proto_pdk_test_utils" version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6cc13d5b46cc92bee69b74784dace83279efabc30af330b13a18d05a3555b0f8" dependencies = [ "extism", "proto_core", @@ -2091,8 +2119,6 @@ dependencies = [ [[package]] name = "proto_wasm_plugin" version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31b644d1fe65ce5412cd6599a38ddc685b82a3f71a1b0254f8cded2dec52c11e" dependencies = [ "extism", "proto_pdk_api", @@ -2570,6 +2596,15 @@ dependencies = [ "dirs 4.0.0", ] +[[package]] +name = "signal-hook-registry" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +dependencies = [ + "libc", +] + [[package]] name = "similar" version = "2.2.1" @@ -2637,9 +2672,9 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "starbase_archive" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13f717bc785efa5d43255b3418f1a3c82c1506a78e7849bee8e04c96c688bf8e" +checksum = "f85e565b134761413513c0091ed002ffb31ba448ca9542c4c41ca5968a29a9bb" dependencies = [ "flate2", "miette", @@ -2651,13 +2686,38 @@ dependencies = [ "tracing", "xz2", "zip", + "zstd 0.12.4", +] + +[[package]] +name = "starbase_events" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f172a2185991dbfb2a3446c47749ade52d66d2aaea724d19bd45607527ebd9d" +dependencies = [ + "async-trait", + "miette", + "starbase_macros", + "tokio", +] + +[[package]] +name = "starbase_macros" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63159597180d00c01353e4bf4d4401328a30eb618c0130adf7b9371db4df3d3a" +dependencies = [ + "darling 0.20.3", + "proc-macro2", + "quote", + "syn 2.0.31", ] [[package]] name = "starbase_sandbox" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8715fbb4e5ea309784161fddca9b5abfc2425ad079ef624c1fc01c8eea8f7163" +checksum = "62ec8301c49429d3da1105475f4e32ce8fa7c8cf1028c4e4535b0c010be2952a" dependencies = [ "assert_cmd", "assert_fs", @@ -2671,9 +2731,9 @@ dependencies = [ [[package]] name = "starbase_styles" -version = "0.1.14" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6930eace291b6c6dc243074efc7a4c8bdebe0ffd94bcee0176472148f76205d" +checksum = "251a45da918b41577ab62fb764c9683a0f50fb2b8999a629dbd6c25476a9c411" dependencies = [ "dirs 5.0.1", "owo-colors", @@ -2682,9 +2742,9 @@ dependencies = [ [[package]] name = "starbase_utils" -version = "0.2.22" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9bf684116f2b02df3926d3412c97c1d8caa4b9edc49c6b806ed6d8e33cdb8be" +checksum = "032493983d1aaa0e6107219e8b17e2b315452f902f0f512c8bd5af6df6704b44" dependencies = [ "dirs 5.0.1", "fs4", @@ -2697,6 +2757,7 @@ dependencies = [ "serde_json", "starbase_styles", "thiserror", + "tokio", "toml 0.7.6", "tracing", "wax", @@ -2894,8 +2955,10 @@ dependencies = [ "bytes", "libc", "mio", + "num_cpus", "parking_lot", "pin-project-lite", + "signal-hook-registry", "socket2 0.5.3", "tokio-macros", "windows-sys 0.48.0", @@ -3169,8 +3232,6 @@ dependencies = [ [[package]] name = "warpgate" version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ef3766f024730109e7479aab34a33ca7cddba42c867ae282b9722210e17ee0a" dependencies = [ "extism", "miette", @@ -3192,8 +3253,6 @@ dependencies = [ [[package]] name = "warpgate_api" version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c87f4f62fa42fa715ce697387b4c5c66ae0380723b841b1e0ff9fd285c78ab5f" dependencies = [ "serde", ] @@ -3432,7 +3491,7 @@ dependencies = [ "sha2", "toml 0.5.11", "windows-sys 0.48.0", - "zstd", + "zstd 0.11.2+zstd.1.5.2", ] [[package]] @@ -4094,7 +4153,16 @@ version = "0.11.2+zstd.1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4" dependencies = [ - "zstd-safe", + "zstd-safe 5.0.2+zstd.1.5.2", +] + +[[package]] +name = "zstd" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a27595e173641171fc74a1232b7b1c7a7cb6e18222c11e9dfb9888fa424c53c" +dependencies = [ + "zstd-safe 6.0.6", ] [[package]] @@ -4107,6 +4175,16 @@ dependencies = [ "zstd-sys", ] +[[package]] +name = "zstd-safe" +version = "6.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee98ffd0b48ee95e6c5168188e44a54550b1564d9d530ee21d5f0eaed1069581" +dependencies = [ + "libc", + "zstd-sys", +] + [[package]] name = "zstd-sys" version = "2.0.8+zstd.1.5.5" diff --git a/Cargo.toml b/Cargo.toml index 2d56744..b5e4edc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,13 +11,13 @@ crate-type = ['cdylib'] [dependencies] extism-pdk = "0.3.4" once_cell = "1.18.0" -proto_pdk = { version = "0.6.5" } # , path = "../../proto/crates/pdk" } +proto_pdk = { version = "0.6.5", path = "../../proto/crates/pdk" } regex = "1.9.5" serde = "1.0.188" [dev-dependencies] -proto_pdk_test_utils = { version = "0.5.9" } # , path = "../../proto/crates/pdk-test-utils" } -starbase_sandbox = "0.1.9" +proto_pdk_test_utils = { version = "0.5.9", path = "../../proto/crates/pdk-test-utils" } +starbase_sandbox = "0.1.10" tokio = "1.32.0" [profile.release] diff --git a/README.md b/README.md index 849059a..45674e8 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ ## Caveats -This plugin only supports pre-builts via [indygreg/python-build-standalone](https://github.com/indygreg/python-build-standalone), and primarily only Python 3. +If `python-build` exists on the host machine, this will be used to install python. Otherwise, a pre-built version will be downloaded from [indygreg/python-build-standalone](https://github.com/indygreg/python-build-standalone), which doesn't support all versions, only Python 3. -Building from source (with `python-build`), and supporting Python 2, will be supported in the future. +Building from source directly (with `python-build`), and supporting Python 2, will be fully supported in the future. ## Contributing diff --git a/src/proto.rs b/src/proto.rs index f34641f..6ab7d38 100644 --- a/src/proto.rs +++ b/src/proto.rs @@ -8,6 +8,7 @@ use std::fs; #[host_fn] extern "ExtismHost" { fn exec_command(input: Json) -> Json; + fn host_log(input: Json); } static NAME: &str = "Python"; @@ -22,6 +23,34 @@ pub fn register_tool(Json(_): Json) -> FnResult, +) -> FnResult> { + let mut output = NativeInstallOutput::default(); + let env = get_proto_environment()?; + + // https://github.com/pyenv/pyenv/tree/master/plugins/python-build + if command_exists(&env, "python-build") { + host_log!("Building with `python-build` instead of downloading a pre-built"); + + let result = exec_command!( + inherit, + "python-build", + [ + input.context.version.as_str(), + input.context.tool_dir.real_path().to_str().unwrap(), + ] + ); + + output.installed = result.exit_code == 0; + } else { + output.skip_install = true; + } + + Ok(Json(output)) +} + #[derive(Deserialize)] struct ReleaseEntry { download: String, @@ -39,19 +68,16 @@ pub fn download_prebuilt( )?; let Some(release_triples) = releases.get(&input.context.version) else { - return err!(format!( + return err!( "No pre-built available for version {}!", input.context.version - )); + ); }; - let triple = get_target_triple(&env, "Python")?; + let triple = get_target_triple(&env, NAME)?; let Some(release) = release_triples.get(&triple) else { - return err!(format!( - "No pre-built available for architecture {}!", - triple - )); + return err!("No pre-built available for architecture {}!", triple); }; Ok(Json(DownloadPrebuiltOutput {