diff --git a/CHANGELOG.md b/CHANGELOG.md index 4234217b..3a56f7f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Fixed Windows (without WSL) build failure on ABI generation step by adding `/FORCE:UNRESOLVED` linker flag for MSVC +- Fixed RUSTFLAGS handling in cargo_native::compile to append flags instead of replacing them + ## [0.19.0](https://github.com/near/cargo-near/compare/cargo-near-v0.18.0...cargo-near-v0.19.0) - 2026-01-12 ### Added diff --git a/cargo-near-build/src/cargo_native/compile.rs b/cargo-near-build/src/cargo_native/compile.rs index 1a2e891c..c7c0907f 100644 --- a/cargo-near-build/src/cargo_native/compile.rs +++ b/cargo-near-build/src/cargo_native/compile.rs @@ -1,4 +1,4 @@ -use std::{collections::BTreeMap, ffi::OsStr, marker::PhantomData, process::Command, thread}; +use std::{ffi::OsStr, marker::PhantomData, process::Command, thread}; use camino::Utf8Path; use cargo_metadata::{Artifact, Message}; @@ -23,9 +23,24 @@ where T: ArtifactType, { let final_env = { - let mut env: BTreeMap<_, _> = env.into_iter().collect(); + // Convert to owned strings to allow modification + let mut env: Vec<(String, String)> = env + .into_iter() + .map(|(k, v)| (k.to_string(), v.to_string())) + .collect(); if hide_warnings { - env.insert(crate::env_keys::RUSTFLAGS, "-Awarnings"); + // Check if RUSTFLAGS already exists and append -Awarnings + if let Some(pos) = env + .iter() + .position(|(k, _)| k == crate::env_keys::RUSTFLAGS) + { + env[pos].1.push_str(" -Awarnings"); + } else { + env.push(( + crate::env_keys::RUSTFLAGS.to_string(), + "-Awarnings".to_string(), + )); + } } env }; @@ -36,7 +51,7 @@ where "build", [&["--message-format=json-render-diagnostics"], args].concat(), manifest_path.directory().ok(), - final_env.iter(), + final_env.iter().map(|(k, v)| (k.as_str(), v.as_str())), &removed_env, color, )?; diff --git a/cargo-near-build/src/near/abi/generate/mod.rs b/cargo-near-build/src/near/abi/generate/mod.rs index 74e96f8c..97b2aa8a 100644 --- a/cargo-near-build/src/near/abi/generate/mod.rs +++ b/cargo-near-build/src/near/abi/generate/mod.rs @@ -70,12 +70,23 @@ pub fn procedure( pretty_print::step("Generating ABI"); let compile_env = { - let compile_env = vec![ + #[allow(unused_mut)] + let mut compile_env = vec![ ("CARGO_PROFILE_DEV_OPT_LEVEL", "0"), ("CARGO_PROFILE_DEV_DEBUG", "0"), ("CARGO_PROFILE_DEV_LTO", "off"), (env_keys::BUILD_RS_ABI_STEP_HINT, "true"), ]; + + // On Windows MSVC, the linker doesn't allow unresolved symbols by default. + // When building a dylib for ABI generation, near-sdk's runtime functions + // (from near-sys) won't be available since they're provided by the NEAR VM + // in wasm builds. We use /FORCE:UNRESOLVED to allow the build to succeed. + #[cfg(windows)] + { + compile_env.push((env_keys::RUSTFLAGS, "-C link-arg=/FORCE:UNRESOLVED")); + } + [&compile_env, env].concat() }; let dylib_artifact = cargo_native::compile::run::(