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

Windows CRT linking behavior in no_std build #1203

Closed
CarePackage17 opened this issue Jan 10, 2019 · 8 comments
Closed

Windows CRT linking behavior in no_std build #1203

CarePackage17 opened this issue Jan 10, 2019 · 8 comments

Comments

@CarePackage17
Copy link

Relevant users forum thread: https://users.rust-lang.org/t/linker-error-when-building-no-std-windows-dll-that-uses-libc/23976

My goal is to enable Rust to run on Windows UWP, which requires linking to a different version of the CRT. Since there's no support in the standard library yet, I tried to go the no_std route to get familiar with the linking behavior on win32 before trying to adapt to UWP. However, as was pointed out by winapis maintainer, libc doesn't link properly for no_std executables/DLLs.

Is there a reason for this behavior or is this a bug?

@alexcrichton
Copy link
Member

I think we've just never gotten around to implementing this, would be good to fix!

@CarePackage17
Copy link
Author

I've commented out the //#[cfg(all(target_env = "msvc", feature = "rustc-dep-of-std"))], but the compiler doesn't like cfg(target_feature = "..."). It was nice enough to point me to this issue though: rust-lang/rust#37406

I've read through it and if I understood right, cfg(target_feature = "...") is unstable and should only be used when building as part of std.

Do you have any suggestion what could be done to fix this?

@alexcrichton
Copy link
Member

The target_feature shouldn't be necessary in theory as the build script can detect what's the best attribute to emit, but it's likely not trivial to figure out the right incantation there.

@CarePackage17
Copy link
Author

Do you mean the top-level one or is there another build script that I'm not aware of?

A quick search turned up that the only two usages of target_feature are in src/windows/mod.rs and and src/unix/mod.rs, so it's mainly about statically linking the CRT if specified.

@alexcrichton
Copy link
Member

Yes in that build script it should be possible to detect whether we're using a static crt or not, and then emit a cfg directive indicating which linking directive should be used.

@CarePackage17
Copy link
Author

Is the cfg! macro the right way to handle this?

@alexcrichton
Copy link
Member

I'd recommend testing it out locally! I suspect whatever works is good to go

@JohnTitor
Copy link
Member

Closing in favor of #1227 (comment).

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.

3 participants