Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support wasm32-unknown-wasi and x86_64-apple-macosx10.7.0 #14

Merged
merged 5 commits into from
Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 45 additions & 2 deletions src/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,15 @@ pub enum OperatingSystem {
Ios,
L4re,
Linux,
MacOSX { major: u16, minor: u16, patch: u16 },
Nebulet,
Netbsd,
None_,
Openbsd,
Redox,
Solaris,
Uefi,
Wasi,
Windows,
}

Expand Down Expand Up @@ -424,9 +426,11 @@ impl Architecture {
pub fn default_binary_format(triple: &Triple) -> BinaryFormat {
match triple.operating_system {
OperatingSystem::None_ => BinaryFormat::Unknown,
OperatingSystem::Darwin | OperatingSystem::Ios => BinaryFormat::Macho,
OperatingSystem::Darwin | OperatingSystem::Ios
| OperatingSystem::MacOSX { .. } => BinaryFormat::Macho,
OperatingSystem::Windows => BinaryFormat::Coff,
OperatingSystem::Nebulet | OperatingSystem::Emscripten | OperatingSystem::Unknown => {
OperatingSystem::Nebulet | OperatingSystem::Emscripten | OperatingSystem::Wasi
| OperatingSystem::Unknown => {
match triple.architecture {
Architecture::Wasm32 => BinaryFormat::Wasm,
_ => BinaryFormat::Unknown,
Expand Down Expand Up @@ -677,13 +681,17 @@ impl fmt::Display for OperatingSystem {
OperatingSystem::Ios => "ios",
OperatingSystem::L4re => "l4re",
OperatingSystem::Linux => "linux",
OperatingSystem::MacOSX { major, minor, patch } => {
return write!(f, "macosx{}.{}.{}", major, minor, patch);
}
OperatingSystem::Nebulet => "nebulet",
OperatingSystem::Netbsd => "netbsd",
OperatingSystem::None_ => "none",
OperatingSystem::Openbsd => "openbsd",
OperatingSystem::Redox => "redox",
OperatingSystem::Solaris => "solaris",
OperatingSystem::Uefi => "uefi",
OperatingSystem::Wasi => "wasi",
OperatingSystem::Windows => "windows",
};
f.write_str(s)
Expand All @@ -694,6 +702,37 @@ impl FromStr for OperatingSystem {
type Err = ();

fn from_str(s: &str) -> Result<Self, ()> {
// TODO also parse version number for darwin and ios OSes
if s.starts_with("macosx") {
// Parse operating system names like `macosx10.7.0`.
let s = &s["macosx".len()..];
let mut parts = s.split(".").map(|num| num.parse::<u16>());
bjorn3 marked this conversation as resolved.
Show resolved Hide resolved

macro_rules! get_part {
() => {
if let Some(Ok(part)) = parts.next() {
part
} else {
return Err(());
}
};
}

let major = get_part!();
let minor = get_part!();
let patch = get_part!();

if parts.next().is_some() {
return Err(());
}

return Ok(OperatingSystem::MacOSX {
major,
minor,
patch,
})
}
bjorn3 marked this conversation as resolved.
Show resolved Hide resolved

Ok(match s {
"unknown" => OperatingSystem::Unknown,
"bitrig" => OperatingSystem::Bitrig,
Expand All @@ -715,6 +754,7 @@ impl FromStr for OperatingSystem {
"redox" => OperatingSystem::Redox,
"solaris" => OperatingSystem::Solaris,
"uefi" => OperatingSystem::Uefi,
"wasi" => OperatingSystem::Wasi,
"windows" => OperatingSystem::Windows,
_ => return Err(()),
})
Expand Down Expand Up @@ -850,6 +890,7 @@ mod tests {
"i586-unknown-linux-musl",
"i686-apple-darwin",
"i686-linux-android",
"i686-apple-macosx10.7.0",
"i686-pc-windows-gnu",
"i686-pc-windows-msvc",
"i686-unknown-cloudabi",
Expand Down Expand Up @@ -897,11 +938,13 @@ mod tests {
"wasm32-experimental-emscripten",
"wasm32-unknown-emscripten",
"wasm32-unknown-unknown",
"wasm32-wasi",
"x86_64-apple-darwin",
"x86_64-apple-ios",
"x86_64-fortanix-unknown-sgx",
"x86_64-fuchsia",
"x86_64-linux-android",
"x86_64-apple-macosx10.7.0",
"x86_64-pc-windows-gnu",
"x86_64-pc-windows-msvc",
"x86_64-rumprun-netbsd",
Expand Down
14 changes: 12 additions & 2 deletions src/triple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ impl PointerWidth {
#[allow(missing_docs)]
pub enum CallingConvention {
SystemV,
/// https://github.com/WebAssembly/tool-conventions/blob/master/BasicCABI.md
WasmBasicCAbi,
WindowsFastcall,
}

Expand Down Expand Up @@ -97,12 +99,19 @@ impl Triple {
| OperatingSystem::Ios
| OperatingSystem::L4re
| OperatingSystem::Linux
| OperatingSystem::Nebulet
| OperatingSystem::MacOSX { .. }
| OperatingSystem::Netbsd
| OperatingSystem::Openbsd
| OperatingSystem::Redox
| OperatingSystem::Solaris => CallingConvention::SystemV,
OperatingSystem::Windows => CallingConvention::WindowsFastcall,
OperatingSystem::Nebulet | OperatingSystem::Emscripten | OperatingSystem::Wasi
| OperatingSystem::Unknown => {
match self.architecture {
Architecture::Wasm32 => CallingConvention::WasmBasicCAbi,
_ => return Err(()),
}
}
_ => return Err(()),
})
}
Expand Down Expand Up @@ -160,6 +169,7 @@ impl fmt::Display for Triple {
&& (self.environment == Environment::Android
|| self.environment == Environment::Androideabi))
|| self.operating_system == OperatingSystem::Fuchsia
|| self.operating_system == OperatingSystem::Wasi
|| (self.operating_system == OperatingSystem::None_
&& (self.architecture == Architecture::Arm(ArmArchitecture::Armebv7r)
|| self.architecture == Architecture::Arm(ArmArchitecture::Armv7r)
Expand All @@ -170,7 +180,7 @@ impl fmt::Display for Triple {
|| self.architecture == Architecture::Arm(ArmArchitecture::Thumbv8mMain)
|| self.architecture == Architecture::Msp430)))
{
// As a special case, omit the vendor for Android, Fuchsia, and sometimes
// As a special case, omit the vendor for Android, Fuchsia, Wasi, and sometimes
// None_, depending on the hardware architecture. This logic is entirely
// ad-hoc, and is just sufficient to handle the current set of recognized
// triples.
Expand Down