Skip to content

Linker to be used with Rust on Windows #16023

Description

@dnicolodi

I know little about Rust and less about Windows, thus I am not sure whether this is just surprising behavior or a bug.

To setup the Rust compiler, Meson detects the available linker and then passes it to rustc via the -C liker= command line flag. On Windows systems where GCC is installed, this picks up cc as the linker and Meson tries to use rustc -C linker=cc as the Rust compiler. However, rustc on Windows assumes MSVS style command line arguments, thus linking fails when cc receives MSVC style command line arguments. In principle, this could be fixed passing the -C lin ker-flavor= command line option to rustc. However, rustc (at least the version I tried) only works with MSVS style compilers on Windows (see #16021 for an attempt at doing exactly this).

All this is fixed passing the --vsenv options to meson setup to setup the Visual Studio build environment.

The question are: What is the default linker for rustc on Windows? Should Meson try to use that despite the fact that other linkers are found? If MSVC link.exe is the default liker on Windows, does rustc require to be run in a Visual Studio environment? Should the fact that a linker incompatible with rustc has been detected result in a better error message than ERROR: Compiler rustc -C linker=cc cannot compile programs.?

This has been tested on GitHub Actions windows-latest runners.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions