summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Denton <chris@chrisdenton.dev>2023-03-30 23:34:31 +0100
committerChris Denton <chris@chrisdenton.dev>2023-03-30 23:35:46 +0100
commita340cf7c613122ac14696d7ee5b1bb665e642272 (patch)
tree1dab2007125594b436f605e8d59f0d56d567fa02
parent68e06adafa8f793b094a23b210d39b27c813600c (diff)
downloadrust-libc-a340cf7c613122ac14696d7ee5b1bb665e642272.tar.gz
MSVC: Add `msvc_crt_link` options
This allow configuring how the MSVC CRT is linked without involving the compiler.
-rw-r--r--src/windows/mod.rs95
1 files changed, 91 insertions, 4 deletions
diff --git a/src/windows/mod.rs b/src/windows/mod.rs
index 7f2f1ded19..fb4502b70d 100644
--- a/src/windows/mod.rs
+++ b/src/windows/mod.rs
@@ -254,10 +254,97 @@ pub const SIG_GET: ::sighandler_t = 2;
pub const SIG_SGE: ::sighandler_t = 3;
pub const SIG_ACK: ::sighandler_t = 4;
-// inline comment below appeases style checker
-#[cfg(all(target_env = "msvc", feature = "rustc-dep-of-std"))] // " if "
-#[link(name = "msvcrt", cfg(not(target_feature = "crt-static")))]
-#[link(name = "libcmt", cfg(target_feature = "crt-static"))]
+// MSVC C RunTime (CRT) link options.
+//
+// If `target_feature = "crt-static" then use the static CRT. Otherwise use the
+// dll.
+//
+// Linking the CRT can be further configured using the `msvc_crt_link` cfg.
+// It can be set in rustflags with `--cfg msvc_crt_link=option` where "option"
+// can be:
+//
+// * `nocrt`: do not link the crt. This makes other options be no-ops.
+// * `debug`: use the debug crt libraries
+// * `dynamic-ucrt`: link the ucrt dynamically even if using the static C runtime
+#[cfg(all(target_env = "msvc", feature = "rustc-dep-of-std"))]
+#[link(
+ // MSVC dynamic crt (release)
+ name = "msvcrt",
+ cfg(all(
+ not(target_feature = "crt-static"),
+ not(msvc_crt_link = "debug"),
+ not(msvc_crt_link = "nocrt")
+ ))
+)]
+#[link(
+ // MSVC dynamic crt (debug)
+ name = "msvcrtd",
+ cfg(all(
+ not(target_feature = "crt-static"),
+ msvc_crt_link = "debug",
+ not(msvc_crt_link = "nocrt")
+ ))
+)]
+#[link(
+ // MSVC static crt (release)
+ name = "libcmt",
+ cfg(all(
+ target_feature = "crt-static",
+ not(msvc_crt_link = "debug"),
+ not(msvc_crt_link = "nocrt")
+ ))
+)]
+#[link(
+ // MSVC static crt (debug)
+ name = "libcmtd",
+ cfg(all(
+ target_feature = "crt-static",
+ msvc_crt_link = "debug",
+ not(msvc_crt_link = "nocrt")
+ ))
+)]
+#[link(
+ // Link the ucrt dynamically (release)
+ name = "ucrt",
+ cfg(all(
+ target_feature = "crt-static",
+ msvc_crt_link = "dynamic-ucrt",
+ not(msvc_crt_link = "debug"),
+ not(msvc_crt_link = "nocrt")
+ ))
+)]
+#[link(
+ // Disable the static ucrt (release)
+ name = "/nodefaultlib:libucrt",
+ cfg(all(
+ target_feature = "crt-static",
+ msvc_crt_link = "dynamic-ucrt",
+ not(msvc_crt_link = "debug"),
+ not(msvc_crt_link = "nocrt")
+ )),
+ modifiers = "+verbatim"
+)]
+#[link(
+ // Link the ucrt dynamically (debug)
+ name = "ucrtd",
+ cfg(all(
+ target_feature = "crt-static",
+ msvc_crt_link = "dynamic-ucrt",
+ msvc_crt_link = "debug",
+ not(msvc_crt_link = "nocrt")
+ ))
+)]
+#[link(
+ // Disable the static ucrt (debug)
+ name = "/nodefaultlib:libucrtd",
+ cfg(all(
+ target_feature = "crt-static",
+ msvc_crt_link = "dynamic-ucrt",
+ msvc_crt_link = "debug",
+ not(msvc_crt_link = "nocrt")
+ )),
+ modifiers = "+verbatim"
+)]
extern "C" {}
#[cfg_attr(feature = "extra_traits", derive(Debug))]