Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1721-crt-static provides Windows/MSVC-specific instructions that don't work on Windows #3096

Closed
micolous opened this issue Mar 24, 2021 · 0 comments · Fixed by #3125
Closed

Comments

@micolous
Copy link

micolous commented Mar 24, 2021

From https://rust-lang.github.io/rfcs/1721-crt-static.html#lazy-link-attributes

Finally, an example of compiling for MSVC and linking statically to the C runtime would look like:

RUSTFLAGS='-C target-feature=+crt-static' cargo build --target x86_64-pc-windows-msvc

When you try to actually enter this into a Windows cmd prompt, you get back:

D:\code>RUSTFLAGS='-C target-feature=+crt-static' cargo build --target x86_64-pc-windows-msvc

'RUSTFLAGS' is not recognized as an internal or external command,
operable program or batch file.

Similarly in PowerShell:

PS D:\code> RUSTFLAGS='-C target-feature=+crt-static' cargo build --target x86_64-pc-windows-msvc
RUSTFLAGS=-C target-feature=+crt-static : The term 'RUSTFLAGS=-C target-feature=+crt-static' is not recognized as the
name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:1
+ RUSTFLAGS='-C target-feature=+crt-static' cargo build --target x86_64 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (RUSTFLAGS=-C target-feature=+crt-static:String) [], CommandNotFoundExce
   ption
    + FullyQualifiedErrorId : CommandNotFoundException

The best way to do it that works with both cmd and PowerShell is set:

D:\code>set RUSTFLAGS=-C target-feature=+crt-static
D:\code>cargo build --target x86_64-pc-windows-msvc
[build proceeds as normal]

However, this is equivalent to export in /bin/sh, and will persist until the shell is closed.

Note also that you must not specify quotes here, otherwise it will break in cmd (because the environment variable includes those quotation marks):

error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `rustc - --crate-name ___ --print=file-names '-C target-feature=+crt-static' --target x86_64-pc-windows-msvc --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=cfg` (exit code: 1)
  --- stderr
  error: multiple input filenames provided (first two filenames are `-` and `'-C`)

The only way that the present instructions could work with MSVC on Windows is with msys version of bash. However, that environment is generally geared towards *-pc-windows-gnu, which doesn't need the crt-static feature AFAIK.

Previously pointed out in rust-lang/cargo#1137 (comment) and rust-cli/team#34

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant