Skip to content

Commit cc42fb1

Browse files
authored
[native_toolchain_c] Use sysroot on Android (#180)
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.
1 parent 01d92b0 commit cc42fb1

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ class RunCBuilder {
9898
.first
9999
.uri;
100100

101+
Uri androidSysroot(ToolInstance compiler) =>
102+
compiler.uri.resolve('../sysroot/');
103+
101104
Future<void> run() async {
102105
final compiler_ = await compiler();
103106
final compilerTool = compiler_.tool;
@@ -127,14 +130,10 @@ class RunCBuilder {
127130
executable: compiler.uri,
128131
arguments: [
129132
if (target.os == OS.android) ...[
130-
// TODO(dacoharkes): How to solve linking issues?
131-
// Non-working fix: --sysroot=$NDKPATH/toolchains/llvm/prebuilt/linux-x86_64/sysroot.
132-
// The sysroot should be discovered automatically after NDK 22.
133-
// Workaround:
134-
if (dynamicLibrary != null) '-nostartfiles',
135133
'--target='
136134
'${androidNdkClangTargetFlags[target]!}'
137135
'${buildConfig.targetAndroidNdkApi!}',
136+
'--sysroot=${androidSysroot(compiler).toFilePath()}',
138137
],
139138
if (target.os == OS.macOS)
140139
'--target=${appleClangMacosTargetFlags[target]!}',

0 commit comments

Comments
 (0)