diff options
author | L. E. Segovia <amy@centricular.com> | 2023-08-23 02:51:53 +0000 |
---|---|---|
committer | L. E. Segovia <amy@centricular.com> | 2023-11-21 19:19:47 -0300 |
commit | df6a972073a08dc004f8391532a0e572f1b616fa (patch) | |
tree | f12ef7f6cfabb7804fc66c170782fdf33a0764fd | |
parent | cce63e831e1e3e793f973046ba136ac11a199f5c (diff) |
gst-plugins-rs: Complete the NDK migration to fix linking against Rust
From !915 and !1191, the following bits were missing:
- Autotools expects the raw linker to perform detection for version
scripting. If that parameter isn't detected in the `--help`, shared
libraries are disabled (breaks libpng).
- Cargo, conversely, expects implicitly the clang executable itself
because of a new dependency on libunwind starting with 1.68
To appease both, I pass the corresponding linkers separately, then
massage the flags into link-args entries in the TOML's rustflags entry.
Part-of: <https://gitlab.freedesktop.org/gstreamer/cerbero/-/merge_requests/1255>
-rw-r--r-- | cerbero/build/build.py | 14 | ||||
-rw-r--r-- | config/android.config | 13 |
2 files changed, 15 insertions, 12 deletions
diff --git a/cerbero/build/build.py b/cerbero/build/build.py index 47cdb3f9..06b1e474 100644 --- a/cerbero/build/build.py +++ b/cerbero/build/build.py @@ -1277,19 +1277,15 @@ class Cargo(Build, ModifyEnvBase): self.append_config_toml(s) if self.config.target_platform == Platform.ANDROID: - linker = self.env['LD'] + # Use the compiler's forwarding + # See https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md#linkers + linker = self.get_env('RUSTC_LINKER') link_args = [] - args = iter(shlex.split(self.env['LDFLAGS'])) + args = iter(shlex.split(self.get_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}') + link_args += ['-C', f"link-args={arg}"] s = f'[target.{self.target_triple}]\n' \ f'linker = "{linker}"\n' \ f'rustflags = {link_args!r}\n' diff --git a/config/android.config b/config/android.config index 5b24585f..bdbc7dbb 100644 --- a/config/android.config +++ b/config/android.config @@ -104,6 +104,9 @@ env['CFLAGS'] = '' env['CXXFLAGS'] = '' env['OBJCFLAGS'] = '' +# Make sure user's env doesn't mess up with our build. +env.pop('RUSTFLAGS', None) + # Android NDK path env['ANDROID_NDK_HOME'] = toolchain_prefix @@ -152,7 +155,8 @@ if not target_arch in [Architecture.ARM64, Architecture.X86_64]: # nocopyreloc causes broken linking on arm64 ldflags += ' -Wl,-z,nocopyreloc ' -ldflags += f' -L{sysroot}/usr/lib/{host}/{v} ' +# Initialize both the linker and the sysroot +ldflags += f' -L{sysroot}/usr/lib/{host}/{v} -Wl,--sysroot={sysroot}' ldvariant = 'lld' ldflags += f' -fuse-ld={ldvariant} ' @@ -171,8 +175,11 @@ def llvm_cmd(command): env['CC']= ccache + llvm_cmd('clang') + f' -target {llvm_triple}' + f' --sysroot {sysroot}' env['CC_FOR_BUILD']= ccache + llvm_cmd('clang') env['CXX']= ccache + llvm_cmd('clang++') + f' -target {llvm_triple}' + f' --sysroot {sysroot}' -# linker should be invoked through the clang/++ frontend -env['LD']= '' +# linker is needed for Autotools +env['LD']= llvm_cmd(f'ld.lld') +# Supply the linker separately to pick up the dependency on -lunwind +# See https://blog.rust-lang.org/2023/01/09/android-ndk-update-r25.html +env['RUSTC_LINKER']= llvm_cmd(f'{llvm_triple}-clang') env['CPP']= llvm_cmd('clang') + ' -E' env['RANLIB']= llvm_cmd('llvm-ranlib') env['AR']= llvm_cmd('llvm-ar') |