Skip to content

[native_toolchain_c] Fix MSVC builds when paths contain spaces#3453

Merged
dcharkes merged 3 commits into
dart-lang:mainfrom
jakobkordez:ntc/msvc-fix
Jul 8, 2026
Merged

[native_toolchain_c] Fix MSVC builds when paths contain spaces#3453
dcharkes merged 3 commits into
dart-lang:mainfrom
jakobkordez:ntc/msvc-fix

Conversation

@jakobkordez

Copy link
Copy Markdown
Contributor

Description

Building with MSVC failed with 'C:\Program' is not recognized as an internal or external command whenever a source or include path contained a space —
e.g. the default pub cache under a Windows user name with a space
(C:\Users\First Last\AppData\Local\Pub\Cache\...).

The cause: runProcess ran every command through cmd.exe /c on Windows
(when a working directory was set), and cmd strips the outer quotes once the
command line contains more than two quote characters — so a quoted cl.exe
path plus one quoted argument was enough to mangle the invocation.

Changes:

  • runProcess no longer runs through a shell; cl.exe/lib.exe are invoked
    directly. (No caller needs shell features: on Windows programs expand
    wildcards themselves, and the vcvars environment setup uses its own
    Process.run.) As a consequence, cmd.exe %VAR% expansion no longer
    applies to compiler flags/defines — they now reach the tools verbatim.
  • The archiver is now passed the object file names derived from sources
    (matching cl.exe /c's naming) instead of *.obj. This keeps object files
    left in the output directory by other builds out of the archive, and keeps
    archive member names short and machine-independent instead of embedding
    the local build path (verified with lib.exe /list).
  • The logged command line now quotes the executable and spaced arguments so
    it can be copy-pasted to reproduce an invocation.
  • Adds a Windows regression test building a library (dynamic + static) with
    spaces in the source, include, and output paths.
  • Bumps to 0.19.3.

Related Issues

Fixes #3321.
Fixes #2848.

PR Checklist

  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
  • I've run dart tool/ci.dart --all locally and resolved all issues identified. This ensures the PR is formatted, has no lint errors, and ran all code generators. This applies to the packages part of the toplevel pubspec.yaml workspace.
  • All existing and new tests are passing. I added new tests to check the change I am making.
  • The PR is actually solving the issue. PRs that don't solve the issue will be closed. Please be respectful of the maintainers' time. If it's not clear what the issue is, feel free to ask questions on the GitHub issue before submitting a PR.
  • I have updated CHANGELOG.md for the relevant packages. (Not needed for small changes such as doc typos).
  • I have updated the pubspec package version if necessary.

@jakobkordez

Copy link
Copy Markdown
Contributor Author

@dcharkes do you mind checking this out?
Thanks

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

Package publishing

If you have publishing permissions, you can use the links below to publish the changes after merging this PR.

Package Version Status Publish tag (post-merge)
package:code_assets 1.2.1 already published at pub.dev
package:data_assets 0.20.0 already published at pub.dev
package:ffi 2.2.0 already published at pub.dev
package:hooks 2.0.2 already published at pub.dev
package:hooks_runner 1.5.1-wip WIP (no publish necessary)
package:jni_flutter 1.0.1 already published at pub.dev
package:native_toolchain_c 0.19.3 ready to publish native_toolchain_c-v0.19.3
package:record_use 0.6.1-wip WIP (no publish necessary)
package:swift2objc 0.2.0 already published at pub.dev
package:swiftgen 0.1.3-wip WIP (no publish necessary)

Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

PR Health

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
native_toolchain_c None 0.19.2 0.19.3-wip 0.19.3-wip ✔️

This check can be disabled by tagging the PR with skip-breaking-check.

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbol Leaking sources

This check can be disabled by tagging the PR with skip-leaking-check.

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

This check can be disabled by tagging the PR with skip-changelog-check.

@dcharkes dcharkes left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

arguments,
workingDirectory: workingDirectory?.toFilePath(),
environment: environment,
runInShell: Platform.isWindows && workingDirectory != null,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I don't remember why I did this. I remember it was to work around some other bug. But let's try removing it and see if anything breaks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runInShell was modified in #1759.
Check out the diff https://github.com/dart-lang/native/pull/1759/changes#diff-a9ce5e451f2dda3e3d822fa8660b26845b97441b58e55575af6673bb9e176cbeL59

Also the run_process.dart in the hooks_runner:

runInShell:
          Platform.isWindows &&
          (!includeParentEnvironment || workingDirectory != null),

It seems to be a blend of both?

Comment thread pkgs/native_toolchain_c/CHANGELOG.md Outdated
Comment thread pkgs/native_toolchain_c/CHANGELOG.md
@dcharkes dcharkes merged commit 6292be5 into dart-lang:main Jul 8, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

2 participants