Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 19 additions & 4 deletions cargo-near-build/src/cargo_native/compile.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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
};
Expand All @@ -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,
)?;
Expand Down
13 changes: 12 additions & 1 deletion cargo-near-build/src/near/abi/generate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Dylib>(
Expand Down