1
0
Fork 0

Handle AArch64 and more cross compilation targets

In the bundler.
This commit is contained in:
Robbert van der Helm 2022-04-05 04:12:26 +02:00
parent 98d725d24f
commit cf05ca10f8

View file

@ -2,7 +2,7 @@ use anyhow::{bail, Context};
use serde::Deserialize; use serde::Deserialize;
use std::collections::HashMap; use std::collections::HashMap;
use std::fs; use std::fs;
use std::path::Path; use std::path::{Path, PathBuf};
use std::process::Command; use std::process::Command;
mod symbols; mod symbols;
@ -33,16 +33,20 @@ struct PackageConfig {
/// The target we're generating a plugin for. This can be either the native target or a cross /// The target we're generating a plugin for. This can be either the native target or a cross
/// compilation target, so to reduce redundancy when determining the correct bundle paths we'll use /// compilation target, so to reduce redundancy when determining the correct bundle paths we'll use
/// an enum for this. /// an enum for this.
/// #[derive(Debug, Clone, Copy)]
/// TODO: Right now we don't consider ARM targets at all
#[allow(dead_code)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CompilationTarget { pub enum CompilationTarget {
Linux64, Linux(Architecture),
Linux32, MacOS(Architecture),
Mac64, Windows(Architecture),
Windows64, }
Windows32,
#[derive(Debug, Clone, Copy)]
pub enum Architecture {
X86,
X86_64,
// There are also a ton of different 32-bit ARM architectures, we'll just pretend they don't
// exist for now
AArch64,
} }
/// The main xtask entry point function. See the readme for instructions on how to use this. /// The main xtask entry point function. See the readme for instructions on how to use this.
@ -171,7 +175,7 @@ pub fn bundle(package: &str, args: &[String]) -> Result<()> {
} }
let compilation_target = compilation_target(cross_compile_target.as_deref())?; let compilation_target = compilation_target(cross_compile_target.as_deref())?;
let lib_path = Path::new(target_base(cross_compile_target.as_deref())?) let lib_path = target_base(cross_compile_target.as_deref())?
.join(if is_release_build { "release" } else { "debug" }) .join(if is_release_build { "release" } else { "debug" })
.join(library_basename(package, compilation_target)); .join(library_basename(package, compilation_target));
if !lib_path.exists() { if !lib_path.exists() {
@ -295,43 +299,56 @@ fn load_bundler_config() -> Result<Option<BundlerConfig>> {
/// plugin bundles. /// plugin bundles.
fn compilation_target(cross_compile_target: Option<&str>) -> Result<CompilationTarget> { fn compilation_target(cross_compile_target: Option<&str>) -> Result<CompilationTarget> {
match cross_compile_target { match cross_compile_target {
Some("x86_64-unknown-linux-gnu") => Ok(CompilationTarget::Linux64), Some("i686-unknown-linux-gnu") => Ok(CompilationTarget::Linux(Architecture::X86)),
Some("x86_64-apple-darwin") => Ok(CompilationTarget::Mac64), Some("i686-apple-darwin") => Ok(CompilationTarget::MacOS(Architecture::X86)),
Some("x86_64-pc-windows-gnu") => Ok(CompilationTarget::Windows64), Some("i686-pc-windows-gnu") | Some("i686-pc-windows-msvc") => {
Ok(CompilationTarget::Windows(Architecture::X86))
}
Some("x86_64-unknown-linux-gnu") => Ok(CompilationTarget::Linux(Architecture::X86_64)),
Some("x86_64-apple-darwin") => Ok(CompilationTarget::MacOS(Architecture::X86_64)),
Some("x86_64-pc-windows-gnu") | Some("x86_64-pc-windows-msvc") => {
Ok(CompilationTarget::Windows(Architecture::X86_64))
}
Some("aarch64-unknown-linux-gnu") => Ok(CompilationTarget::Linux(Architecture::AArch64)),
Some("aarch64-apple-darwin") => Ok(CompilationTarget::MacOS(Architecture::AArch64)),
Some("aarch64-pc-windows-gnu") | Some("aarch64-pc-windows-msvc") => {
Ok(CompilationTarget::Windows(Architecture::AArch64))
}
Some(target) => bail!("Unhandled cross-compilation target: {}", target), Some(target) => bail!("Unhandled cross-compilation target: {}", target),
None => { None => {
#[cfg(all(target_os = "linux", target_arch = "x86_64"))] #[cfg(target_arch = "x86")]
return Ok(CompilationTarget::Linux64); let architecture = Architecture::X86;
#[cfg(all(target_os = "linux", target_arch = "x86"))] #[cfg(target_arch = "x86_64")]
return Ok(CompilationTarget::Linux32); let architecture = Architecture::X86_64;
#[cfg(all(target_os = "macos", target_arch = "x86_64"))] #[cfg(target_arch = "aarch64")]
return Ok(CompilationTarget::Mac64); let architecture = Architecture::ARM64;
#[cfg(all(target_os = "windows", target_arch = "x86_64"))]
return Ok(CompilationTarget::Windows64); #[cfg(target_os = "linux")]
#[cfg(all(target_os = "windows", target_arch = "x86"))] return Ok(CompilationTarget::Linux(architecture));
return Ok(CompilationTarget::Windows32); #[cfg(target_os = "macos")]
return Ok(CompilationTarget::MacOS(architecture));
#[cfg(target_os = "windows")]
return Ok(CompilationTarget::Windows(architecture));
} }
} }
} }
/// The base directory for the compiled binaries. This does not use [`CompilationTarget`] as we need /// The base directory for the compiled binaries. This does not use [`CompilationTarget`] as we need
/// to be able to differentiate between native and cross-compilation. /// to be able to differentiate between native and cross-compilation.
fn target_base(cross_compile_target: Option<&str>) -> Result<&'static str> { fn target_base(cross_compile_target: Option<&str>) -> Result<PathBuf> {
match cross_compile_target { match cross_compile_target {
Some("x86_64-unknown-linux-gnu") => Ok("target/x86_64-unknown-linux-gnu"), // Unhandled targets will already be handled in `compilation_target`
Some("x86_64-pc-windows-gnu") => Ok("target/x86_64-pc-windows-gnu"), Some(target) => Ok(Path::new("target").join(target)),
Some("x86_64-apple-darwin") => Ok("target/x86_64-apple-darwin"), None => Ok(PathBuf::from("target")),
Some(target) => bail!("Unhandled cross-compilation target: {}", target),
None => Ok("target"),
} }
} }
/// The file name of the compiled library for a `cdylib` crate. /// The file name of the compiled library for a `cdylib` crate.
fn library_basename(package: &str, target: CompilationTarget) -> String { fn library_basename(package: &str, target: CompilationTarget) -> String {
match target { match target {
CompilationTarget::Linux64 | CompilationTarget::Linux32 => format!("lib{package}.so"), CompilationTarget::Linux(_) => format!("lib{package}.so"),
CompilationTarget::Mac64 => format!("lib{package}.dylib"), CompilationTarget::MacOS(_) => format!("lib{package}.dylib"),
CompilationTarget::Windows64 | CompilationTarget::Windows32 => format!("{package}.dll"), CompilationTarget::Windows(_) => format!("{package}.dll"),
} }
} }
@ -339,11 +356,8 @@ fn library_basename(package: &str, target: CompilationTarget) -> String {
/// inside of a CLAP bundle on macOS /// inside of a CLAP bundle on macOS
fn clap_bundle_library_name(package: &str, target: CompilationTarget) -> String { fn clap_bundle_library_name(package: &str, target: CompilationTarget) -> String {
match target { match target {
CompilationTarget::Linux64 CompilationTarget::Linux(_) | CompilationTarget::Windows(_) => format!("{package}.clap"),
| CompilationTarget::Linux32 CompilationTarget::MacOS(_) => format!("{package}.clap/Contents/MacOS/{package}"),
| CompilationTarget::Windows64
| CompilationTarget::Windows32 => format!("{package}.clap"),
CompilationTarget::Mac64 => format!("{package}.clap/Contents/MacOS/{package}"),
} }
} }
@ -351,9 +365,9 @@ fn clap_bundle_library_name(package: &str, target: CompilationTarget) -> String
/// bundle. /// bundle.
fn vst2_bundle_library_name(package: &str, target: CompilationTarget) -> String { fn vst2_bundle_library_name(package: &str, target: CompilationTarget) -> String {
match target { match target {
CompilationTarget::Linux64 | CompilationTarget::Linux32 => format!("{package}.so"), CompilationTarget::Linux(_) => format!("{package}.so"),
CompilationTarget::Windows64 | CompilationTarget::Windows32 => format!("{package}.dll"), CompilationTarget::MacOS(_) => format!("{package}.vst/Contents/MacOS/{package}"),
CompilationTarget::Mac64 => format!("{package}.vst/Contents/MacOS/{package}"), CompilationTarget::Windows(_) => format!("{package}.dll"),
} }
} }
@ -363,13 +377,25 @@ fn vst2_bundle_library_name(package: &str, target: CompilationTarget) -> String
/// See <https://developer.steinberg.help/display/VST/Plug-in+Format+Structure>. /// See <https://developer.steinberg.help/display/VST/Plug-in+Format+Structure>.
fn vst3_bundle_library_name(package: &str, target: CompilationTarget) -> String { fn vst3_bundle_library_name(package: &str, target: CompilationTarget) -> String {
match target { match target {
CompilationTarget::Linux64 => format!("{package}.vst3/Contents/x86_64-linux/{package}.so"), CompilationTarget::Linux(Architecture::X86) => {
CompilationTarget::Linux32 => format!("{package}.vst3/Contents/i386-linux/{package}.so"), format!("{package}.vst3/Contents/i386-linux/{package}.so")
CompilationTarget::Mac64 => format!("{package}.vst3/Contents/MacOS/{package}"), }
CompilationTarget::Windows64 => { CompilationTarget::Linux(Architecture::X86_64) => {
format!("{package}.vst3/Contents/x86_64-linux/{package}.so")
}
CompilationTarget::Linux(Architecture::AArch64) => {
format!("{package}.vst3/Contents/aarch64-linux/{package}.so")
}
CompilationTarget::MacOS(_) => format!("{package}.vst3/Contents/MacOS/{package}"),
CompilationTarget::Windows(Architecture::X86) => {
format!("{package}.vst3/Contents/x86-win/{package}.vst3")
}
CompilationTarget::Windows(Architecture::X86_64) => {
format!("{package}.vst3/Contents/x86_64-win/{package}.vst3") format!("{package}.vst3/Contents/x86_64-win/{package}.vst3")
} }
CompilationTarget::Windows32 => format!("{package}.vst3/Contents/x86-win/{package}.vst3"), CompilationTarget::Windows(Architecture::AArch64) => {
format!("{package}.vst3/Contents/arm_64-win/{package}.vst3")
}
} }
} }
@ -382,7 +408,7 @@ pub fn maybe_create_macos_bundle_metadata(
bundle_home: &Path, bundle_home: &Path,
target: CompilationTarget, target: CompilationTarget,
) -> Result<()> { ) -> Result<()> {
if target != CompilationTarget::Mac64 { if !matches!(target, CompilationTarget::MacOS(_)) {
return Ok(()); return Ok(());
} }