Skip to content

Commit

Permalink
Rollup merge of rust-lang#128873 - ChrisDenton:windows-targets, r=Mar…
Browse files Browse the repository at this point in the history
…k-Simulacrum

Add windows-targets crate to std's sysroot

With this PR, when backtrace is used as a crate from crates.io it will (once updated) use the real [windows-targets](https://crates.io/crates/windows-targets) crate. But when used from std it'll use std's replacement version.

This allows sharing our customized `windows_tagets::link!` macro between std proper and the backtrace crate when used as part of std, ensuring a consistent linking story. This will be especially important once we move to using [`raw-dylib`](https://doc.rust-lang.org/reference/items/external-blocks.html#dylib-versus-raw-dylib) by default.
  • Loading branch information
GuillaumeGomez authored Aug 13, 2024
2 parents 2e344d6 + a1b2b7f commit 8bf0656
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 7 deletions.
7 changes: 6 additions & 1 deletion library/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ dependencies = [
"std_detect",
"unwind",
"wasi",
"windows-targets 0.0.0",
]

[[package]]
Expand Down Expand Up @@ -421,9 +422,13 @@ version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
"windows-targets",
"windows-targets 0.52.5",
]

[[package]]
name = "windows-targets"
version = "0.0.0"

[[package]]
name = "windows-targets"
version = "0.52.5"
Expand Down
1 change: 1 addition & 0 deletions library/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
exclude = [
# stdarch has its own Cargo workspace
"stdarch",
"windows_targets"
]

[profile.release.package.compiler_builtins]
Expand Down
5 changes: 4 additions & 1 deletion library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ object = { version = "0.36.0", default-features = false, optional = true, featur
'archive',
] }

[target.'cfg(windows)'.dependencies.windows-targets]
path = "../windows_targets"

[dev-dependencies]
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }
rand_xorshift = "0.3.0"
Expand Down Expand Up @@ -116,7 +119,7 @@ std_detect_env_override = ["std_detect/std_detect_env_override"]

# Enable using raw-dylib for Windows imports.
# This will eventually be the default.
windows_raw_dylib = []
windows_raw_dylib = ["windows-targets/windows_raw_dylib"]

[package.metadata.fortanix-sgx]
# Maximum possible number of threads when testing
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/pal/windows/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::alloc::{GlobalAlloc, Layout, System};
use crate::ffi::c_void;
use crate::ptr;
use crate::sync::atomic::{AtomicPtr, Ordering};
use crate::sys::c::{self, windows_targets};
use crate::sys::c;
use crate::sys::common::alloc::{realloc_fallback, MIN_ALIGN};

#[cfg(test)]
Expand Down
2 changes: 0 additions & 2 deletions library/std/src/sys/pal/windows/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use core::ffi::{c_uint, c_ulong, c_ushort, c_void, CStr};
use core::{mem, ptr};

pub(super) mod windows_targets;

mod windows_sys;
pub use windows_sys::*;

Expand Down
1 change: 0 additions & 1 deletion library/std/src/sys/pal/windows/c/windows_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3317,4 +3317,3 @@ pub struct WSADATA {
#[cfg(target_arch = "arm")]
pub enum CONTEXT {}
// ignore-tidy-filelength
use super::windows_targets;
10 changes: 10 additions & 0 deletions library/windows_targets/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "windows-targets"
description = "A drop-in replacement for the real windows-targets crate for use in std only."
version = "0.0.0"
edition = "2021"

[features]
# Enable using raw-dylib for Windows imports.
# This will eventually be the default.
windows_raw_dylib = []
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
//!
//! This is a simple wrapper around an `extern` block with a `#[link]` attribute.
//! It's very roughly equivalent to the windows-targets crate.
#![no_std]
#![no_core]
#![feature(decl_macro)]
#![feature(no_core)]

#[cfg(feature = "windows_raw_dylib")]
pub macro link {
Expand Down
1 change: 0 additions & 1 deletion src/tools/generate-windows-sys/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ fn main() -> Result<(), Box<dyn Error>> {
let mut f = std::fs::File::options().append(true).open("windows_sys.rs")?;
f.write_all(ARM32_SHIM.as_bytes())?;
writeln!(&mut f, "// ignore-tidy-filelength")?;
writeln!(&mut f, "use super::windows_targets;")?;

Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions src/tools/tidy/src/pal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use crate::walk::{filter_dirs, walk};

// Paths that may contain platform-specific code.
const EXCEPTION_PATHS: &[&str] = &[
"library/windows_targets",
"library/panic_abort",
"library/panic_unwind",
"library/unwind",
Expand Down

0 comments on commit 8bf0656

Please sign in to comment.