-
Notifications
You must be signed in to change notification settings - Fork 69
[native_toolchain_c] Add linking for Android #2347
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
base: main
Are you sure you want to change the base?
Conversation
PR HealthChangelog Entry ✔️
Changes to files need to be accounted for in their respective changelogs. API leaks ✔️The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.
License Headers ✔️
All source files should start with a license header. Unrelated files missing license headers
|
Package publishing
Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation. |
84b1b48
to
ca6c274
Compare
Hm, it's not clear to me why the bot wants the version to be bumped to 0.17.0 |
You should be able to repro it with the |
|
||
//TODO(mosuem): Enable for windows and mac. | ||
// See https://github.com/dart-lang/native/issues/1376. | ||
@TestOn('linux') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be removed now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is still correct. This test checks whether we can link on the current host OS for different architectures running the same (host) OS. For that, we still only support Linux for now. The new functionality (cross linking for Android from Linux/Windows/MaxOS) I added the new *_cross_android_test.dart tests, which do not have a @TestOn
limitation.
(Technically, this test doesn't belong to this change as it is unrelated to the Android work and testing existing functionality. I just saw this as a whole in the existing testing story and added it for completeness - and to make sure that my Android work doesn't break this scenario).
Thank you! I am pretty sure that the tool is wrong here based on what it has identified as a breaking change in a local run:
The Edit: It looks like the |
ca6c274
to
330b8db
Compare
It does indeed check out the package from pub. See the discussion here: bmw-tech/dart_apitool#216 The packages on pub.dev should work, they are used in the flutter template and flutter integration tests. It's fishy that it fails. (Yeah indeed just apply the label for now.) |
@@ -53,10 +53,12 @@ class CLinker extends CTool implements Linker { | |||
required LinkOutputBuilder output, | |||
required Logger? logger, | |||
}) async { | |||
if (OS.current != OS.linux || input.config.code.targetOS != OS.linux) { | |||
const supportedTargetOSs = [OS.linux, OS.android]; | |||
if (!supportedTargetOSs.contains(input.config.code.targetOS)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This no longer checks if the hostOS is Linux if the targetOS is Linux.
@@ -0,0 +1,78 @@ | |||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new file 2025
@@ -0,0 +1,30 @@ | |||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that users need to have clang or similar installed? Linux will have ld
preinstalled, but not clang.
@@ -51,7 +51,7 @@ class LinkerOptions { | |||
}) : _linkerFlags = <String>[ | |||
...flags ?? [], | |||
'--strip-debug', | |||
if (symbols != null) ...symbols.expand((e) => ['-u', e]), | |||
if (symbols != null) ...symbols.expand((e) => ['-u,$e']), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (symbols != null) ...symbols.expand((e) => ['-u,$e']), | |
if (symbols != null) ...symbols.map((e) => '-u,$e'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(in case you want to go with interpolation instead of expand
)
Architecture.riscv64: 'elf64-littleriscv', | ||
}; | ||
|
||
Future<void> expectMachineArchitecture(Uri libUri, Architecture target) async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use some documentation
/// From https://docs.flutter.dev/reference/supported-platforms. | ||
const flutterAndroidNdkVersionHighestSupported = 34; | ||
|
||
const objdumpFileFormat = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also could use some documentation- where are the strings taken from?
final toolInstance_ = linkerOptions != null | ||
? await linker() | ||
: await compiler(); | ||
final toolInstance_ = await compiler(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we now delete linker
?
Towards #1376
This enables linking for Android on Windows, Linux, and MacOS hosts.
With this PR the linker is no longer invoked directly. Instead, it is invoked via the compiler driver (clang, etc.), which has the advantage that we don't have to hand-translate the arguments to the format the linker expects them to be. The compiler driver is doing that for us and we can mostly reuse the compiler driver invocation.
Contribution guidelines:
dart format
.Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.