Skip to content

Commit 7324caf

Browse files
authored
[native_toolchain_c] Don't require lld on PATH for MacOS -> Linux (#3044)
1 parent 7eab15e commit 7324caf

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

pkgs/native_toolchain_c/lib/src/native_toolchain/clang.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ final Tool lld = Tool(
7878
wrappedResolver: clang.defaultResolver!,
7979
relativePath: Uri.file(OS.current.executableFileName('ld')),
8080
),
81+
InstallLocationResolver(
82+
toolName: 'LLD',
83+
paths: [
84+
'/opt/homebrew/opt/lld/bin/ld.lld',
85+
'/opt/homebrew/bin/ld.lld',
86+
'/usr/local/opt/lld/bin/ld.lld',
87+
'/usr/local/bin/ld.lld',
88+
],
89+
),
8190
PathToolResolver(
8291
toolName: 'LLD',
8392
executableName: OS.current.executableFileName('ld.lld'),

pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_macos_host_test.dart

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,35 @@ import 'dart:io';
1010

1111
import 'package:code_assets/code_assets.dart';
1212
import 'package:hooks/hooks.dart';
13+
import 'package:logging/logging.dart';
1314
import 'package:native_toolchain_c/native_toolchain_c.dart';
1415
import 'package:native_toolchain_c/src/native_toolchain/apple_clang.dart';
16+
import 'package:native_toolchain_c/src/native_toolchain/clang.dart';
1517
import 'package:native_toolchain_c/src/tool/tool_resolver.dart';
1618
import 'package:native_toolchain_c/src/utils/run_process.dart';
1719
import 'package:test/test.dart';
1820

1921
import '../helpers.dart';
2022

21-
void main() {
23+
void main() async {
2224
if (!Platform.isMacOS) {
2325
// Avoid needing status files on Dart SDK CI.
2426
return;
2527
}
2628

27-
const targets = [
29+
final context = ToolResolvingContext(logger: Logger.detached('main'));
30+
final lldInstances = await lld.defaultResolver!.resolve(context);
31+
final lldAvailable = lldInstances.isNotEmpty;
32+
final lldPath = lldAvailable ? lldInstances.first.uri.toFilePath() : 'ld.lld';
33+
34+
if (!lldAvailable) {
35+
stderr.writeln(
36+
'ld.lld not found. Linux cross-compilation tests will fail.',
37+
);
38+
stderr.writeln("Install with 'brew install lld' on macOS.");
39+
}
40+
41+
final targets = [
2842
(OS.macOS, Architecture.arm64),
2943
(OS.macOS, Architecture.x64),
3044
(OS.linux, Architecture.arm),
@@ -135,7 +149,7 @@ void main() {
135149
// Only homebrew lld can link for linux, and we don't have a
136150
// sysroot so we can't use stdlibs / C-runtime files.
137151
if (os == OS.linux) ...[
138-
'--ld-path=ld.lld',
152+
'--ld-path=$lldPath',
139153
'-nostartfiles',
140154
'-nostdlib',
141155
],

0 commit comments

Comments
 (0)