Skip to content

Commit 134e63f

Browse files
authored
Introducing the windows-link crate (#3450)
1 parent 021257c commit 134e63f

File tree

326 files changed

+21421
-21050
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

326 files changed

+21421
-21050
lines changed

.github/workflows/clippy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ jobs:
305305
run: cargo clippy -p windows-implement
306306
- name: Clippy windows-interface
307307
run: cargo clippy -p windows-interface
308+
- name: Clippy windows-link
309+
run: cargo clippy -p windows-link
308310
- name: Clippy windows-registry
309311
run: cargo clippy -p windows-registry
310312
- name: Clippy windows-result
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: windows-link
2+
3+
on:
4+
pull_request:
5+
paths-ignore:
6+
- '.github/ISSUE_TEMPLATE/**'
7+
- 'web/**'
8+
push:
9+
paths-ignore:
10+
- '.github/ISSUE_TEMPLATE/**'
11+
- 'web/**'
12+
branches:
13+
- master
14+
15+
jobs:
16+
check:
17+
strategy:
18+
matrix:
19+
rust: [1.71.0, stable, nightly]
20+
runs-on: windows-2022
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
- name: Prepare
25+
run: rustup update --no-self-update ${{ matrix.rust }} && rustup default ${{ matrix.rust }}
26+
- name: Check
27+
run: cargo check -p windows-link

.github/workflows/no-default-features.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ jobs:
4545
run: cargo check -p windows-implement --no-default-features
4646
- name: Check windows-interface
4747
run: cargo check -p windows-interface --no-default-features
48+
- name: Check windows-link
49+
run: cargo check -p windows-link --no-default-features
4850
- name: Check windows-registry
4951
run: cargo check -p windows-registry --no-default-features
5052
- name: Check windows-result

.github/workflows/raw-dylib.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ jobs:
336336
run: cargo test -p windows-implement --target ${{ matrix.target }} ${{ matrix.etc }}
337337
- name: Test windows-interface
338338
run: cargo test -p windows-interface --target ${{ matrix.target }} ${{ matrix.etc }}
339+
- name: Test windows-link
340+
run: cargo test -p windows-link --target ${{ matrix.target }} ${{ matrix.etc }}
339341
- name: Test windows-registry
340342
run: cargo test -p windows-registry --target ${{ matrix.target }} ${{ matrix.etc }}
341343
- name: Test windows-result
@@ -362,6 +364,8 @@ jobs:
362364
run: cargo test -p windows_x86_64_gnu --target ${{ matrix.target }} ${{ matrix.etc }}
363365
- name: Test windows_x86_64_gnullvm
364366
run: cargo test -p windows_x86_64_gnullvm --target ${{ matrix.target }} ${{ matrix.etc }}
367+
- name: Clean
368+
run: cargo clean
365369
- name: Test windows_x86_64_msvc
366370
run: cargo test -p windows_x86_64_msvc --target ${{ matrix.target }} ${{ matrix.etc }}
367371
- name: Check diff

.github/workflows/test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,8 @@ jobs:
333333
run: cargo test -p windows-implement --target ${{ matrix.target }} ${{ matrix.etc }}
334334
- name: Test windows-interface
335335
run: cargo test -p windows-interface --target ${{ matrix.target }} ${{ matrix.etc }}
336+
- name: Test windows-link
337+
run: cargo test -p windows-link --target ${{ matrix.target }} ${{ matrix.etc }}
336338
- name: Test windows-registry
337339
run: cargo test -p windows-registry --target ${{ matrix.target }} ${{ matrix.etc }}
338340
- name: Test windows-result
@@ -359,6 +361,8 @@ jobs:
359361
run: cargo test -p windows_x86_64_gnu --target ${{ matrix.target }} ${{ matrix.etc }}
360362
- name: Test windows_x86_64_gnullvm
361363
run: cargo test -p windows_x86_64_gnullvm --target ${{ matrix.target }} ${{ matrix.etc }}
364+
- name: Clean
365+
run: cargo clean
362366
- name: Test windows_x86_64_msvc
363367
run: cargo test -p windows_x86_64_msvc --target ${{ matrix.target }} ${{ matrix.etc }}
364368
- name: Check diff

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ windows-result = { path = "crates/libs/result" }
3131
windows-strings = { path = "crates/libs/strings" }
3232
windows-sys = { path = "crates/libs/sys" }
3333
windows-targets = { path = "crates/libs/targets" }
34+
windows-link = { path = "crates/libs/link" }
3435
windows-version = { path = "crates/libs/version" }
3536
helpers = { path = "crates/libs/helpers" }

crates/libs/bindgen/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct Config {
6161
pub sys: bool,
6262
pub implement: bool,
6363
pub derive: Derive,
64+
pub link: String,
6465
}
6566

6667
/// The Windows code generator.
@@ -88,6 +89,7 @@ where
8889
let mut rustfmt = String::new();
8990
let mut output = String::new();
9091
let mut sys = false;
92+
let mut link = "windows_link".to_string();
9193

9294
for arg in &args {
9395
if arg.starts_with('-') {
@@ -110,6 +112,7 @@ where
110112
"--package" => package = true,
111113
"--sys" => sys = true,
112114
"--implement" => implement = true,
115+
"--link" => kind = ArgKind::Link,
113116
_ => panic!("invalid option `{arg}`"),
114117
},
115118
ArgKind::Output => {
@@ -134,6 +137,7 @@ where
134137
derive.push(arg.as_str());
135138
}
136139
ArgKind::Rustfmt => rustfmt = arg.to_string(),
140+
ArgKind::Link => link = arg.to_string(),
137141
}
138142
}
139143

@@ -179,6 +183,7 @@ where
179183
output,
180184
sys,
181185
implement,
186+
link,
182187
}));
183188

184189
let tree = TypeTree::new(&config.types);
@@ -199,6 +204,7 @@ enum ArgKind {
199204
Rustfmt,
200205
Reference,
201206
Derive,
207+
Link,
202208
}
203209

204210
#[track_caller]

crates/libs/bindgen/src/types/cpp_fn.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ impl CppFn {
6969
quote! {}
7070
};
7171

72+
let link = to_ident(&writer.config.link);
73+
7274
link_fmt(quote! {
73-
windows_targets::link!(#library #abi #symbol fn #name(#(#params),* #vararg) #return_sig);
75+
#link::link!(#library #abi #symbol fn #name(#(#params),* #vararg) #return_sig);
7476
})
7577
}
7678

crates/libs/core/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ workspace = true
1717
default-target = "x86_64-pc-windows-msvc"
1818
targets = []
1919

20-
[dependencies.windows-targets]
21-
version = "0.53.0"
22-
path = "../targets"
20+
[dependencies.windows-link]
21+
version = "0.1.0"
22+
path = "../link"
2323

2424
[dependencies.windows-result]
2525
version = "0.3.0"

crates/libs/core/src/imp/bindings.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
clippy::all
77
)]
88

9-
windows_targets::link!("kernel32.dll" "system" fn CloseHandle(hobject : HANDLE) -> BOOL);
10-
windows_targets::link!("ole32.dll" "system" fn CoIncrementMTAUsage(pcookie : *mut CO_MTA_USAGE_COOKIE) -> HRESULT);
11-
windows_targets::link!("ole32.dll" "system" fn CoTaskMemAlloc(cb : usize) -> *mut core::ffi::c_void);
12-
windows_targets::link!("ole32.dll" "system" fn CoTaskMemFree(pv : *const core::ffi::c_void));
13-
windows_targets::link!("kernel32.dll" "system" fn CreateEventW(lpeventattributes : *const SECURITY_ATTRIBUTES, bmanualreset : BOOL, binitialstate : BOOL, lpname : PCWSTR) -> HANDLE);
14-
windows_targets::link!("kernel32.dll" "system" fn EncodePointer(ptr : *const core::ffi::c_void) -> *mut core::ffi::c_void);
15-
windows_targets::link!("kernel32.dll" "system" fn FreeLibrary(hlibmodule : HMODULE) -> BOOL);
16-
windows_targets::link!("kernel32.dll" "system" fn GetProcAddress(hmodule : HMODULE, lpprocname : PCSTR) -> FARPROC);
17-
windows_targets::link!("kernel32.dll" "system" fn LoadLibraryExA(lplibfilename : PCSTR, hfile : HANDLE, dwflags : LOAD_LIBRARY_FLAGS) -> HMODULE);
18-
windows_targets::link!("api-ms-win-core-winrt-l1-1-0.dll" "system" fn RoGetActivationFactory(activatableclassid : HSTRING, iid : *const GUID, factory : *mut *mut core::ffi::c_void) -> HRESULT);
19-
windows_targets::link!("kernel32.dll" "system" fn SetEvent(hevent : HANDLE) -> BOOL);
20-
windows_targets::link!("kernel32.dll" "system" fn WaitForSingleObject(hhandle : HANDLE, dwmilliseconds : u32) -> WAIT_EVENT);
9+
windows_link::link!("kernel32.dll" "system" fn CloseHandle(hobject : HANDLE) -> BOOL);
10+
windows_link::link!("ole32.dll" "system" fn CoIncrementMTAUsage(pcookie : *mut CO_MTA_USAGE_COOKIE) -> HRESULT);
11+
windows_link::link!("ole32.dll" "system" fn CoTaskMemAlloc(cb : usize) -> *mut core::ffi::c_void);
12+
windows_link::link!("ole32.dll" "system" fn CoTaskMemFree(pv : *const core::ffi::c_void));
13+
windows_link::link!("kernel32.dll" "system" fn CreateEventW(lpeventattributes : *const SECURITY_ATTRIBUTES, bmanualreset : BOOL, binitialstate : BOOL, lpname : PCWSTR) -> HANDLE);
14+
windows_link::link!("kernel32.dll" "system" fn EncodePointer(ptr : *const core::ffi::c_void) -> *mut core::ffi::c_void);
15+
windows_link::link!("kernel32.dll" "system" fn FreeLibrary(hlibmodule : HMODULE) -> BOOL);
16+
windows_link::link!("kernel32.dll" "system" fn GetProcAddress(hmodule : HMODULE, lpprocname : PCSTR) -> FARPROC);
17+
windows_link::link!("kernel32.dll" "system" fn LoadLibraryExA(lplibfilename : PCSTR, hfile : HANDLE, dwflags : LOAD_LIBRARY_FLAGS) -> HMODULE);
18+
windows_link::link!("api-ms-win-core-winrt-l1-1-0.dll" "system" fn RoGetActivationFactory(activatableclassid : HSTRING, iid : *const GUID, factory : *mut *mut core::ffi::c_void) -> HRESULT);
19+
windows_link::link!("kernel32.dll" "system" fn SetEvent(hevent : HANDLE) -> BOOL);
20+
windows_link::link!("kernel32.dll" "system" fn WaitForSingleObject(hhandle : HANDLE, dwmilliseconds : u32) -> WAIT_EVENT);
2121
pub type BOOL = i32;
2222
pub type CO_MTA_USAGE_COOKIE = *mut core::ffi::c_void;
2323
pub type FARPROC = Option<unsafe extern "system" fn() -> isize>;

0 commit comments

Comments
 (0)