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

ndk-build: Use LLVM binutils when GNU binutils are removed (r23+) #137

Merged
merged 2 commits into from
Apr 15, 2021
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
16 changes: 11 additions & 5 deletions ndk-build/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,30 @@ pub enum NdkError {
environment variable."
)]
NdkNotFound,
#[error("Path {0:?} doesn't exist.")]
#[error("GNU toolchain binary `{gnu_bin}` nor LLVM toolchain binary `{llvm_bin}` found in `{toolchain_path:?}`.")]
ToolchainBinaryNotFound {
toolchain_path: PathBuf,
gnu_bin: String,
llvm_bin: String,
},
#[error("Path `{0:?}` doesn't exist.")]
PathNotFound(PathBuf),
#[error("Command {0} not found.")]
#[error("Command `{0}` not found.")]
CmdNotFound(String),
#[error("Android SDK has no build tools.")]
BuildToolsNotFound,
#[error("Android SDK has no platforms installed.")]
NoPlatformFound,
#[error("Platform {0} is not installed.")]
#[error("Platform `{0}` is not installed.")]
PlatformNotFound(u32),
#[error("Target is not supported.")]
UnsupportedTarget,
#[error("Host {0} is not supported.")]
#[error("Host `{0}` is not supported.")]
UnsupportedHost(String),
#[error(transparent)]
Io(#[from] IoError),
#[error("Invalid semver")]
InvalidSemver,
#[error("Command '{}' had a non-zero exit code.", format!("{:?}", .0).replace('"', ""))]
#[error("Command `{}` had a non-zero exit code.", format!("{:?}", .0).replace('"', ""))]
CmdFailed(Command),
}
33 changes: 23 additions & 10 deletions ndk-build/src/ndk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,22 +196,35 @@ impl Ndk {
Ok((clang, clang_pp))
}

pub fn toolchain_bin(&self, bin: &str, target: Target) -> Result<PathBuf, NdkError> {
pub fn toolchain_bin(&self, name: &str, target: Target) -> Result<PathBuf, NdkError> {
#[cfg(target_os = "windows")]
let ext = ".exe";
#[cfg(not(target_os = "windows"))]
let ext = "";

let bin = self.toolchain_dir()?.join("bin").join(format!(
"{}-{}{}",
target.ndk_triple(),
bin,
ext
));
if !bin.exists() {
return Err(NdkError::PathNotFound(bin));
let toolchain_path = self.toolchain_dir()?.join("bin");

// Since r21 (https://github.com/android/ndk/wiki/Changelog-r21) LLVM binutils are included _for testing_;
// Since r22 (https://github.com/android/ndk/wiki/Changelog-r22) GNU binutils are deprecated in favour of LLVM's;
// Since r23 (https://github.com/android/ndk/wiki/Changelog-r23) GNU binutils have been removed.
// To maintain stability with the current ndk-build crate release, prefer GNU binutils for
// as long as it is provided by the NDK instead of trying to use llvm-* from r21 onwards.
let gnu_bin = format!("{}-{}{}", target.ndk_triple(), name, ext);
let gnu_path = toolchain_path.join(&gnu_bin);
if gnu_path.exists() {
Ok(gnu_path)
} else {
let llvm_bin = format!("llvm-{}{}", name, ext);
let llvm_path = toolchain_path.join(&llvm_bin);
llvm_path
.exists()
.then(|| llvm_path)
.ok_or_else(|| NdkError::ToolchainBinaryNotFound {
toolchain_path,
gnu_bin,
llvm_bin,
})
}
Ok(bin)
}

pub fn android_dir(&self) -> Result<PathBuf, NdkError> {
Expand Down