Skip to content

Commit 1add614

Browse files
committed
Fix component URL if bundled within the forc tarball (#654)
1 parent 5905a32 commit 1add614

File tree

1 file changed

+36
-30
lines changed

1 file changed

+36
-30
lines changed

src/target_triple.rs

+36-30
Original file line numberDiff line numberDiff line change
@@ -53,40 +53,46 @@ impl TargetTriple {
5353
}
5454

5555
pub fn from_component(component: &str) -> Result<Self> {
56-
match Component::from_name(component).map(|c| c.name)?.as_str() {
57-
component::FORC => {
58-
let os = match std::env::consts::OS {
59-
"macos" => "darwin",
60-
"linux" => "linux",
61-
unsupported_os => bail!("Unsupported os: {}", unsupported_os),
62-
};
63-
let architecture = match std::env::consts::ARCH {
64-
"aarch64" => "arm64",
65-
"x86_64" => "amd64",
66-
unsupported_arch => bail!("Unsupported architecture: {}", unsupported_arch),
67-
};
56+
let is_bundled_with_forc = Component::from_name(component)
57+
.map(|comp| {
58+
comp.name == component::FORC
59+
|| Component::from_name(component::FORC)
60+
.map(|forc| comp.tarball_prefix == forc.tarball_prefix)
61+
.unwrap_or(false)
62+
})
63+
.unwrap_or(false);
6864

69-
Ok(Self(format!("{os}_{architecture}")))
70-
}
71-
_ => {
72-
let architecture = match std::env::consts::ARCH {
73-
"aarch64" | "x86_64" => std::env::consts::ARCH,
74-
unsupported_arch => bail!("Unsupported architecture: {}", unsupported_arch),
75-
};
65+
if is_bundled_with_forc {
66+
let os = match std::env::consts::OS {
67+
"macos" => "darwin",
68+
"linux" => "linux",
69+
unsupported_os => bail!("Unsupported os: {}", unsupported_os),
70+
};
71+
let architecture = match std::env::consts::ARCH {
72+
"aarch64" => "arm64",
73+
"x86_64" => "amd64",
74+
unsupported_arch => bail!("Unsupported architecture: {}", unsupported_arch),
75+
};
7676

77-
let vendor = match std::env::consts::OS {
78-
"macos" => "apple",
79-
_ => "unknown",
80-
};
77+
Ok(Self(format!("{os}_{architecture}")))
78+
} else {
79+
let architecture = match std::env::consts::ARCH {
80+
"aarch64" | "x86_64" => std::env::consts::ARCH,
81+
unsupported_arch => bail!("Unsupported architecture: {}", unsupported_arch),
82+
};
8183

82-
let os = match std::env::consts::OS {
83-
"macos" => "darwin",
84-
"linux" => "linux-gnu",
85-
unsupported_os => bail!("Unsupported os: {}", unsupported_os),
86-
};
84+
let vendor = match std::env::consts::OS {
85+
"macos" => "apple",
86+
_ => "unknown",
87+
};
8788

88-
Ok(Self(format!("{architecture}-{vendor}-{os}")))
89-
}
89+
let os = match std::env::consts::OS {
90+
"macos" => "darwin",
91+
"linux" => "linux-gnu",
92+
unsupported_os => bail!("Unsupported os: {}", unsupported_os),
93+
};
94+
95+
Ok(Self(format!("{architecture}-{vendor}-{os}")))
9096
}
9197
}
9298
}

0 commit comments

Comments
 (0)