On some (most?) Linux distributions, installing clang does not automatically install lld. In particular, the Set up Linux development page shows commands for Ubuntu that would not install lld as a linker (indeed, the clang package on Ubuntu depends on binutils to use GCC linkers / archivers by default).
However, when running build hooks for Linux targets, we try to find an lld installation next to clang++:
|
return CCompilerConfig( |
|
linker: _findExecutableIfExists(path: clangDir, possibleExecutableNames: kLdBinaryOptions), |
|
compiler: _findExecutableIfExists(path: clangDir, possibleExecutableNames: kClangBinaryOptions), |
|
archiver: _findExecutableIfExists(path: clangDir, possibleExecutableNames: kArBinaryOptions), |
|
); |
For users following the official setup instructions, building a Linux application depending on build hooks would fail because lld can't be found (reported to me in simolus3/sqlite3.dart#332). There are different ways to fix this:
- We could update the docs to mention that
lld is a dependency and must be installed. Note that for isolated snap installations, this might be harder or require further changes.
- Flutter could detect a binutils installation and use a GCC toolchain for
linker instead.
- If there are missing clang/llvm toolchain entries, we could just not pass a
CCompilerConfig at all and let the hook worry about resolving this? native_toolchain_c finds GGC toolchains just fine.
I assume the preference for LLVM was added for better cross-compilation support? But I think depending on clang for that is not enough because you also need sysroot headers for the other architectures anyway. And especially for dynamically-loaded libraries, I don't see why the main app and hooks would have to be compiled with the same C compiler.
cc @dcharkes for input on this. I'm happy to submit a PR for this, but it would be good to know which approach makes the most sense to you.
On some (most?) Linux distributions, installing clang does not automatically install
lld. In particular, the Set up Linux development page shows commands for Ubuntu that would not installlldas a linker (indeed, theclangpackage on Ubuntu depends onbinutilsto use GCC linkers / archivers by default).However, when running build hooks for Linux targets, we try to find an
lldinstallation next toclang++:flutter/packages/flutter_tools/lib/src/isolated/native_assets/linux/native_assets.dart
Lines 34 to 38 in 0bbbfd5
For users following the official setup instructions, building a Linux application depending on build hooks would fail because
lldcan't be found (reported to me in simolus3/sqlite3.dart#332). There are different ways to fix this:lldis a dependency and must be installed. Note that for isolatedsnapinstallations, this might be harder or require further changes.linkerinstead.CCompilerConfigat all and let the hook worry about resolving this?native_toolchain_cfinds GGC toolchains just fine.I assume the preference for LLVM was added for better cross-compilation support? But I think depending on clang for that is not enough because you also need sysroot headers for the other architectures anyway. And especially for dynamically-loaded libraries, I don't see why the main app and hooks would have to be compiled with the same C compiler.
cc @dcharkes for input on this. I'm happy to submit a PR for this, but it would be good to know which approach makes the most sense to you.