feat: run link and archive in parallel via argv spawn#1300
Open
krystophny wants to merge 3 commits into
Open
Conversation
Extend the argv-based Fortran compile spawn to Windows so it no longer falls back to the shell there. Tokenize with the OS-native lexer (ms_split on Windows, sh_split on Unix) so backslash paths and quoting survive, route run_argv through c_run_argv on both platforms, and add a CreateProcessA path with per-process stdout/stderr redirect. The shell run remains as a fallback when the spawn returns a negative status. Windows std handles are only overridden when redirecting, to avoid stripping the child console; out-of-range child exit codes are clamped positive so they are not mistaken for the spawn-failure sentinel.
Replace the shell run() in link_executable/link_shared/make_archive with an argv spawn through run_argv (posix_spawn on Unix, CreateProcess on Windows), which is fork-safe under OpenMP, and drop the critical(run_command) that previously serialized them. Link and archive steps now run in parallel; the rare shell fallback (tokenization failure) and run_argv's own shell fallback stay serialized under critical(run_command). make_archive reproduces 'self%ar // output' exactly: the archive name glues onto the last flag token for MSVC 'lib /OUT:' and is a separate token for GNU 'ar -rs '. Promote split_append/clean_shlex_token to module scope so link/archive reuse the compile path tokenization.
This was referenced Jun 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
run_argvinstead of shelling out, so the
critical(run_command)serialization isdropped and link/archive run concurrently under OpenMP
critical(run_command)since those still forksplit_append/clean_shlex_tokenpromoted to module scope so link andarchive reuse the compile path's OS-native tokenization
Context
Commit
bb891e3fwrapped link/archive incritical(run_command)because theirrun()shells out and concurrent fork from OpenMP threads is not safe. Thisserializes all linking and archiving. After the argv Fortran compile migration
(#1299), this change extends the safe spawn path to link and archive.
Merge order
This is PR 2 of 3 in the argv spawn chain. Merge in order:
Note: Until #1299 merges, the diff for this PR includes its commits.
After merge, rebase will show only this PR's own commit.
Refs: #962
Verification
A fresh sample project compiles, archives (libargvtest2.a), links, and runs
through the new argv archive+link path.