-
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? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f4846fa
[native_toolchain_c] Add linking for Android
goderbauer c0987f5
fix -u syntax
goderbauer 7a18291
speculative windows fix
goderbauer c4c8cc4
test on more android API levels
goderbauer 330b8db
fix naming
goderbauer 1ec9e5a
reviews
goderbauer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
pkgs/native_toolchain_c/test/clinker/objects_cross_android_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:code_assets/code_assets.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import '../helpers.dart'; | ||
import 'objects_helper.dart'; | ||
|
||
void main() { | ||
final architectures = [ | ||
Architecture.arm, | ||
Architecture.arm64, | ||
Architecture.ia32, | ||
Architecture.x64, | ||
Architecture.riscv64, | ||
]; | ||
|
||
const targetOS = OS.android; | ||
|
||
for (final apiLevel in [ | ||
flutterAndroidNdkVersionLowestSupported, | ||
flutterAndroidNdkVersionHighestSupported, | ||
]) { | ||
group('Android API$apiLevel', () { | ||
runObjectsTests(targetOS, architectures, androidTargetNdkApi: apiLevel); | ||
}); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
pkgs/native_toolchain_c/test/clinker/objects_cross_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
//TODO(mosuem): Enable for windows and mac. | ||
// See https://github.com/dart-lang/native/issues/1376. | ||
@TestOn('linux') | ||
goderbauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
library; | ||
|
||
import 'dart:io'; | ||
|
||
import 'package:code_assets/code_assets.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import 'objects_helper.dart'; | ||
|
||
void main() { | ||
if (!Platform.isLinux) { | ||
// Avoid needing status files on Dart SDK CI. | ||
return; | ||
} | ||
|
||
final architectures = [ | ||
Architecture.arm, | ||
Architecture.arm64, | ||
Architecture.ia32, | ||
Architecture.x64, | ||
Architecture.riscv64, | ||
]..remove(Architecture.current); | ||
|
||
runObjectsTests(OS.current, architectures); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:io'; | ||
|
||
import 'package:code_assets/code_assets.dart'; | ||
import 'package:hooks/hooks.dart'; | ||
import 'package:native_toolchain_c/native_toolchain_c.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import '../helpers.dart'; | ||
import 'build_testfiles.dart'; | ||
|
||
void runObjectsTests( | ||
OS targetOS, | ||
List<Architecture> architectures, { | ||
int? androidTargetNdkApi, // Must be specified iff targetOS is OS.android. | ||
}) { | ||
assert((targetOS != OS.android) == (androidTargetNdkApi == null)); | ||
const name = 'mylibname'; | ||
|
||
for (final architecture in architectures) { | ||
test('link two objects for $architecture', () async { | ||
final tempUri = await tempDirForTest(); | ||
final tempUri2 = await tempDirForTest(); | ||
|
||
final uri = await buildTestArchive( | ||
tempUri, | ||
tempUri2, | ||
targetOS, | ||
architecture, | ||
androidTargetNdkApi: androidTargetNdkApi, | ||
); | ||
|
||
final linkInputBuilder = LinkInputBuilder() | ||
..setupShared( | ||
packageName: 'testpackage', | ||
packageRoot: tempUri, | ||
outputFile: tempUri.resolve('output.json'), | ||
outputDirectoryShared: tempUri2, | ||
) | ||
..setupLink(assets: [], recordedUsesFile: null) | ||
..addExtension( | ||
CodeAssetExtension( | ||
targetOS: targetOS, | ||
targetArchitecture: architecture, | ||
linkModePreference: LinkModePreference.dynamic, | ||
cCompiler: cCompiler, | ||
android: androidTargetNdkApi != null | ||
? AndroidCodeConfig(targetNdkApi: androidTargetNdkApi) | ||
: null, | ||
), | ||
); | ||
|
||
final linkInput = linkInputBuilder.build(); | ||
final linkOutput = LinkOutputBuilder(); | ||
|
||
printOnFailure(linkInput.config.code.cCompiler.toString()); | ||
printOnFailure(Platform.environment.keys.toList().toString()); | ||
await CLinker.library( | ||
name: name, | ||
assetName: '', | ||
linkerOptions: LinkerOptions.manual(gcSections: false), | ||
sources: [uri.toFilePath()], | ||
).run(input: linkInput, output: linkOutput, logger: logger); | ||
|
||
final codeAssets = LinkOutput(linkOutput.json).assets.code; | ||
expect(codeAssets, hasLength(1)); | ||
final asset = codeAssets.first; | ||
expect(asset, isA<CodeAsset>()); | ||
expect( | ||
await nmReadSymbols(asset), | ||
stringContainsInOrder(['my_func', 'my_other_func']), | ||
); | ||
}); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 was assuming that we only check for combinations that should work, but currently don't because they are still WIP - similarly to how cbuilder.dart is also not checking that you can only target linux from linux.