Skip to content

Linux: Apps using native assets need lld which may not be available #178659

Description

@simolus3

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:

  1. 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.
  2. Flutter could detect a binutils installation and use a GCC toolchain for linker instead.
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    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