diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2022-09-01 19:56:38 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2022-09-15 10:40:15 +0530 |
commit | 7d242f69e94818a15598fefd368f81a8ca9f9c44 (patch) | |
tree | 813f06f350589fb142813a64ade348abc62efc03 | |
parent | ceb6534a6b5a4f8e9b67e8efd9ac5b5b5e16ff1a (diff) |
cerbero: Use Android NDK LD when building Cargo recipes
Also needs a patch to cargo-c to pass -soname instead of -Wl,-soname
when using the Android linker because ld.gold cannot handle the
spurious -Wl prefix.
Part-of: <https://gitlab.freedesktop.org/gstreamer/cerbero/-/merge_requests/915>
-rw-r--r-- | cerbero/build/build.py | 26 | ||||
-rw-r--r-- | recipes/build-tools/cargo-c.recipe | 3 | ||||
-rw-r--r-- | recipes/build-tools/cargo-c/0001-Fix-linking-with-Android-NDK-linker.patch | 27 |
3 files changed, 54 insertions, 2 deletions
diff --git a/cerbero/build/build.py b/cerbero/build/build.py index da0e0d08..e30bb56d 100644 --- a/cerbero/build/build.py +++ b/cerbero/build/build.py @@ -18,6 +18,7 @@ import os import re +import glob import copy import shutil import shlex @@ -1138,13 +1139,13 @@ class Cargo(Build, ModifyEnvBase): self.cargo = os.path.join(self.config.cargo_home, 'bin', 'cargo' + self.config._get_exe_suffix()) try: - target_triple = self.config.rust_triple(self.config.target_arch, + self.target_triple = self.config.rust_triple(self.config.target_arch, self.config.target_platform, self.using_msvc()) except FatalError as e: raise InvalidRecipeError(self.name, e.msg) self.cargo_args = [ '--verbose', '--offline', - '--target', target_triple, + '--target', self.target_triple, '--target-dir', self.cargo_dir, ] @@ -1156,6 +1157,27 @@ class Cargo(Build, ModifyEnvBase): os.makedirs(self.cargo_dir) else: os.makedirs(self.cargo_dir) + if self.config.target_platform == Platform.ANDROID: + dot_cargo = os.path.join(self.config_src_dir, '.cargo') + os.makedirs(dot_cargo, exist_ok=True) + linker = self.env['LD'] + link_args = [] + args = iter(shlex.split(self.env['LDFLAGS'])) + # We need to extract necessary linker flags from LDFLAGS which is + # passed to the compiler + for arg in args: + if arg.startswith('-L'): + link_args.append(arg) + elif arg == '-gcc-toolchain': + arg = next(args) + for l in glob.glob(f'{arg}/lib/gcc/*/*/libgcc.a'): + d = os.path.dirname(l) + link_args.append(f'-L{d}') + # Append so we don't overwrite cargo vendor settings + with open(os.path.join(dot_cargo, 'config.toml'), 'a') as f: + f.write(f'[target.{self.target_triple}]\n') + f.write(f'linker = "{linker}"\n') + f.write(f'rustflags = {link_args!r}\n') # No configure step with cargo async def compile(self): diff --git a/recipes/build-tools/cargo-c.recipe b/recipes/build-tools/cargo-c.recipe index 82770885..143a5e09 100644 --- a/recipes/build-tools/cargo-c.recipe +++ b/recipes/build-tools/cargo-c.recipe @@ -11,6 +11,9 @@ class Recipe(recipe.Recipe): # Need system openssl on Linux use_system_libs = True + # https://github.com/lu-zero/cargo-c/pull/277 + patches = [name + '/0001-Fix-linking-with-Android-NDK-linker.patch'] + deps = ['pkg-config'] # Need openssl on macOS. On Windows, a prebuilt openssl crate is downloaded. platform_deps = { diff --git a/recipes/build-tools/cargo-c/0001-Fix-linking-with-Android-NDK-linker.patch b/recipes/build-tools/cargo-c/0001-Fix-linking-with-Android-NDK-linker.patch new file mode 100644 index 00000000..38fbb7ed --- /dev/null +++ b/recipes/build-tools/cargo-c/0001-Fix-linking-with-Android-NDK-linker.patch @@ -0,0 +1,27 @@ +From 1f25fb1c4c69a845b01afe0e6619c2a10c890522 Mon Sep 17 00:00:00 2001 +From: Nirbheek Chauhan <nirbheek@centricular.com> +Date: Thu, 1 Sep 2022 21:33:29 +0530 +Subject: [PATCH] Fix linking with Android NDK linker + +Android ld.gold cannot handle -Wl, and it's incorrect anyway since all +the other linker arguments passed by cargo do not have a -Wl prefix. +--- + src/target.rs | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/target.rs b/src/target.rs +index 7b1c43e..03a0d4c 100644 +--- a/src/target.rs ++++ b/src/target.rs +@@ -70,7 +70,7 @@ impl Target { + let env = &self.env; + + if os == "android" { +- lines.push(format!("-Wl,-soname,lib{}.so", lib_name)); ++ lines.push(format!("-soname,lib{}.so", lib_name)); + } else if os == "linux" + || os == "freebsd" + || os == "dragonfly" +-- +2.37.1 + |