Skip to content

Commit 28bf1a4

Browse files
committed
feat: probe for windows nightly
1 parent 54e3eb2 commit 28bf1a4

File tree

6 files changed

+108
-54
lines changed

6 files changed

+108
-54
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,6 @@ jobs:
5151
- stable
5252
- beta
5353
- nightly
54-
exclude:
55-
# Windows builds depend on an unstable feature: windows_process_exit_code_from
56-
# TODO: find a better way to handle this for windows without nightly
57-
- os: windows-latest
58-
rust:
59-
- '1.86'
60-
- '1.87'
61-
- '1.88'
62-
- '1.89'
63-
- '1.90'
64-
- stable
65-
- beta
6654
runs-on: ${{ matrix.os }}
6755
env:
6856
RUSTFLAGS: "-D warnings"

crates/git-remote-codecommit/build.rs

Lines changed: 60 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,54 +23,75 @@ macro_rules! die {
2323
fn main() {
2424
println!("cargo:rustc-check-cfg=cfg(build_feature_probe)");
2525
println!("cargo:rustc-check-cfg=cfg(bool_to_result)");
26-
println!("cargo:rerun-if-changed=src/nightly.rs");
27-
28-
let bool_to_result;
29-
let consider_rustc_bootstrap;
30-
if compile_probe(false) {
31-
// This is a nightly or dev compiler, so it supports unstable
32-
// features regardless of RUSTC_BOOTSTRAP. No need to rerun build
33-
// script if RUSTC_BOOTSTRAP is changed.
34-
bool_to_result = true;
35-
consider_rustc_bootstrap = false;
36-
} else if let Some(rustc_bootstrap) = std::env::var_os("RUSTC_BOOTSTRAP") {
37-
if compile_probe(true) {
38-
// This is a stable or beta compiler for which the user has set
39-
// RUSTC_BOOTSTRAP to turn on unstable features. Rerun build
40-
// script if they change it.
41-
bool_to_result = true;
42-
consider_rustc_bootstrap = true;
43-
} else if rustc_bootstrap == "1" {
44-
// This compiler does not support the generic member access API
45-
// in the form that anyhow expects. No need to pay attention to
46-
// RUSTC_BOOTSTRAP.
47-
bool_to_result = false;
48-
consider_rustc_bootstrap = false;
49-
} else {
50-
// This is a stable or beta compiler for which RUSTC_BOOTSTRAP
51-
// is set to restrict the use of unstable features by this
52-
// crate.
53-
bool_to_result = false;
54-
consider_rustc_bootstrap = true;
55-
}
56-
} else {
57-
// Without RUSTC_BOOTSTRAP, this compiler does not support the
58-
// unstable features this crate uses, but try again if the user turns on
59-
// unstable features.
60-
bool_to_result = false;
61-
consider_rustc_bootstrap = true;
62-
}
26+
println!("cargo:rustc-check-cfg=cfg(windows_process_exit_code_from)");
27+
println!("cargo:rerun-if-changed=src/nightly/mod.rs");
28+
println!("cargo:rerun-if-changed=src/nightly/bool_or.rs");
29+
println!("cargo:rerun-if-changed=src/nightly/windows_process_exit_code.rs");
30+
31+
let CompilerProbeResult {
32+
supported: bool_to_result,
33+
consider_rustc_bootstrap,
34+
} = compiler_probe("bool_or.rs");
6335

6436
if bool_to_result {
6537
println!("cargo:rustc-cfg=bool_to_result");
6638
}
6739

40+
#[cfg(windows)]
41+
let consider_rustc_bootstrap = {
42+
let CompilerProbeResult {
43+
supported,
44+
consider_rustc_bootstrap: consider_rustc_bootstrap_windows,
45+
} = compiler_probe("windows_process_exit_code.rs");
46+
if supported {
47+
println!("cargo:rustc-cfg=windows_process_exit_code_from");
48+
}
49+
50+
consider_rustc_bootstrap || consider_rustc_bootstrap_windows
51+
};
52+
6853
if consider_rustc_bootstrap {
6954
println!("cargo:rerun-if-env-changed=RUSTC_BOOTSTRAP");
7055
}
7156
}
7257

73-
fn compile_probe(rustc_bootstrap: bool) -> bool {
58+
struct CompilerProbeResult {
59+
supported: bool,
60+
consider_rustc_bootstrap: bool,
61+
}
62+
63+
fn compiler_probe(filename: impl AsRef<Path>) -> CompilerProbeResult {
64+
if compile_probe(&filename, false) {
65+
CompilerProbeResult {
66+
supported: true,
67+
consider_rustc_bootstrap: false,
68+
}
69+
} else if let Some(rustc_bootstrap) = std::env::var_os("RUSTC_BOOTSTRAP") {
70+
if compile_probe("bool_or.rs", true) {
71+
CompilerProbeResult {
72+
supported: true,
73+
consider_rustc_bootstrap: true,
74+
}
75+
} else if rustc_bootstrap == "1" {
76+
CompilerProbeResult {
77+
supported: false,
78+
consider_rustc_bootstrap: false,
79+
}
80+
} else {
81+
CompilerProbeResult {
82+
supported: false,
83+
consider_rustc_bootstrap: true,
84+
}
85+
}
86+
} else {
87+
CompilerProbeResult {
88+
supported: false,
89+
consider_rustc_bootstrap: true,
90+
}
91+
}
92+
}
93+
94+
fn compile_probe(filename: impl AsRef<Path>, rustc_bootstrap: bool) -> bool {
7495
if std::env::var_os("RUSTC_STAGE").is_some() {
7596
println!("cargo:rerun-if-env-changed=RUSTC_STAGE");
7697
// We are running inside rustc bootstrap. This is a highly non-standard
@@ -89,7 +110,7 @@ fn compile_probe(rustc_bootstrap: bool) -> bool {
89110
let out_subdir = Path::new(&out_dir).join(probe_dir);
90111
mkdir(&out_subdir);
91112

92-
let probefile = Path::new("src").join("nightly.rs");
113+
let probefile = Path::new("src").join("nightly").join(filename);
93114

94115
let mut cmd = rustc_command();
95116

crates/git-remote-codecommit/src/main.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
#![cfg_attr(windows, feature(windows_process_exit_code_from))]
1+
#![cfg_attr(
2+
windows_process_exit_code_from,
3+
feature(windows_process_exit_code_from)
4+
)]
25
#![cfg_attr(bool_to_result, feature(bool_to_result))]
36

47
mod canonical_request;
@@ -144,13 +147,13 @@ fn exec_replace(mut cmd: std::process::Command) -> anyhow::Result<ExitCode> {
144147
fn exec_replace(mut cmd: std::process::Command) -> anyhow::Result<ExitCode> {
145148
#![expect(unsafe_code)]
146149

147-
use std::os::windows::process::ExitCodeExt;
148-
149150
use windows_sys::Win32::Foundation::FALSE;
150151
use windows_sys::Win32::Foundation::TRUE;
151152
use windows_sys::Win32::System::Console::SetConsoleCtrlHandler;
152153
use windows_sys::core::BOOL;
153154

155+
use crate::nightly::ExitCodeExt;
156+
154157
unsafe extern "system" fn ctrlc_handler(_: u32) -> BOOL {
155158
// Do nothing; let the child process handle it.
156159
TRUE
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#[cfg(not(build_feature_probe))]
2+
mod bool_or;
3+
4+
#[cfg(all(windows, not(build_feature_probe)))]
5+
mod windows_process_exit_code;
6+
7+
#[cfg(all(windows, windows_process_exit_code_from))]
8+
pub(crate) use std::os::windows::process::ExitCodeExt;
9+
10+
#[cfg(not(bool_to_result))]
11+
pub(crate) use self::bool_or::BoolExt;
12+
#[cfg(all(windows, not(windows_process_exit_code_from)))]
13+
pub(crate) use self::windows_process_exit_code::ExitCodeExt;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#![cfg_attr(build_feature_probe, feature(windows_process_exit_code_from))]
2+
3+
#[cfg(build_feature_probe)]
4+
const _: () = {
5+
use std::process::ExitCode;
6+
7+
fn _probe() -> std::process::ExitCode {
8+
std::os::windows::process::ExitCodeExt::from_raw(0_u32)
9+
}
10+
};
11+
12+
#[cfg(build_feature_probe)]
13+
const _: Option<&str> = option_env!("RUSTC_BOOTSTRAP");
14+
15+
#[cfg(not(windows_process_exit_code_from))]
16+
pub(crate) trait ExitCodeExt {
17+
fn from_raw(code: u32) -> Self;
18+
}
19+
20+
#[cfg(not(windows_process_exit_code_from))]
21+
impl ExitCodeExt for std::process::ExitCode {
22+
fn from_raw(code: u32) -> Self {
23+
if (code & 0xff) == code {
24+
std::process::ExitCode::from((code & 0xff) as u8)
25+
} else {
26+
std::process::ExitCode::FAILURE
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)