diff --git a/manifests/cargo-rdme.json b/manifests/cargo-rdme.json index 42149b6f..18f79cab 100644 --- a/manifests/cargo-rdme.json +++ b/manifests/cargo-rdme.json @@ -1,5 +1,5 @@ { - "rust_crate": null, + "rust_crate": "cargo-rdme", "template": { "x86_64_linux_musl": { "url": "https://github.com/orium/cargo-rdme/releases/download/v${version}/cargo-rdme_v${version}_x86_64-unknown-linux-musl.tar.bz2" diff --git a/tools/codegen/Cargo.toml b/tools/codegen/Cargo.toml index 37702931..fe973e04 100644 --- a/tools/codegen/Cargo.toml +++ b/tools/codegen/Cargo.toml @@ -14,6 +14,7 @@ serde_json = "1" sha2 = "0.10" tar = "0.4" toml_edit = { version = "0.22", default-features = false, features = ["parse", "serde"] } +# TODO: call curl command instead of using ureq? ureq = { version = "2", features = ["json"] } [lints] diff --git a/tools/codegen/base/cargo-dinghy.json b/tools/codegen/base/cargo-dinghy.json index 1c3066c6..a6e2a63e 100644 --- a/tools/codegen/base/cargo-dinghy.json +++ b/tools/codegen/base/cargo-dinghy.json @@ -2,7 +2,7 @@ "repository": "https://github.com/sonos/dinghy", "tag_prefix": "", "rust_crate": "${package}", - "asset_name": "${package}-${os_name}-${version}.tgz", + "asset_name": "${package}-${rust_target_os}-${version}.tgz", "bin": "${package}-${version}/${package}${exe}", "platform": { "x86_64_linux_musl": {}, diff --git a/tools/codegen/base/cargo-rdme.json b/tools/codegen/base/cargo-rdme.json index 99ad896c..f3e2fc6b 100644 --- a/tools/codegen/base/cargo-rdme.json +++ b/tools/codegen/base/cargo-rdme.json @@ -1,6 +1,7 @@ { "repository": "https://github.com/orium/cargo-rdme", "tag_prefix": "v", + "rust_crate": "${package}", "broken": ["1.4.3"], "platform": { "x86_64_linux_musl": { diff --git a/tools/codegen/base/wasmtime.json b/tools/codegen/base/wasmtime.json index c870bd50..0cd6095f 100644 --- a/tools/codegen/base/wasmtime.json +++ b/tools/codegen/base/wasmtime.json @@ -2,26 +2,15 @@ "repository": "https://github.com/bytecodealliance/wasmtime", "tag_prefix": "v", "rust_crate": "wasmtime-cli", + "asset_name": "${package}-v${version}-${rust_target_arch}-${rust_target_os}.tar.xz", + "bin": "${package}-v${version}-${rust_target_arch}-${rust_target_os}/${package}${exe}", "platform": { - "x86_64_linux_gnu": { - "asset_name": "${package}-v${version}-x86_64-linux.tar.xz", - "bin": "${package}-v${version}-x86_64-linux/${package}${exe}" - }, - "x86_64_macos": { - "asset_name": "${package}-v${version}-x86_64-macos.tar.xz", - "bin": "${package}-v${version}-x86_64-macos/${package}${exe}" - }, + "x86_64_linux_gnu": {}, + "x86_64_macos": {}, "x86_64_windows": { - "asset_name": "${package}-v${version}-x86_64-windows.zip", - "bin": "${package}-v${version}-x86_64-windows/${package}${exe}" + "asset_name": "${package}-v${version}-${rust_target_arch}-${rust_target_os}.zip" }, - "aarch64_linux_gnu": { - "asset_name": "${package}-v${version}-aarch64-linux.tar.xz", - "bin": "${package}-v${version}-aarch64-linux/${package}${exe}" - }, - "aarch64_macos": { - "asset_name": "${package}-v${version}-aarch64-macos.tar.xz", - "bin": "${package}-v${version}-aarch64-macos/${package}${exe}" - } + "aarch64_linux_gnu": {}, + "aarch64_macos": {} } } diff --git a/tools/codegen/base/xbuild.json b/tools/codegen/base/xbuild.json index caec34e8..41525ad9 100644 --- a/tools/codegen/base/xbuild.json +++ b/tools/codegen/base/xbuild.json @@ -2,8 +2,8 @@ "repository": "https://github.com/rust-mobile/xbuild", "tag_prefix": "v", "rust_crate": "${package}", - "asset_name": "${package}-${os_name}-x64${exe}", - "bin": "${package}-${os_name}-x64${exe}", + "asset_name": "${package}-${rust_target_os}-x64${exe}", + "bin": "${package}-${rust_target_os}-x64${exe}", "version_range": ">= 0.2.0", "platform": { "x86_64_linux_gnu": {}, diff --git a/tools/codegen/src/main.rs b/tools/codegen/src/main.rs index 462a1923..698629e7 100644 --- a/tools/codegen/src/main.rs +++ b/tools/codegen/src/main.rs @@ -83,8 +83,11 @@ fn main() -> Result<()> { } let mut crates_io_info = None; - base_info.rust_crate = - base_info.rust_crate.as_ref().map(|s| replace_vars(s, package, None, None)).transpose()?; + base_info.rust_crate = base_info + .rust_crate + .as_ref() + .map(|s| replace_vars(s, package, None, None, base_info.rust_crate.as_deref())) + .transpose()?; if let Some(crate_name) = &base_info.rust_crate { eprintln!("downloading crate info from https://crates.io/api/v1/crates/{crate_name}"); crates_io_info = Some( @@ -185,7 +188,15 @@ fn main() -> Result<()> { .with_context(|| format!("asset_name is needed for {package} on {platform:?}"))? .as_slice() .iter() - .map(|asset_name| replace_vars(asset_name, package, Some(version), Some(platform))) + .map(|asset_name| { + replace_vars( + asset_name, + package, + Some(version), + Some(platform), + base_info.rust_crate.as_deref(), + ) + }) .collect::>>()?; let (url, asset_name) = match asset_names.iter().find_map(|asset_name| { release @@ -306,7 +317,15 @@ fn main() -> Result<()> { .bin .as_ref() .or(base_info.bin.as_ref()) - .map(|s| replace_vars(s, package, Some(version), Some(platform))) + .map(|s| { + replace_vars( + s, + package, + Some(version), + Some(platform), + base_info.rust_crate.as_deref(), + ) + }) .transpose()?, }); buf.clear(); @@ -471,18 +490,33 @@ fn replace_vars( package: &str, version: Option<&str>, platform: Option, + rust_crate: Option<&str>, ) -> Result { + const RUST_SPECIFIC: &[(&str, fn(HostPlatform) -> &'static str)] = &[ + ("${rust_target}", HostPlatform::rust_target), + ("${rust_target_arch}", HostPlatform::rust_target_arch), + ("${rust_target_os}", HostPlatform::rust_target_os), + ]; let mut s = s.replace("${package}", package).replace("${tool}", package); if let Some(platform) = platform { - s = s - .replace("${rust_target}", platform.rust_target()) - .replace("${os_name}", platform.os_name()) - .replace("${exe}", platform.exe_suffix()); + s = s.replace("${exe}", platform.exe_suffix()); + if rust_crate.is_some() { + for &(var, f) in RUST_SPECIFIC { + s = s.replace(var, f(platform)); + } + } } if let Some(version) = version { s = s.replace("${version}", version); } if s.contains('$') { + for &(var, _) in RUST_SPECIFIC { + if s.contains(var) { + bail!( + "base manifest for {package} refers {var}, but 'rust_crate' field is not set" + ); + } + } bail!("variable not fully replaced: '{s}'"); } Ok(s) @@ -799,7 +833,19 @@ impl HostPlatform { Self::aarch64_windows => "aarch64-pc-windows-msvc", } } - fn os_name(self) -> &'static str { + fn rust_target_arch(self) -> &'static str { + match self { + Self::aarch64_linux_gnu + | Self::aarch64_linux_musl + | Self::aarch64_macos + | Self::aarch64_windows => "aarch64", + Self::x86_64_linux_gnu + | Self::x86_64_linux_musl + | Self::x86_64_macos + | Self::x86_64_windows => "x86_64", + } + } + fn rust_target_os(self) -> &'static str { match self { Self::aarch64_linux_gnu | Self::aarch64_linux_musl