diff --git a/Cargo.lock b/Cargo.lock index c4967d49..f4f2aa54 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + [[package]] name = "ahash" version = "0.8.11" @@ -90,6 +96,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d92bec98840b8f03a5ff5413de5293bfcd8bf96467cf5452609f939ec6f5de16" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "bindgen" version = "0.71.1" @@ -580,6 +592,16 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "flate2" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + [[package]] name = "foldhash" version = "0.1.3" @@ -1073,6 +1095,15 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" +[[package]] +name = "miniz_oxide" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" +dependencies = [ + "adler2", +] + [[package]] name = "ndk-context" version = "0.1.1" @@ -1378,6 +1409,21 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + [[package]] name = "rustc-hash" version = "2.1.0" @@ -1397,6 +1443,38 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "rustls" +version = "0.23.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5065c3f250cbd332cd894be57c40fa52387247659b14a2d6041d121547903b1b" +dependencies = [ + "log", + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pki-types" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2bf47e6ff922db3825eb750c4e2ff784c6ff8fb9e13046ef6a1d1c5401b0b37" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + [[package]] name = "ryu" version = "1.0.18" @@ -1502,6 +1580,12 @@ dependencies = [ "serde", ] +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + [[package]] name = "sptr" version = "0.3.2" @@ -1526,6 +1610,12 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + [[package]] name = "syn" version = "2.0.90" @@ -1895,6 +1985,28 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7de7d73e1754487cb58364ee906a499937a0dfabd86bcb980fa99ec8c8fa2ce" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "ureq" +version = "2.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02d1a66277ed75f640d608235660df48c8e3c19f3b4edb6a263315626cc3c01d" +dependencies = [ + "base64", + "flate2", + "log", + "once_cell", + "rustls", + "rustls-pki-types", + "url", + "webpki-roots", +] + [[package]] name = "url" version = "2.5.4" @@ -2272,6 +2384,15 @@ dependencies = [ "web-sys", ] +[[package]] +name = "webpki-roots" +version = "0.26.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d642ff16b7e79272ae451b7322067cdc17cadf68c23264be9d94a32319efe7e" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "widestring" version = "1.1.0" @@ -2556,6 +2677,7 @@ dependencies = [ "serde", "serde_json", "toml", + "ureq", ] [[package]] diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index a5ccd681..774fd8e8 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -27,3 +27,4 @@ regex.workspace = true semver.workspace = true serde.workspace = true serde_json.workspace = true +ureq = "2.12.1" diff --git a/xtask/src/bump.rs b/xtask/src/bump.rs index 671793cf..ba54eede 100644 --- a/xtask/src/bump.rs +++ b/xtask/src/bump.rs @@ -1,4 +1,4 @@ -use std::{cmp::Ordering, path::Path}; +use std::cmp::Ordering; use anyhow::{anyhow, Result}; use git2::{DiffOptions, Repository}; @@ -6,7 +6,7 @@ use indoc::indoc; use semver::{BuildMetadata, Prerelease, Version}; use toml::Value; -use crate::BumpVersion; +use crate::{create_commit, BumpVersion}; pub fn get_latest_tag(repo: &Repository) -> Result { let mut tags = repo @@ -140,42 +140,26 @@ pub fn run(args: BumpVersion) -> Result<()> { } fn tag_next_version(repo: &Repository, next_version: &Version) -> Result<()> { - // first add the manifests - - let mut index = repo.index()?; - - for file in [ - "Cargo.toml", - "Cargo.lock", - "cli/Cargo.toml", - "cli/config/Cargo.toml", - "cli/loader/Cargo.toml", - "lib/Cargo.toml", - "highlight/Cargo.toml", - "tags/Cargo.toml", - "cli/npm/package.json", - "lib/binding_web/package.json", - "Makefile", - "lib/CMakeLists.txt", - "build.zig.zon", - ] { - index.add_path(Path::new(file))?; - } - - index.write()?; - - let tree_id = index.write_tree()?; - let tree = repo.find_tree(tree_id)?; let signature = repo.signature()?; - let parent_commit = repo.revparse_single("HEAD")?.peel_to_commit()?; - let commit_id = repo.commit( - Some("HEAD"), - &signature, - &signature, + let commit_id = create_commit( + repo, &format!("{next_version}"), - &tree, - &[&parent_commit], + &[ + "Cargo.toml", + "Cargo.lock", + "cli/Cargo.toml", + "cli/config/Cargo.toml", + "cli/loader/Cargo.toml", + "lib/Cargo.toml", + "highlight/Cargo.toml", + "tags/Cargo.toml", + "cli/npm/package.json", + "lib/binding_web/package.json", + "Makefile", + "lib/CMakeLists.txt", + "build.zig.zon", + ], )?; let tag = repo.tag( diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 92f7258d..a9cb3f83 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -5,11 +5,15 @@ mod clippy; mod fetch; mod generate; mod test; +mod upgrade_emscripten; mod upgrade_wasmtime; +use std::path::Path; + use anstyle::{AnsiColor, Color, Style}; use anyhow::Result; use clap::{crate_authors, Args, Command, FromArgMatches as _, Subcommand}; +use git2::{Oid, Repository}; use semver::Version; #[derive(Subcommand)] @@ -42,6 +46,8 @@ enum Commands { TestWasm, /// Upgrade the wasmtime dependency. UpgradeWasmtime(UpgradeWasmtime), + /// Upgrade the emscripten file. + UpgradeEmscripten, } #[derive(Args)] @@ -208,6 +214,7 @@ fn run() -> Result<()> { Commands::UpgradeWasmtime(upgrade_wasmtime_options) => { upgrade_wasmtime::run(&upgrade_wasmtime_options)?; } + Commands::UpgradeEmscripten => upgrade_emscripten::run()?, } Ok(()) @@ -252,3 +259,26 @@ const fn get_styles() -> clap::builder::Styles { ) .placeholder(Style::new().fg_color(Some(Color::Ansi(AnsiColor::White)))) } + +pub fn create_commit(repo: &Repository, msg: &str, paths: &[&str]) -> Result { + let mut index = repo.index()?; + for path in paths { + index.add_path(Path::new(path))?; + } + + index.write()?; + + let tree_id = index.write_tree()?; + let tree = repo.find_tree(tree_id)?; + let signature = repo.signature()?; + let parent_commit = repo.revparse_single("HEAD")?.peel_to_commit()?; + + Ok(repo.commit( + Some("HEAD"), + &signature, + &signature, + msg, + &tree, + &[&parent_commit], + )?) +} diff --git a/xtask/src/upgrade_emscripten.rs b/xtask/src/upgrade_emscripten.rs new file mode 100644 index 00000000..db5d5454 --- /dev/null +++ b/xtask/src/upgrade_emscripten.rs @@ -0,0 +1,40 @@ +use std::{fs, path::Path}; + +use anyhow::{anyhow, Result}; +use git2::Repository; +use serde_json::Value; + +use crate::create_commit; + +pub fn run() -> Result<()> { + let response = ureq::get("https://api.github.com/repos/emscripten-core/emsdk/tags") + .call()? + .into_string()?; + + let json = serde_json::from_str::(&response)?; + let version = json + .as_array() + .and_then(|arr| arr.first()) + .and_then(|tag| tag["name"].as_str()) + .ok_or(anyhow!("No tags found"))?; + + let version_file = Path::new(env!("CARGO_MANIFEST_DIR")) + .parent() + .unwrap() + .join("cli") + .join("loader") + .join("emscripten-version"); + + fs::write(version_file, version)?; + + println!("Upgraded emscripten version to {version}"); + + let repo = Repository::open(".")?; + create_commit( + &repo, + "build(deps): bump emscripten version", + &["cli/loader/emscripten-version"], + )?; + + Ok(()) +} diff --git a/xtask/src/upgrade_wasmtime.rs b/xtask/src/upgrade_wasmtime.rs index 6a8f4976..0510282c 100644 --- a/xtask/src/upgrade_wasmtime.rs +++ b/xtask/src/upgrade_wasmtime.rs @@ -1,10 +1,10 @@ -use std::{path::Path, process::Command}; +use std::process::Command; use anyhow::{Context, Result}; use git2::Repository; use semver::Version; -use crate::UpgradeWasmtime; +use crate::{create_commit, UpgradeWasmtime}; const WASMTIME_RELEASE_URL: &str = "https://github.com/bytecodealliance/wasmtime/releases/download"; @@ -108,29 +108,6 @@ fn update_zig(version: &Version) -> Result<()> { Ok(()) } -fn create_commit(repo: &Repository, version: &Version) -> Result<()> { - let mut index = repo.index()?; - index.add_path(Path::new("lib/Cargo.toml"))?; - index.add_path(Path::new("build.zig.zon"))?; - index.write()?; - - let tree_id = index.write_tree()?; - let tree = repo.find_tree(tree_id)?; - let signature = repo.signature()?; - let parent_commit = repo.revparse_single("HEAD")?.peel_to_commit()?; - - let _ = repo.commit( - Some("HEAD"), - &signature, - &signature, - &format!("build(deps): bump wasmtime-c-api to v{version}"), - &tree, - &[&parent_commit], - )?; - - Ok(()) -} - pub fn run(args: &UpgradeWasmtime) -> Result<()> { println!("Upgrading wasmtime for Rust"); update_cargo(&args.version)?; @@ -139,7 +116,11 @@ pub fn run(args: &UpgradeWasmtime) -> Result<()> { update_zig(&args.version)?; let repo = Repository::open(".")?; - create_commit(&repo, &args.version)?; + create_commit( + &repo, + &format!("build(deps): bump wasmtime-c-api to v{}", args.version), + &["lib/Cargo.toml", "build.zig.zon"], + )?; Ok(()) }