diff --git a/pkgs/native_toolchain_c/lib/src/native_toolchain/clang.dart b/pkgs/native_toolchain_c/lib/src/native_toolchain/clang.dart index dd093a93bb..41c47f28f1 100644 --- a/pkgs/native_toolchain_c/lib/src/native_toolchain/clang.dart +++ b/pkgs/native_toolchain_c/lib/src/native_toolchain/clang.dart @@ -78,6 +78,15 @@ final Tool lld = Tool( wrappedResolver: clang.defaultResolver!, relativePath: Uri.file(OS.current.executableFileName('ld')), ), + InstallLocationResolver( + toolName: 'LLD', + paths: [ + '/opt/homebrew/opt/lld/bin/ld.lld', + '/opt/homebrew/bin/ld.lld', + '/usr/local/opt/lld/bin/ld.lld', + '/usr/local/bin/ld.lld', + ], + ), PathToolResolver( toolName: 'LLD', executableName: OS.current.executableFileName('ld.lld'), diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_macos_host_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_macos_host_test.dart index b4e7d05f6d..ac5b4029d5 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_macos_host_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_macos_host_test.dart @@ -10,21 +10,35 @@ import 'dart:io'; import 'package:code_assets/code_assets.dart'; import 'package:hooks/hooks.dart'; +import 'package:logging/logging.dart'; import 'package:native_toolchain_c/native_toolchain_c.dart'; import 'package:native_toolchain_c/src/native_toolchain/apple_clang.dart'; +import 'package:native_toolchain_c/src/native_toolchain/clang.dart'; import 'package:native_toolchain_c/src/tool/tool_resolver.dart'; import 'package:native_toolchain_c/src/utils/run_process.dart'; import 'package:test/test.dart'; import '../helpers.dart'; -void main() { +void main() async { if (!Platform.isMacOS) { // Avoid needing status files on Dart SDK CI. return; } - const targets = [ + final context = ToolResolvingContext(logger: Logger.detached('main')); + final lldInstances = await lld.defaultResolver!.resolve(context); + final lldAvailable = lldInstances.isNotEmpty; + final lldPath = lldAvailable ? lldInstances.first.uri.toFilePath() : 'ld.lld'; + + if (!lldAvailable) { + stderr.writeln( + 'ld.lld not found. Linux cross-compilation tests will fail.', + ); + stderr.writeln("Install with 'brew install lld' on macOS."); + } + + final targets = [ (OS.macOS, Architecture.arm64), (OS.macOS, Architecture.x64), (OS.linux, Architecture.arm), @@ -135,7 +149,7 @@ void main() { // Only homebrew lld can link for linux, and we don't have a // sysroot so we can't use stdlibs / C-runtime files. if (os == OS.linux) ...[ - '--ld-path=ld.lld', + '--ld-path=$lldPath', '-nostartfiles', '-nostdlib', ],