Files
codex/patches/aws-lc-sys_windows_bazel_prebuilt_nasm.patch
T

68 lines
2.4 KiB
Diff

# What: make Bazel Windows builds use aws-lc-sys's integrity-pinned NASM
# fallback and retain Bazel's declared manifest path.
# Why: build scripts must not probe PATH for an undeclared assembler, and
# canonicalizing the runfiles path loses the declared source-tree layout.
diff --git a/builder/main.rs b/builder/main.rs
index 51a9bc1..0d6f99f 100644
--- a/builder/main.rs
+++ b/builder/main.rs
@@ -723,14 +723,30 @@ fn get_crate_cflags() -> Option<String> {
.or(optional_env_optional_crate_target("CFLAGS"))
}
+pub(crate) fn is_bazel_windows_build_script() -> bool {
+ if target_os() != "windows" {
+ return false;
+ }
+
+ if optional_env("RULES_RUST_BAZEL_BUILD_SCRIPT_RUNNER").is_some() {
+ return true;
+ }
+
+ let cargo_manifest_dir = cargo_env("CARGO_MANIFEST_DIR");
+ Path::new(&cargo_manifest_dir)
+ .components()
+ .any(|component| component.as_os_str() == "bazel-out")
+}
+
fn use_prebuilt_nasm() -> bool {
+ let use_prebuilt_for_bazel_windows = is_bazel_windows_build_script();
target_os() == "windows"
&& target_arch() == "x86_64"
&& !is_no_asm()
- && !test_nasm_command() // NASM not found in environment
&& Some(false) != allow_prebuilt_nasm() // not prevented by environment
&& !is_disable_prebuilt_nasm() // not prevented by feature
// permitted by environment or by feature
+ && (use_prebuilt_for_bazel_windows || !test_nasm_command())
&& (Some(true) == allow_prebuilt_nasm() || is_prebuilt_nasm())
}
@@ -753,6 +769,10 @@ fn has_pregenerated() -> bool {
}
fn test_nasm_command() -> bool {
+ if is_bazel_windows_build_script() {
+ return false;
+ }
+
let status = execute_command("nasm".as_ref(), &["-version".as_ref()]).status;
if !status {
emit_warning("NASM command not found or failed to execute.");
@@ -817,8 +837,12 @@ fn main() {
initialize();
prepare_cargo_cfg();
- let manifest_dir = current_dir();
- let manifest_dir = dunce::canonicalize(Path::new(&manifest_dir)).unwrap();
+ let manifest_dir = if is_bazel_windows_build_script() {
+ PathBuf::from(cargo_env("CARGO_MANIFEST_DIR"))
+ } else {
+ let manifest_dir = current_dir();
+ dunce::canonicalize(Path::new(&manifest_dir)).unwrap()
+ };
let prefix_str = prefix_string();
let prefix = if is_no_prefix() {
None