Skip to content

[native_toolchain_c] Error finding clang compiler with swiftly installed, uses swiftly executable instead #2792

@nikeokoronkwo

Description

@nikeokoronkwo

I did not know whether to put this under package:hooks or package:native_toolchain_c or package:hooks, but I figured this was more an issue with C sources.

Apparently, the CBuilder API, when used with build hooks, seems to infer the wrong executable for the C compiler on macOS when swiftly is installed. When trying to run the following:

import 'package:code_assets/code_assets.dart';
import 'package:glob/glob.dart';
import 'package:glob/list_local_fs.dart';
import 'package:hooks/hooks.dart';
import 'package:native_toolchain_c/native_toolchain_c.dart';

void main(List<String> args) async {
  await build(args, (input, output) async {
    // get C sources
    if (input.config.buildCodeAssets) {
      final builder = CBuilder.library(
        name: 'p',
        assetName: 'src/generated/p_bindings.dart',
        sources: Glob('third-party/p/*.c', recursive: true).listSync().map((f) => f.path).toList(),

      );

      await builder.run(input: input, output: output);
    }
  });
}

It would produce the following error:

Running build hooks... Hook.build hook of package:lua has invalid output
- Code asset "package:p/src/generated/p_generated_bindings.dart" file (/project/.dart_tool/hooks_runner/shared/lua/build/9fb02c5622/liblua.dylib) does not exist as a file.

Error: Running build hooks failed.

Checking the stdout.txt file it produces made me noticed that it picked the wrong executable:

Running `which clang`.

// wrong executable
Running `~/.swiftly/bin/swiftly --version`.

Running `which clang`.

Running `which vswhere.exe`.

Running `~/.swiftly/bin/swiftly --version`.

Running `~/.swiftly/bin/swiftly --version`.

// ...

// wrong final exe
Running `~/.swiftly/bin/swiftly --target=arm64-apple-darwin -mmacos-version-min=12 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/ -fPIC -O3 -DRELEASE -DNDEBUG ... --shared -o /project/.dart_tool/hooks_runner/shared/lua/build/9fb02c5622/liblua.dylib -L/project/.dart_tool/hooks_runner/shared/lua/build/9fb02c5622/`.

Running which clang should produce ~/.swiftly/bin/clang, so I found it surprising it used the swiftly executable (~/.swiftly/bin/swiftly) instead.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions