mirror of
https://github.com/taiki-e/install-action.git
synced 2026-04-09 18:11:48 +08:00
codegen: Add rust_crate field to cargo-rdme
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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": {},
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -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": {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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": {},
|
||||
|
||||
@@ -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::<Result<Vec<_>>>()?;
|
||||
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<HostPlatform>,
|
||||
rust_crate: Option<&str>,
|
||||
) -> Result<String> {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user