Skip to content

Commit d70f59d

Browse files
authored
Rollup merge of rust-lang#102327 - ChrisDenton:std-raw-dylib, r=thomcc
Use `raw-dylib` in the std for non-x86 Windows The [`raw_dylib`](rust-lang#58713) feature was recently [stabilized for non-x86 Windows targets](rust-lang#99916). This is now in beta so std start to use it without feature flags. Eventually this may allowing linking Rust programs without needing import libraries. I think the standard library is best placed to dog food before the beta becomes the stable the release. There hopefully shouldn't be any issues but if there are it'd be good to catch them early.
2 parents c0ee7a1 + 4c05e3a commit d70f59d

File tree

1 file changed

+52
-3
lines changed
  • library/std/src/sys/windows

1 file changed

+52
-3
lines changed

library/std/src/sys/windows/c.rs

+52-3
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ pub const STATUS_INVALID_PARAMETER: NTSTATUS = 0xc000000d_u32 as _;
286286

287287
pub const STATUS_PENDING: NTSTATUS = 0x103 as _;
288288
pub const STATUS_END_OF_FILE: NTSTATUS = 0xC0000011_u32 as _;
289+
#[cfg(target_arch = "x86")]
289290
pub const STATUS_NOT_IMPLEMENTED: NTSTATUS = 0xC0000002_u32 as _;
290291

291292
// Equivalent to the `NT_SUCCESS` C preprocessor macro.
@@ -843,7 +844,8 @@ if #[cfg(not(target_vendor = "uwp"))] {
843844
) -> BOOL;
844845
}
845846

846-
#[link(name = "userenv")]
847+
#[cfg_attr(not(target_arch = "x86"), link(name = "userenv", kind = "raw-dylib"))]
848+
#[cfg_attr(target_arch = "x86", link(name = "userenv"))]
847849
extern "system" {
848850
// Allowed but unused by UWP
849851
pub fn GetUserProfileDirectoryW(
@@ -1158,7 +1160,8 @@ extern "system" {
11581160
pub fn GetFileAttributesW(lpFileName: LPCWSTR) -> DWORD;
11591161
}
11601162

1161-
#[link(name = "ws2_32")]
1163+
#[cfg_attr(not(target_arch = "x86"), link(name = "ws2_32", kind = "raw-dylib"))]
1164+
#[cfg_attr(target_arch = "x86", link(name = "ws2_32"))]
11621165
extern "system" {
11631166
pub fn WSAStartup(wVersionRequested: WORD, lpWSAData: LPWSADATA) -> c_int;
11641167
pub fn WSACleanup() -> c_int;
@@ -1251,7 +1254,8 @@ extern "system" {
12511254
) -> c_int;
12521255
}
12531256

1254-
#[link(name = "bcrypt")]
1257+
#[cfg_attr(not(target_arch = "x86"), link(name = "bcrypt", kind = "raw-dylib"))]
1258+
#[cfg_attr(target_arch = "x86", link(name = "bcrypt"))]
12551259
extern "system" {
12561260
// >= Vista / Server 2008
12571261
// https://docs.microsoft.com/en-us/windows/win32/api/bcrypt/nf-bcrypt-bcryptgenrandom
@@ -1270,6 +1274,47 @@ extern "system" {
12701274
pub fn BCryptCloseAlgorithmProvider(hAlgorithm: BCRYPT_ALG_HANDLE, dwFlags: ULONG) -> NTSTATUS;
12711275
}
12721276

1277+
#[cfg(not(target_arch = "x86"))]
1278+
#[link(name = "ntdll", kind = "raw-dylib")]
1279+
extern "system" {
1280+
pub fn NtCreateFile(
1281+
FileHandle: *mut HANDLE,
1282+
DesiredAccess: ACCESS_MASK,
1283+
ObjectAttributes: *const OBJECT_ATTRIBUTES,
1284+
IoStatusBlock: *mut IO_STATUS_BLOCK,
1285+
AllocationSize: *mut i64,
1286+
FileAttributes: ULONG,
1287+
ShareAccess: ULONG,
1288+
CreateDisposition: ULONG,
1289+
CreateOptions: ULONG,
1290+
EaBuffer: *mut c_void,
1291+
EaLength: ULONG,
1292+
) -> NTSTATUS;
1293+
pub fn NtReadFile(
1294+
FileHandle: BorrowedHandle<'_>,
1295+
Event: HANDLE,
1296+
ApcRoutine: Option<IO_APC_ROUTINE>,
1297+
ApcContext: *mut c_void,
1298+
IoStatusBlock: &mut IO_STATUS_BLOCK,
1299+
Buffer: *mut crate::mem::MaybeUninit<u8>,
1300+
Length: ULONG,
1301+
ByteOffset: Option<&LARGE_INTEGER>,
1302+
Key: Option<&ULONG>,
1303+
) -> NTSTATUS;
1304+
pub fn NtWriteFile(
1305+
FileHandle: BorrowedHandle<'_>,
1306+
Event: HANDLE,
1307+
ApcRoutine: Option<IO_APC_ROUTINE>,
1308+
ApcContext: *mut c_void,
1309+
IoStatusBlock: &mut IO_STATUS_BLOCK,
1310+
Buffer: *const u8,
1311+
Length: ULONG,
1312+
ByteOffset: Option<&LARGE_INTEGER>,
1313+
Key: Option<&ULONG>,
1314+
) -> NTSTATUS;
1315+
pub fn RtlNtStatusToDosError(Status: NTSTATUS) -> ULONG;
1316+
}
1317+
12731318
// Functions that aren't available on every version of Windows that we support,
12741319
// but we still use them and just provide some form of a fallback implementation.
12751320
compat_fn_with_fallback! {
@@ -1310,6 +1355,7 @@ compat_fn_optional! {
13101355
compat_fn_with_fallback! {
13111356
pub static NTDLL: &CStr = ansi_str!("ntdll");
13121357

1358+
#[cfg(target_arch = "x86")]
13131359
pub fn NtCreateFile(
13141360
FileHandle: *mut HANDLE,
13151361
DesiredAccess: ACCESS_MASK,
@@ -1325,6 +1371,7 @@ compat_fn_with_fallback! {
13251371
) -> NTSTATUS {
13261372
STATUS_NOT_IMPLEMENTED
13271373
}
1374+
#[cfg(target_arch = "x86")]
13281375
pub fn NtReadFile(
13291376
FileHandle: BorrowedHandle<'_>,
13301377
Event: HANDLE,
@@ -1338,6 +1385,7 @@ compat_fn_with_fallback! {
13381385
) -> NTSTATUS {
13391386
STATUS_NOT_IMPLEMENTED
13401387
}
1388+
#[cfg(target_arch = "x86")]
13411389
pub fn NtWriteFile(
13421390
FileHandle: BorrowedHandle<'_>,
13431391
Event: HANDLE,
@@ -1351,6 +1399,7 @@ compat_fn_with_fallback! {
13511399
) -> NTSTATUS {
13521400
STATUS_NOT_IMPLEMENTED
13531401
}
1402+
#[cfg(target_arch = "x86")]
13541403
pub fn RtlNtStatusToDosError(
13551404
Status: NTSTATUS
13561405
) -> ULONG {

0 commit comments

Comments
 (0)