This is a follow-up to #178659. When building Flutter apps using code assets on Linux systems that don't have LLVM's linker installed, the build process fails with Failed to find any of [ld.lld, ld] in LocalDirectory: /usr/lib/llvm-18/bin.
To reproduce this, start on a fresh Linux installation that has all the required tools but no full LLVM toolchain, check out an app using code assets (such as this one) and run flutter run -d linux.
To fix #178659, we've made the search in cCompilerConfigLinux optional when running unit tests. My understanding is that we fix the compiler and linker for actual app builds to we'll be able to support static linking with consistent toolchains in the future.
However, that method is still incorrect. It claims it
|
/// Returns a [CCompilerConfig] matching a toolchain that would be used to compile the main app with |
|
/// CMake on Linux. |
which is just not true. Default linux setups that have clang but no lld will use the GNU linker. I'm actually pretty sure that even if lld was installed, cmake would still prefer to use GNU ld. And for cross-compilation, that tool should probably use aarch64-linux-gnu-ld or whatever it's called. But trying to figure out compilers and linkers from the target platform alone is fundamentally flawed since users might customize their cmake logic or pass build flags to customize the linker.
To me at least, it seems like the only way to actually do what the documentation comment promises is to parse CMakeCache.txt in the build directory and extract values for CMAKE_CXX_COMPILER, CMAKE_CXX_COMPILER_AR and CMAKE_LINKER. That seems a bit fragile, but everything else is just wrong.
cc @dcharkes
This is a follow-up to #178659. When building Flutter apps using code assets on Linux systems that don't have LLVM's linker installed, the build process fails with
Failed to find any of [ld.lld, ld] in LocalDirectory: /usr/lib/llvm-18/bin.To reproduce this, start on a fresh Linux installation that has all the required tools but no full LLVM toolchain, check out an app using code assets (such as this one) and run
flutter run -d linux.To fix #178659, we've made the search in
cCompilerConfigLinuxoptional when running unit tests. My understanding is that we fix the compiler and linker for actual app builds to we'll be able to support static linking with consistent toolchains in the future.However, that method is still incorrect. It claims it
flutter/packages/flutter_tools/lib/src/isolated/native_assets/linux/native_assets.dart
Lines 12 to 13 in 0cfc041
which is just not true. Default linux setups that have clang but no
lldwill use the GNU linker. I'm actually pretty sure that even iflldwas installed, cmake would still prefer to use GNU ld. And for cross-compilation, that tool should probably useaarch64-linux-gnu-ldor whatever it's called. But trying to figure out compilers and linkers from the target platform alone is fundamentally flawed since users might customize their cmake logic or pass build flags to customize the linker.To me at least, it seems like the only way to actually do what the documentation comment promises is to parse
CMakeCache.txtin the build directory and extract values forCMAKE_CXX_COMPILER,CMAKE_CXX_COMPILER_ARandCMAKE_LINKER. That seems a bit fragile, but everything else is just wrong.cc @dcharkes