-
Notifications
You must be signed in to change notification settings - Fork 27
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
Add linking for native_toolchain_c
and linux
#987
base: main
Are you sure you want to change the base?
Conversation
commit c24e422 Author: Moritz <mosum@google.com> Date: Tue Apr 16 10:46:50 2024 +0200 Unify `configFile` commit 53ab489 Author: Moritz <mosum@google.com> Date: Tue Apr 16 10:16:26 2024 +0200 Changes as per review commit 95a6479 Author: Moritz <mosum@google.com> Date: Mon Apr 15 16:48:49 2024 +0200 Copy over more files commit c33d5dd Author: Moritz <mosum@google.com> Date: Mon Apr 15 15:02:10 2024 +0200 Fix linking id check commit b88c152 Author: Moritz <mosum@google.com> Date: Fri Apr 12 15:55:56 2024 +0200 Fix dep commit 3d8ed4a Author: Moritz <mosum@google.com> Date: Fri Apr 12 15:17:52 2024 +0200 Fix import commit 3955ea9 Author: Moritz <mosum@google.com> Date: Fri Apr 12 15:09:59 2024 +0200 Export ResourceIdentifiers
commit 725bdd7 Author: Moritz <mosum@google.com> Date: Tue Apr 16 15:58:21 2024 +0200 Make resources nullable commit c24e422 Author: Moritz <mosum@google.com> Date: Tue Apr 16 10:46:50 2024 +0200 Unify `configFile` commit 53ab489 Author: Moritz <mosum@google.com> Date: Tue Apr 16 10:16:26 2024 +0200 Changes as per review commit 95a6479 Author: Moritz <mosum@google.com> Date: Mon Apr 15 16:48:49 2024 +0200 Copy over more files commit c33d5dd Author: Moritz <mosum@google.com> Date: Mon Apr 15 15:02:10 2024 +0200 Fix linking id check commit b88c152 Author: Moritz <mosum@google.com> Date: Fri Apr 12 15:55:56 2024 +0200 Fix dep commit 3d8ed4a Author: Moritz <mosum@google.com> Date: Fri Apr 12 15:17:52 2024 +0200 Fix import commit 3955ea9 Author: Moritz <mosum@google.com> Date: Fri Apr 12 15:09:59 2024 +0200 Export ResourceIdentifiers
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.
Add linking for native_toolchain_c and linux
[native_toolchain_c] Linker support for Linux
@@ -19,7 +17,10 @@ void main(List<String> arguments) async { | |||
'src/native_add.c', | |||
'src/native_multiply.c', | |||
], | |||
dartBuildFiles: ['hook/build.dart'], | |||
dartBuildFiles: [ | |||
'hook/build.dart', |
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.
Why do we want to rerun the build hook if the link hook changed?
os: config.targetOS, | ||
), | ||
linkInPackage: packageName, | ||
NativeCodeAsset placeholderAsset(HookConfig config) { |
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 should not be needed anymore.
Am I correct in thinking that:
- The unit tests for the package here can land without SDK changes.
- Then we land the SDK CL in which this test_data is used in dartdev unit tests and we actually add a new asset in link.
- Then we land another PR in the dart-lang/native that enables the examples.
If I am not mistaken, we should not need to land the placeholder workaround.
/// Get the linker flags for the specified [linker]. | ||
/// | ||
/// Throws if the [linker] is not supported. | ||
Iterable<String> preflags(Tool linker) => |
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.
Document pre-what.
/// Get the linker flags for the specified [linker]. | ||
/// | ||
/// Throws if the [linker] is not supported. | ||
Iterable<String> flags(Tool linker) => _toLinkerSyntax(linker, [ |
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 postFlags? And post-what?
linkerTool == clang || | ||
linkerTool == gcc || | ||
linkerTool == gnuLinker) { | ||
await runClangLike(compiler: linker_); |
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.
compiler: linker_
looks odd, maybe rename the param to tool
so it's tool: linker_
.
tool = gnuLinker; | ||
|
||
//TODO: Make this logic more correct | ||
if (filePath.endsWith(os.executableFileName('clang'))) { |
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.
Why do we recognize a linker with a compiler executable name?
@@ -0,0 +1,6 @@ | |||
#include <stdio.h> |
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.
Don't commit binary files (test.a, test1.o, test2.o).
Add git ignores.
sources: [ | ||
'test/clinker/testfiles/linker/test1.o', | ||
'test/clinker/testfiles/linker/test2.o', | ||
].map((e) => packageUri.resolve(e).toFilePath()).toList()) |
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.
].map((e) => packageUri.resolve(e).toFilePath()).toList(),)
for better formatting
class LinkerRecognizer implements ToolResolver { | ||
final Uri uri; | ||
final OS os; |
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 field is not used, resolve
has a variable os
that shadows it.
@@ -1,7 +1,7 @@ | |||
name: native_toolchain_c | |||
description: >- | |||
A library to invoke the native C compiler installed on the host machine. | |||
version: 0.4.1 | |||
version: 0.4.2-wip |
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 can't leave comments on binary files.)
Don't commit test.so, add a git ignore.
//TODO: expose name from `placeholderAsset` | ||
assetName: 'src/${packageName}_bindings.dart', | ||
linkerOptions: LinkerOptions.treeshake( | ||
symbols: config.resources |
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.
🤯 😄 🚀
Requires #827 to be merged.
Extend API by providing a
CLinker
, supporting development only on linux for now. Other platforms to be added in future PRs.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.