Skip to content

Native assets: Take GNU linkers into account when building Linux apps #180770

Description

@simolus3

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

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: buildBuilding flutter applications with the toola: desktopRunning on desktopplatform-linuxBuilding on or for Linux specificallyr: fixedIssue is closed as already fixed in a newer versionteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool team

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions