Skip to content

Commit

Permalink
[native_toolchain_c] Use sysroot on Android (#180)
Browse files Browse the repository at this point in the history
Addresses: #165 (comment)

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 #165 temporarily.
  • Loading branch information
dcharkes authored Nov 1, 2023
1 parent 01d92b0 commit cc42fb1
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ class RunCBuilder {
.first
.uri;

Uri androidSysroot(ToolInstance compiler) =>
compiler.uri.resolve('../sysroot/');

Future<void> run() async {
final compiler_ = await compiler();
final compilerTool = compiler_.tool;
Expand Down Expand Up @@ -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]!}',
Expand Down

0 comments on commit cc42fb1

Please sign in to comment.