Skip to content

CCompilerConfig grabbed incorrectly on macOS #175553

@GregoryConrad

Description

@GregoryConrad

Steps to reproduce

CC @dcharkes, this is the last of the build-related problems I've run into for Native Assets (I think anyways...)

I'm happy to PR a fix for this, I just would like clarification on which of the 2 approaches listed below (or something else) we would like to go with in order to fix this.

Currently, CCompilerConfig is created this way on macOS:

/// Flutter expects `xcrun` to be on the path on macOS hosts.
///
/// Use the `clang`, `ar`, and `ld` that would be used if run with `xcrun`.
Future<CCompilerConfig> cCompilerConfigMacOS() async {
final ProcessResult xcrunResult = await globals.processManager.run(<String>[
'xcrun',
'clang',
'--version',
]);
if (xcrunResult.exitCode != 0) {
throwToolExit('Failed to find clang with xcrun:\n${xcrunResult.stderr}');
}
final String installPath = LineSplitter.split(
xcrunResult.stdout as String,
).firstWhere((String s) => s.startsWith('InstalledDir: ')).split(' ').last;
return CCompilerConfig(
compiler: Uri.file('$installPath/clang'),
archiver: Uri.file('$installPath/ar'),
linker: Uri.file('$installPath/ld'),
);
}

This breaks under Nix on macOS when the xcrun is provided via Nix, as ld + ar are not present at the location expected above.

Expected results

CCompilerConfig should be created via either:

  1. (Simpler + likely more correct) use xcrun --find <binary-name> to find clang, ld, and ar
    i. Based on CLI experimentation this produces correct results in both Nix + non-Nix environments on macOS
  2. Looking on PATH for clang and then use that to find its associated ld + ar (like is done on Linux)

Actual results

Build fails due to ld + ar not existing at the expected location.

Logs

Logs
ERROR: Build input for <project-name> contains errors
- BuildInput.config.code.cCompiler.linker (/nix/store/538b7kiga26rcxpqjspyn4r8wg32fmgh-clang-20.1.6/bin/ld) does not exist as a file.
- BuildInput.config.code.cCompiler.archiver (/nix/store/538b7kiga26rcxpqjspyn4r8wg32fmgh-clang-20.1.6/bin/ar) does not exist as a file.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listplatform-macBuilding on or for macOS specificallyteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions