flang: update support and add flang-rt#452306
Conversation
|
Continuing the work from @picostove's seemly inactive PR #391942. Requesting reviews from original reviewers in case I miss something. Any feedback would be greatly appreciated. |
|
Build took an extremely long time. wasn't expecting this though |
|
|
I think I just ran into a bug with nixpkgs-review, the build is still running. |
|
alyssais
left a comment
There was a problem hiding this comment.
I think this should be split into multiple commits. There's a lot going on here.
ff9c766 to
1c38124
Compare
I've updated the wrapper to explicitly filter -nostdlibinc, and rewrite @file arguments to a tmp file. |
|
It works for me too now |
Great. Let's see if someone could help with merging. |
There was a problem hiding this comment.
Pull request overview
Updates the LLVM Flang Fortran toolchain packaging to include the new flang-rt runtime and adjusts cc-wrapper/toolchain plumbing so Flang can be used as a wrapped compiler in nixpkgs (including handling Flang’s -fc1 mode).
Changes:
- Update
flangpackaging to includeflang-rtsources and export language capability passthru flags forcc-wrapper. - Add a new
flang-rtderivation (runtime library) and wire it into the LLVM toolchain set. - Extend
cc-wrapperto recognize-fc1ascc1-like and add initial Fortran wrapper support forflang.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| pkgs/development/compilers/llvm/common/flang/default.nix | Adds flang-rt to the extracted monorepo source and exports passthru.lang* fields for wrapper behavior. |
| pkgs/development/compilers/llvm/common/flang-rt/default.nix | Introduces the flang-rt runtime build from LLVM runtimes. |
| pkgs/development/compilers/llvm/common/default.nix | Adds flang-unwrapped, flang-rt, and a Flang adapter wrapper; wires wrapped flang to include runtime libs. |
| pkgs/development/compilers/llvm/common/clang/default.nix | Explicitly marks clang as providing C and C++. |
| pkgs/build-support/cc-wrapper/default.nix | Updates Fortran wrapping logic to optionally wrap flang; adjusts a libc++ flags condition to use cc.langCC. |
| pkgs/build-support/cc-wrapper/cc-wrapper.sh | Treats -fc1 like -cc1 to avoid injecting wrapper flags in that mode. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Build on the initial LLVM Flang wrapper work by exposing the needed clang passthru and teaching cc-wrapper about flang-specific flag handling. Co-authored-by: stove <stove@rivosinc.com> Co-authored-by: acture <acture@gmail.com> Co-authored-by: Emily <hello@emily.moe> Co-authored-by: Philip Taron <philip.taron@gmail.com>
Build on the initial LLVM Flang runtime packaging work and carry the final runtime build settings needed by the current branch state. Co-authored-by: stove <stove@rivosinc.com> Co-authored-by: acture <acture@gmail.com>
Build on the earlier standalone flang work by wiring flang into llvmPackages, carrying the LLVM 21 driver compatibility patches, and adding focused wrapper/driver tests. Co-authored-by: stove <stove@rivosinc.com> Co-authored-by: acture <acture@gmail.com> Co-authored-by: Alyssa Ross <hi@alyssa.is>
|
@alyssais I've reworked the approach based on your feedback. The standalone wrapper script is gone. Instead of silently dropping flags, the new revision handles flag compatibility at three levels:
No user-supplied flags are dropped. Flags that flang doesn't support either produce a proper diagnostic (via backported patches) or are never injected in the first place (via cc-wrapper / hardeningUnsupportedFlags). Ready for another look when you have time. |
|
@emilazy Take a look when you have time. It seems |
MLIRConfig.cmake unconditionally overwrites MLIR_TABLEGEN_EXE and does not create an imported target, breaking standalone builds that provide their own mlir-tblgen binary (e.g. Nix sandboxed builds). Add guards to respect caller-set values and create an imported mlir-tblgen target automatically. Remove the now-unnecessary dummy target workaround from the flang package. See: llvm/llvm-project#150986
flang-rt's runtimes build does not consume CLANG_DIR or MLIR_DIR, and does not link against MLIR or libclang. Remove the unused inputs and the empty dev output.
Co-authored-by: Alexander Bantyev <balsoft@balsoft.ru>
|
I think I won’t be able to get around to re‐reviewing this PR in a timely manner – apologies! – so I’ve dismissed my blocking review to not hold it up. (Looks like @alyssais still has a blocking review, though.) |
Supersedes #391942
Summary
Package LLVM Flang as a first-class Fortran compiler in nixpkgs, with runtime library, cc-wrapper integration, and driver compatibility patches backported from upstream.
Based on the excellent initial implementation by @picostove.
Key Changes
Packages:
cc-wrapper integration:
Driver patches (backported from upstream):
MLIR: fix MLIRConfig.cmake for standalone builds
MLIRConfig.cmake unconditionally overwrites
MLIR_TABLEGEN_EXE, breaking standalonebuilds that provide their own pre-built
mlir-tblgen(e.g. in Nix sandboxed builds).The patch adds guards to respect caller-set values and auto-creates an imported
mlir-tblgentarget for downstream consumers. This replaces the previous dummy targetworkaround in flang's CMakeLists.txt.
Upstream issue: llvm/llvm-project#150986
flang-rt: remove unused dependencies
flang-rt does not link against MLIR or libclang; removed unused
CLANG_DIR/MLIR_DIRcmake flags, build inputs, and the empty
devoutput.Tests:
Design
No user-supplied flags are silently dropped. Flag incompatibility is handled at three layers:
Test plan
nix-build -A llvmPackages_21.flangnix-build -A llvmPackages_21.flang-rtnix-build -A llvmPackages_21.flang.passthru.tests.compile-smokenix-build -A llvmPackages_21.flang.passthru.tests.driver-flagsChecklist
nix fmt.