Skip to content
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b789ef5
[native_toolchain_c] Fix clang compiler search + tools for Swiftly
nikeokoronkwo Nov 18, 2025
a367d17
Resolved tool_resolver.dart unnecessary import
nikeokoronkwo Nov 19, 2025
0ff54c4
Added CHANGELOG.md update and version bump
nikeokoronkwo Nov 19, 2025
ec4e5d7
updated lookup for apple linker
nikeokoronkwo Dec 15, 2025
a1a38a2
Merge branch 'main' into fix/swiftly
nikeokoronkwo Dec 15, 2025
9cf4dac
updated pubspec version for native_toolchain_c
nikeokoronkwo Dec 15, 2025
836991b
Merge branch 'main' into fix/swiftly
nikeokoronkwo Dec 22, 2025
7a25e6c
Merge branch 'main' into fix/swiftly
nikeokoronkwo Jan 10, 2026
9980d95
Updated CI for swiftly
nikeokoronkwo Jan 10, 2026
294624b
merge main branch
nikeokoronkwo Mar 15, 2026
c089af9
Squashed commit of the following:
nikeokoronkwo Mar 15, 2026
34c5e98
Merge branch 'main' into fix/swiftly
nikeokoronkwo Mar 15, 2026
72c450d
Updated Github PATH for Swiftly in CI
nikeokoronkwo Mar 15, 2026
2e88d0e
Merge branch 'fix/swiftly' of https://github.com/nikeokoronkwo/native…
nikeokoronkwo Mar 15, 2026
bafbfd9
updated swiftly job with deps
nikeokoronkwo Mar 19, 2026
573d96f
Merge branch 'main' into fix/swiftly
nikeokoronkwo Mar 19, 2026
f7d636a
Fixed apple `ld` test by testing against stderr rather than stdout
nikeokoronkwo Mar 19, 2026
31a1b15
Add priority for builtin `ar` for apple
nikeokoronkwo Mar 19, 2026
fd67c32
analyzing issues fixed
nikeokoronkwo Mar 19, 2026
d60f514
Replaced AbsoluteToolResolver with PathFilter for absolute path
nikeokoronkwo Mar 20, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/native_toolchain_c.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,44 @@ on:
- cron: "0 0 * * 0" # weekly

jobs:
dart-swiftly-clang:
strategy:
matrix:
os: [ubuntu]
sdk: [dev, stable]
package: [native_toolchain_c]

runs-on: ${{ matrix.os }}-latest

defaults:
run:
working-directory: pkgs/${{ matrix.package }}

steps:
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8

- uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c
with:
sdk: ${{ matrix.sdk }}

- name: Install swiftly dependencies
run: sudo apt-get update && sudo apt-get -y install libcurl4-openssl-dev

- name: Install swiftly
run: |
curl -O https://download.swift.org/swiftly/linux/swiftly-$(uname -m).tar.gz
tar zxf swiftly-$(uname -m).tar.gz
./swiftly init --quiet-shell-followup -y
echo "$SWIFTLY_BIN_DIR" >> $GITHUB_PATH

- name: Install the latest Swift toolchain
run: swiftly install latest

- run: echo "$SWIFTLY_BIN_DIR" >> $GITHUB_PATH

- run: clang --version

- run: dart test
dart-sdk-clang:
strategy:
matrix:
Expand Down
3 changes: 2 additions & 1 deletion pkgs/hooks_runner/lib/src/build_runner/build_planner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ class PackageGraph {
/// compilation. This enum holds static information about these hooks.
enum Hook {
link('link'),
build('build');
build('build')
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there was some weird stuff going on with some dev versions of Dart and the formatter. I think this should be fixed now if you take one of the newest versions of Dart.

;

final String _scriptName;

Expand Down
5 changes: 5 additions & 0 deletions pkgs/native_toolchain_c/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.17.7

- Fixed resolution of C compiler and tools on macOS when `swiftly` is installed.
- Broaden compiler tool discovery on macOS.

## 0.17.6

- On Android, use the NDK's `libc++.a` linker script when `cppLinkStdLib` is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// 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 '../tool/tool.dart';
import '../tool/tool_resolver.dart';

Expand All @@ -13,7 +15,8 @@ final Tool appleClang = Tool(
defaultResolver: CliVersionResolver(
wrappedResolver: CliFilter(
cliArguments: ['--version'],
keepIf: ({required String stdout}) => stdout.contains('Apple clang'),
keepIf: ({required String stdout, required String stderr}) =>
stdout.contains('Apple clang'),
wrappedResolver: PathToolResolver(
toolName: 'Apple Clang',
executableName: 'clang',
Expand All @@ -31,6 +34,14 @@ final Tool appleAr = Tool(
wrappedResolver: appleClang.defaultResolver!,
relativePath: Uri.file('ar'),
),
AbsoluteToolResolver(
toolName: 'Apple archiver',
wrappedResolver: PathToolResolver(
toolName: 'Apple archiver',
executableName: OS.current.executableFileName('ar'),
),
absolutePath: Uri.file('/usr/bin/ar'),
),
]),
);

Expand All @@ -43,6 +54,15 @@ final Tool appleLd = Tool(
wrappedResolver: appleClang.defaultResolver!,
relativePath: Uri.file('ld'),
),
CliFilter(
wrappedResolver: PathToolResolver(
toolName: 'Apple linker',
executableName: OS.current.executableFileName('ld'),
),
cliArguments: ['-v'],
keepIf: ({required String stdout, required String stderr}) =>
stdout.contains('Apple TAPI') || stderr.contains('Apple TAPI'),
),
]),
);

Expand Down
3 changes: 2 additions & 1 deletion pkgs/native_toolchain_c/lib/src/native_toolchain/clang.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ final Tool clang = Tool(
defaultResolver: CliVersionResolver(
wrappedResolver: CliFilter(
cliArguments: ['--version'],
keepIf: ({required String stdout}) => !stdout.contains('Apple clang'),
keepIf: ({required String stdout, required String stderr}) =>
!stdout.contains('Apple clang'),
wrappedResolver: ToolResolvers([
PathToolResolver(
toolName: 'Clang',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CompilerRecognizer implements ToolResolver {
if (filePath.contains('-gcc')) {
tool = gcc;
} else if (filePath.endsWith(os.executableFileName('clang'))) {
final stdout = await CliFilter.executeCli(
final (:stdout, :stderr) = await CliFilter.executeCli(
uri,
arguments: ['--version'],
logger: logger,
Expand Down
50 changes: 44 additions & 6 deletions pkgs/native_toolchain_c/lib/src/tool/tool_resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ class PathToolResolver extends ToolResolver {
if (process.exitCode == 0) {
final file = File(LineSplitter.split(process.stdout).first);
final uri = File(await file.resolveSymbolicLinks()).uri;
if (uri.pathSegments.last case 'llvm' || 'lld') {
if (uri.pathSegments.last case 'llvm' || 'lld' || 'swiftly') {
// https://github.com/dart-lang/native/issues/136
// https://github.com/dart-lang/native/issues/2792
Comment thread
nikeokoronkwo marked this conversation as resolved.
return file.uri;
}
return uri;
Expand Down Expand Up @@ -373,10 +374,47 @@ class RelativeToolResolver implements ToolResolver {
}
}

class AbsoluteToolResolver implements ToolResolver {
final String toolName;
final ToolResolver wrappedResolver;
final Uri absolutePath;

AbsoluteToolResolver({
required this.toolName,
required this.wrappedResolver,
required this.absolutePath,
});

@override
Future<List<ToolInstance>> resolve(ToolResolvingContext context) async {
final logger = context.logger;
final otherToolInstances = await wrappedResolver.resolve(context);

logger?.finer(
'Checking if one of $toolName resolved as $otherToolInstances is '
'at the path $absolutePath',
);

final result = otherToolInstances
.where((instance) => instance.uri == absolutePath)
Comment thread
nikeokoronkwo marked this conversation as resolved.
Outdated
.toList();

if (result.isNotEmpty) {
logger?.fine('Found $result.');
} else {
logger?.finer(
'Found no $toolName with the specified absolute path '
'$otherToolInstances.',
);
}
return result;
}
}

class CliFilter implements ToolResolver {
final ToolResolver wrappedResolver;
final List<String> cliArguments;
final bool Function({required String stdout}) keepIf;
final bool Function({required String stdout, required String stderr}) keepIf;

CliFilter({
required this.wrappedResolver,
Expand All @@ -399,12 +437,12 @@ class CliFilter implements ToolResolver {
}) async {
if (toolInstance.version != null) return toolInstance;
logger?.finer('Checking if $toolInstance satisfies CLI filter.');
final stdout = await executeCli(
final (:stdout, :stderr) = await executeCli(
toolInstance.uri,
arguments: cliArguments,
logger: logger,
);
final doKeep = keepIf(stdout: stdout);
final doKeep = keepIf(stdout: stdout, stderr: stderr);
if (doKeep) {
logger?.fine('$toolInstance satisfies CLI filter.');
return toolInstance;
Expand All @@ -413,7 +451,7 @@ class CliFilter implements ToolResolver {
return null;
}

static Future<String> executeCli(
static Future<({String stdout, String stderr})> executeCli(
Uri executable, {
required List<String> arguments,
int expectedExitCode = 0,
Expand All @@ -426,6 +464,6 @@ class CliFilter implements ToolResolver {
);
final exitCode = process.exitCode;
assert(exitCode == expectedExitCode);
return process.stdout;
return (stdout: process.stdout, stderr: process.stderr);
}
}
2 changes: 1 addition & 1 deletion pkgs/native_toolchain_c/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: native_toolchain_c
description: >-
A library to invoke the native C compiler installed on the host machine.
version: 0.17.6
version: 0.17.7
repository: https://github.com/dart-lang/native/tree/main/pkgs/native_toolchain_c

topics:
Expand Down
Loading