Skip to content

Commit

Permalink
Add support for ARM64EC when building with MSVC
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaoliello committed Dec 13, 2023
1 parent f2e1b1c commit 5692c65
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1636,6 +1636,8 @@ impl Build {
} else {
if target.contains("i586") {
cmd.push_cc_arg("-arch:IA32".into());
} else if target.contains("arm64ec") {
cmd.push_cc_arg("-arm64EC".into());
}
}

Expand Down
32 changes: 22 additions & 10 deletions src/windows_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ mod impl_ {
// Convert the Rust target arch to its VS arch equivalent.
let arch = match target.split("-").next() {
Some("x86_64") => "x64",
Some("aarch64") => "arm64",
Some("aarch64") | Some("arm64ec") => "arm64",
Some("i686") | Some("i586") => "x86",
Some("thumbv7a") => "arm",
// An unrecognized arch.
Expand Down Expand Up @@ -286,7 +286,7 @@ mod impl_ {
if target.contains("x86_64") {
tool.env.push(("Platform".into(), "X64".into()));
}
if target.contains("aarch64") {
if target.contains("aarch64") || target.contains("arm64ec") {
tool.env.push(("Platform".into(), "ARM64".into()));
}
Some(tool)
Expand Down Expand Up @@ -340,7 +340,7 @@ mod impl_ {
let tools_arch = match arch {
"i586" | "i686" | "x86_64" => Some("x86.x64"),
"arm" | "thumbv7a" => Some("ARM"),
"aarch64" => Some("ARM64"),
"aarch64" | "arm64ec" => Some("ARM64"),
_ => None,
};

Expand Down Expand Up @@ -480,7 +480,7 @@ mod impl_ {
let bin_path = path
.join("bin")
.join(&format!("Host{}", host))
.join(&target);
.join(&bin_subdir(target)?);
// But! we also need PATH to contain the target directory for the host
// architecture, because it contains dlls like mspdb140.dll compiled for
// the host architecture.
Expand All @@ -507,7 +507,7 @@ mod impl_ {
// the Windows 10 SDK or Windows 8.1 SDK.
pub fn find_msvc_14(tool: &str, target: &str) -> Option<Tool> {
let vcdir = get_vc_dir("14.0")?;
let mut tool = get_tool(tool, &vcdir, target)?;
let mut tool = get_tool_14_and_older(tool, &vcdir, target)?;
add_sdks(&mut tool, target)?;
Some(tool.into_tool())
}
Expand Down Expand Up @@ -557,7 +557,7 @@ mod impl_ {
// For MSVC 12 we need to find the Windows 8.1 SDK.
pub fn find_msvc_12(tool: &str, target: &str) -> Option<Tool> {
let vcdir = get_vc_dir("12.0")?;
let mut tool = get_tool(tool, &vcdir, target)?;
let mut tool = get_tool_14_and_older(tool, &vcdir, target)?;
let sub = lib_subdir(target)?;
let sdk81 = get_sdk81_dir()?;
tool.path.push(sdk81.join("bin").join(sub));
Expand All @@ -573,7 +573,7 @@ mod impl_ {
// For MSVC 11 we need to find the Windows 8 SDK.
pub fn find_msvc_11(tool: &str, target: &str) -> Option<Tool> {
let vcdir = get_vc_dir("11.0")?;
let mut tool = get_tool(tool, &vcdir, target)?;
let mut tool = get_tool_14_and_older(tool, &vcdir, target)?;
let sub = lib_subdir(target)?;
let sdk8 = get_sdk8_dir()?;
tool.path.push(sdk8.join("bin").join(sub));
Expand All @@ -596,8 +596,8 @@ mod impl_ {

// Given a possible MSVC installation directory, we look for the linker and
// then add the MSVC library path.
fn get_tool(tool: &str, path: &Path, target: &str) -> Option<MsvcTool> {
bin_subdir(target)
fn get_tool_14_and_older(tool: &str, path: &Path, target: &str) -> Option<MsvcTool> {
bin_subdir_14_and_older(target)
.into_iter()
.map(|(sub, host)| {
(
Expand Down Expand Up @@ -734,7 +734,7 @@ mod impl_ {
// linkers that can target the architecture we desire. The 64-bit host
// linker is preferred, and hence first, due to 64-bit allowing it more
// address space to work with and potentially being faster.
fn bin_subdir(target: &str) -> Vec<(&'static str, &'static str)> {
fn bin_subdir_14_and_older(target: &str) -> Vec<(&'static str, &'static str)> {
let arch = target.split('-').next().unwrap();
match (arch, host_arch()) {
("i586", X86) | ("i686", X86) => vec![("", "")],
Expand All @@ -754,6 +754,18 @@ mod impl_ {
"x86_64" => Some("x64"),
"arm" | "thumbv7a" => Some("arm"),
"aarch64" => Some("arm64"),
"arm64ec" => Some("arm64ec"),
_ => None,
}
}

fn bin_subdir(target: &str) -> Option<&'static str> {
let arch = target.split('-').next().unwrap();
match arch {
"i586" | "i686" => Some("x86"),
"x86_64" => Some("x64"),
"arm" | "thumbv7a" => Some("arm"),
"aarch64" | "arm64ec" => Some("arm64"),
_ => None,
}
}
Expand Down

0 comments on commit 5692c65

Please sign in to comment.