From cc42fb15f4da9e2bae7d24d6415acba702adb7b5 Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Wed, 1 Nov 2023 17:50:39 +0100 Subject: [PATCH] [native_toolchain_c] Use sysroot on Android (#180) Addresses: https://github.com/dart-lang/native/pull/165#discussion_r1375048853 This is in line with what CMake does, so it's probably a more reasonable thing to do than `-nostartfiles`. The documentation says the sysroot should be auto-discovered on NDKs newer than 22, but it doesn't seem to break the newer versions, so maybe lets just keep the logic consistent for various NDK versions. We probably need a workaround for https://github.com/dart-lang/native/pull/165 temporarily. --- .../lib/src/cbuilder/run_cbuilder.dart | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart b/pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart index b5ccd6c16..1fa571865 100644 --- a/pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart +++ b/pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart @@ -98,6 +98,9 @@ class RunCBuilder { .first .uri; + Uri androidSysroot(ToolInstance compiler) => + compiler.uri.resolve('../sysroot/'); + Future run() async { final compiler_ = await compiler(); final compilerTool = compiler_.tool; @@ -127,14 +130,10 @@ class RunCBuilder { executable: compiler.uri, arguments: [ if (target.os == OS.android) ...[ - // TODO(dacoharkes): How to solve linking issues? - // Non-working fix: --sysroot=$NDKPATH/toolchains/llvm/prebuilt/linux-x86_64/sysroot. - // The sysroot should be discovered automatically after NDK 22. - // Workaround: - if (dynamicLibrary != null) '-nostartfiles', '--target=' '${androidNdkClangTargetFlags[target]!}' '${buildConfig.targetAndroidNdkApi!}', + '--sysroot=${androidSysroot(compiler).toFilePath()}', ], if (target.os == OS.macOS) '--target=${appleClangMacosTargetFlags[target]!}',