From 6375e014a22aeab17e687f36849acc9ca3eb434d Mon Sep 17 00:00:00 2001 From: Ilya Baryshnikov Date: Mon, 24 Aug 2026 18:00:40 +0300 Subject: [PATCH] Adding an explicit pgma flag for interaction with GHC --- Cabal/src/Distribution/Simple/GHC/Internal.hs | 1 + Cabal/src/Distribution/Simple/Program/GHC.hs | 3 +++ .../PackageTests/FFI/ForeignOptsPgma/Main.hs | 15 ++++++++++++++ .../FFI/ForeignOptsPgma/README.md | 7 +++++++ .../abits/asmlib_aarch64_darwin.S | 11 ++++++++++ .../abits/asmlib_x86_64_darwin.asm | 6 ++++++ .../abits/asmlib_x86_64_linux.S | 7 +++++++ .../abits/asmlib_x86_64_windows.S | 6 ++++++ .../FFI/ForeignOptsPgma/abits/pgma.h | 6 ++++++ .../FFI/ForeignOptsPgma/cabal.out | 0 .../FFI/ForeignOptsPgma/cabal.project | 1 + .../FFI/ForeignOptsPgma/cabal.test.hs | 8 ++++++++ .../ForeignOptsPgma/foreign-opts-pgma.cabal | 20 +++++++++++++++++++ .../FFI/ForeignOptsPgma/scripts/as-wrapper.sh | 4 ++++ .../ShowBuildInfo/Complex/single.out | 8 ++++---- .../src/Test/Cabal/OutputNormalizer.hs | 6 +++++- changelog.d/11764.md | 8 ++++++++ 17 files changed, 112 insertions(+), 5 deletions(-) create mode 100644 cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/Main.hs create mode 100644 cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/README.md create mode 100644 cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/abits/asmlib_aarch64_darwin.S create mode 100644 cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/abits/asmlib_x86_64_darwin.asm create mode 100644 cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/abits/asmlib_x86_64_linux.S create mode 100644 cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/abits/asmlib_x86_64_windows.S create mode 100644 cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/abits/pgma.h create mode 100644 cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/cabal.out create mode 100644 cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/cabal.project create mode 100644 cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/cabal.test.hs create mode 100644 cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/foreign-opts-pgma.cabal create mode 100755 cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/scripts/as-wrapper.sh create mode 100644 changelog.d/11764.md diff --git a/Cabal/src/Distribution/Simple/GHC/Internal.hs b/Cabal/src/Distribution/Simple/GHC/Internal.hs index 6959b8f48b6..84297424b6a 100644 --- a/Cabal/src/Distribution/Simple/GHC/Internal.hs +++ b/Cabal/src/Distribution/Simple/GHC/Internal.hs @@ -597,6 +597,7 @@ linkGhcOptions verbosity lbi bi clbi = (mkVersion [9, 4]) (compiler lbi) (maybeToFlag $ programPath <$> lookupProgram gppProgram (withPrograms lbi)) + , ghcOptAsProgram = maybeToFlag $ programPath <$> lookupProgram gccProgram (withPrograms lbi) } where exe_paths = diff --git a/Cabal/src/Distribution/Simple/Program/GHC.hs b/Cabal/src/Distribution/Simple/Program/GHC.hs index 1b6a1857d11..5a6d6697f21 100644 --- a/Cabal/src/Distribution/Simple/Program/GHC.hs +++ b/Cabal/src/Distribution/Simple/Program/GHC.hs @@ -532,6 +532,8 @@ data GhcOptions = GhcOptions -- ^ Program to use for the C compiler; the @ghc -pgmc@ flag. , ghcOptGppProgram :: Flag FilePath -- ^ Program to use for the C++ compiler; the @ghc -pgmcxx@ flag. + , ghcOptAsProgram :: Flag FilePath + -- ^ Program to use for the Assembler; the @ghc -pgma@ flag. , ---------------------------- -- Language and extensions @@ -889,6 +891,7 @@ renderGhcOptions comp _platform@(Platform _arch os) opts , ["-opta" ++ opt | opt <- ghcOptAsmOptions opts] , concat [["-pgmc", cc] | cc <- flag ghcOptCcProgram] , concat [["-pgmcxx", cxx] | cxx <- flag ghcOptGppProgram] + , concat [["-pgma", as] | as <- flag ghcOptAsProgram] , ----------------- -- Linker stuff diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/Main.hs b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/Main.hs new file mode 100644 index 00000000000..1c5836c0f75 --- /dev/null +++ b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/Main.hs @@ -0,0 +1,15 @@ +{-# LANGUAGE ForeignFunctionInterface #-} + +module Main where + +import Foreign.C (CInt (..)) + +foreign import ccall "pgma.h meaning_of_life_asm" + meaning_of_life_asm :: IO CInt + +main :: IO () +main = do + secret <- meaning_of_life_asm + if secret == 33 + then putStrLn ("The secret is " ++ show secret) + else error ("Expected value 33, got " ++ show secret) diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/README.md b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/README.md new file mode 100644 index 00000000000..c32929eed13 --- /dev/null +++ b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/README.md @@ -0,0 +1,7 @@ +# ForeignOptsPgma + +This test case asserts that cabal passes the `-pgma` GHC option to override the assembler program. + +The cabal file sets `ghc-options: -pgma scripts/as-wrapper.sh`, pointing GHC at a shell script wrapper (`scripts/as-wrapper.sh`) instead of the system assembler program. The wrapper adds `--defsym meaning_of_life_val=33` to every compilation and then delegates to the real `as`. The assembler source requires `meaning_of_life_val` to be defined; if the wrapper is not used as the assembler program, the build fails. + +This test is skipped on Windows (no POSIX shell). diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/abits/asmlib_aarch64_darwin.S b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/abits/asmlib_aarch64_darwin.S new file mode 100644 index 00000000000..3a13064e4cc --- /dev/null +++ b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/abits/asmlib_aarch64_darwin.S @@ -0,0 +1,11 @@ + # macOS/AArch64 (Mach-O) + .macro func name + .globl _\name +_\name: + .endm + + .text + func meaning_of_life_asm + + mov w0, #MEANING_OF_LIFE_VAL + ret \ No newline at end of file diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/abits/asmlib_x86_64_darwin.asm b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/abits/asmlib_x86_64_darwin.asm new file mode 100644 index 00000000000..95d5e79b130 --- /dev/null +++ b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/abits/asmlib_x86_64_darwin.asm @@ -0,0 +1,6 @@ +section .text +global meaning_of_life_asm + +meaning_of_life_asm: + mov eax, meaning_of_life_val + ret \ No newline at end of file diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/abits/asmlib_x86_64_linux.S b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/abits/asmlib_x86_64_linux.S new file mode 100644 index 00000000000..2c1dfb2f758 --- /dev/null +++ b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/abits/asmlib_x86_64_linux.S @@ -0,0 +1,7 @@ + .text + .globl meaning_of_life_asm + .type meaning_of_life_asm, @function +meaning_of_life_asm: + movl $MEANING_OF_LIFE_VAL, %eax + ret + .size meaning_of_life_asm, .-meaning_of_life_asm \ No newline at end of file diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/abits/asmlib_x86_64_windows.S b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/abits/asmlib_x86_64_windows.S new file mode 100644 index 00000000000..0669d7acfd7 --- /dev/null +++ b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/abits/asmlib_x86_64_windows.S @@ -0,0 +1,6 @@ + .text + .globl meaning_of_life_asm + +meaning_of_life_asm: + movl $MEANING_OF_LIFE_VAL, %eax + ret \ No newline at end of file diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/abits/pgma.h b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/abits/pgma.h new file mode 100644 index 00000000000..ff412994d3a --- /dev/null +++ b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/abits/pgma.h @@ -0,0 +1,6 @@ +#ifndef PGMALIB_H +#define PGMALIB_H + +int meaning_of_life_asm(); + +#endif diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/cabal.out b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/cabal.out new file mode 100644 index 00000000000..e69de29bb2d diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/cabal.project b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/cabal.project new file mode 100644 index 00000000000..e6fdbadb439 --- /dev/null +++ b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/cabal.project @@ -0,0 +1 @@ +packages: . diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/cabal.test.hs b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/cabal.test.hs new file mode 100644 index 00000000000..bc64ce40b01 --- /dev/null +++ b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/cabal.test.hs @@ -0,0 +1,8 @@ +import Test.Cabal.Prelude + +main = do + cabalTest $ recordMode DoNotRecord $ do + cwd <- fmap testCurrentDir getTestEnv + let wrapper = cwd "scripts/as-wrapper.sh" + cabal "v2-build" ["foreign-opts-pgma-exe"] + withPlan $ runPlanExe "foreign-opts-pgma" "foreign-opts-pgma-exe" [] diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/foreign-opts-pgma.cabal b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/foreign-opts-pgma.cabal new file mode 100644 index 00000000000..66e378549e7 --- /dev/null +++ b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/foreign-opts-pgma.cabal @@ -0,0 +1,20 @@ +cabal-version: 3.0 +name: foreign-opts-pgma +version: 0.1 +build-type: Simple + +executable foreign-opts-pgma-exe + main-is: Main.hs + build-depends: base + default-language: Haskell2010 + include-dirs: abits + if os(windows) + asm-sources: abits/asmlib_x86_64_windows.S + elif os(darwin) + asm-sources: abits/asmlib_x86_64_darwin.asm + asm-options: -d meaning_of_life_val=33 + elif os(aarch64) + asm-sources: abits/asmlib_aarch64_darwin.S + elif os(linux) + asm-sources: abits/asmlib_x86_64_linux.S + ghc-options: -pgma scripts/as-wrapper.sh diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/scripts/as-wrapper.sh b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/scripts/as-wrapper.sh new file mode 100755 index 00000000000..ddbf239a6ff --- /dev/null +++ b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgma/scripts/as-wrapper.sh @@ -0,0 +1,4 @@ +#!/bin/sh +# Wrapper around `as` that adds --d meaning_of_life_val=33 to every compilation. +# Used by the ForeignOptsPgma test to verify that -pgma selects this wrapper. +exec nasm -f macho64 "$@" diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single.out b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single.out index 1d21331c5fa..eb53178eaac 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single.out +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single.out @@ -15,11 +15,11 @@ Warning: Complex [unknown-directory] 'hs-source-dirs: doesnt-exist' specifies a Preprocessing executable 'Complex' for Complex-0.1.0.0... Building executable 'Complex' for Complex-0.1.0.0... # show-build-info Complex exe:Complex -{"cabal-lib-version":"","compiler":{"flavour":"ghc","compiler-id":"ghc-","path":""},"components":[{"type":"exe","name":"exe:Complex","unit-id":"Complex-0.1.0.0-inplace-Complex","compiler-args":["-fbuilding-cabal-package","-O","-outputdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-odir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-hidir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-hiedir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/extra-compilation-artifacts/hie","-stubdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-i","-iapp","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/Complex/autogen","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/Complex/autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-optP-include","-optPsingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/Complex/autogen/cabal_macros.h","-pgmc","","-pgmcxx","","-this-unit-id","Complex-0.1.0.0-inplace-Complex","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/single.dist/home/.cabal/store/ghc-/package.db","-package-db","/single.dist/work/dist/packagedb/ghc-","-package-id","","-package-id","","-XHaskell2010","-threaded","-rtsopts","-with-rtsopts=-N -T","-Wredundant-constraints"],"modules":["Other","Paths_Complex"],"src-files":["Main.lhs"],"hs-src-dirs":["app"],"src-dir":"/","cabal-file":"Complex.cabal"}]} +{"cabal-lib-version":"","compiler":{"flavour":"ghc","compiler-id":"ghc-","path":""},"components":[{"type":"exe","name":"exe:Complex","unit-id":"Complex-0.1.0.0-inplace-Complex","compiler-args":["-fbuilding-cabal-package","-O","-outputdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-odir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-hidir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-hiedir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/extra-compilation-artifacts/hie","-stubdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-i","-iapp","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/Complex/autogen","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/Complex/autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-optP-include","-optPsingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/Complex/autogen/cabal_macros.h","-pgmc","","-pgmcxx","","-pgma","","-this-unit-id","Complex-0.1.0.0-inplace-Complex","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/single.dist/home/.cabal/store/ghc-/package.db","-package-db","/single.dist/work/dist/packagedb/ghc-","-package-id","","-package-id","","-XHaskell2010","-threaded","-rtsopts","-with-rtsopts=-N -T","-Wredundant-constraints"],"modules":["Other","Paths_Complex"],"src-files":["Main.lhs"],"hs-src-dirs":["app"],"src-dir":"/","cabal-file":"Complex.cabal"}]} # cabal build Up to date # show-build-info Complex lib -{"cabal-lib-version":"","compiler":{"flavour":"ghc","compiler-id":"ghc-","path":""},"components":[{"type":"lib","name":"lib","unit-id":"Complex-0.1.0.0-inplace","compiler-args":["-fbuilding-cabal-package","-O","-outputdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-odir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-hidir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-hiedir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/extra-compilation-artifacts/hie","-stubdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-i","-isrc","-idoesnt-exist","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/autogen","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-optP-include","-optPsingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/autogen/cabal_macros.h","-pgmc","","-pgmcxx","","-this-unit-id","Complex-0.1.0.0-inplace","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/single.dist/home/.cabal/store/ghc-/package.db","-package-db","/single.dist/work/dist/packagedb/ghc-","-package-id","","-XHaskell2010","-Wall"],"modules":["A","B","C","D","Paths_Complex"],"src-files":[],"hs-src-dirs":["src","doesnt-exist"],"src-dir":"/","cabal-file":"Complex.cabal"}]} +{"cabal-lib-version":"","compiler":{"flavour":"ghc","compiler-id":"ghc-","path":""},"components":[{"type":"lib","name":"lib","unit-id":"Complex-0.1.0.0-inplace","compiler-args":["-fbuilding-cabal-package","-O","-outputdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-odir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-hidir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-hiedir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/extra-compilation-artifacts/hie","-stubdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-i","-isrc","-idoesnt-exist","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/autogen","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-optP-include","-optPsingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/autogen/cabal_macros.h","-pgmc","","-pgmcxx","","-pgma","","-this-unit-id","Complex-0.1.0.0-inplace","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/single.dist/home/.cabal/store/ghc-/package.db","-package-db","/single.dist/work/dist/packagedb/ghc-","-package-id","","-XHaskell2010","-Wall"],"modules":["A","B","C","D","Paths_Complex"],"src-files":[],"hs-src-dirs":["src","doesnt-exist"],"src-dir":"/","cabal-file":"Complex.cabal"}]} # cabal build Build profile: -w ghc- -O1 In order, the following will be built: @@ -34,7 +34,7 @@ Warning: Complex [unknown-directory] 'hs-source-dirs: doesnt-exist' specifies a Preprocessing benchmark 'complex-benchmarks' for Complex-0.1.0.0... Building benchmark 'complex-benchmarks' for Complex-0.1.0.0... # show-build-info Complex bench:complex-benchmarks -{"cabal-lib-version":"","compiler":{"flavour":"ghc","compiler-id":"ghc-","path":""},"components":[{"type":"bench","name":"bench:complex-benchmarks","unit-id":"Complex-0.1.0.0-inplace-complex-benchmarks","compiler-args":["-fbuilding-cabal-package","-O","-outputdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-odir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-hidir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-hiedir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/extra-compilation-artifacts/hie","-stubdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-i","-ibenchmark","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/complex-benchmarks/autogen","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/complex-benchmarks/autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-optP-include","-optPsingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/complex-benchmarks/autogen/cabal_macros.h","-pgmc","","-pgmcxx","","-this-unit-id","Complex-0.1.0.0-inplace-complex-benchmarks","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/single.dist/home/.cabal/store/ghc-/package.db","-package-db","/single.dist/work/dist/packagedb/ghc-","-package-id","","-package-id","","-package-id","","-XHaskell2010","-Wall","-rtsopts","-threaded","-with-rtsopts=-N"],"modules":["Paths_Complex"],"src-files":["Main.hs"],"hs-src-dirs":["benchmark"],"src-dir":"/","cabal-file":"Complex.cabal"}]} +{"cabal-lib-version":"","compiler":{"flavour":"ghc","compiler-id":"ghc-","path":""},"components":[{"type":"bench","name":"bench:complex-benchmarks","unit-id":"Complex-0.1.0.0-inplace-complex-benchmarks","compiler-args":["-fbuilding-cabal-package","-O","-outputdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-odir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-hidir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-hiedir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/extra-compilation-artifacts/hie","-stubdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-i","-ibenchmark","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/complex-benchmarks/autogen","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/complex-benchmarks/autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-optP-include","-optPsingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/complex-benchmarks/autogen/cabal_macros.h","-pgmc","","-pgmcxx","","-pgma","","-this-unit-id","Complex-0.1.0.0-inplace-complex-benchmarks","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/single.dist/home/.cabal/store/ghc-/package.db","-package-db","/single.dist/work/dist/packagedb/ghc-","-package-id","","-package-id","","-package-id","","-XHaskell2010","-Wall","-rtsopts","-threaded","-with-rtsopts=-N"],"modules":["Paths_Complex"],"src-files":["Main.hs"],"hs-src-dirs":["benchmark"],"src-dir":"/","cabal-file":"Complex.cabal"}]} # cabal build Build profile: -w ghc- -O1 In order, the following will be built: @@ -49,7 +49,7 @@ Warning: Complex [unknown-directory] 'hs-source-dirs: doesnt-exist' specifies a Preprocessing test suite 'func-test' for Complex-0.1.0.0... Building test suite 'func-test' for Complex-0.1.0.0... # show-build-info Complex test:func-test -{"cabal-lib-version":"","compiler":{"flavour":"ghc","compiler-id":"ghc-","path":""},"components":[{"type":"test","name":"test:func-test","unit-id":"Complex-0.1.0.0-inplace-func-test","compiler-args":["-fbuilding-cabal-package","-O","-outputdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-odir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-hidir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-hiedir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/extra-compilation-artifacts/hie","-stubdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-i","-itest","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/func-test/autogen","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/func-test/autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-optP-include","-optPsingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/func-test/autogen/cabal_macros.h","-pgmc","","-pgmcxx","","-this-unit-id","Complex-0.1.0.0-inplace-func-test","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/single.dist/home/.cabal/store/ghc-/package.db","-package-db","/single.dist/work/dist/packagedb/ghc-","-package-id","","-package-id","","-package-id","","-XHaskell2010"],"modules":[],"src-files":["FuncMain.hs"],"hs-src-dirs":["test"],"src-dir":"/","cabal-file":"Complex.cabal"}]} +{"cabal-lib-version":"","compiler":{"flavour":"ghc","compiler-id":"ghc-","path":""},"components":[{"type":"test","name":"test:func-test","unit-id":"Complex-0.1.0.0-inplace-func-test","compiler-args":["-fbuilding-cabal-package","-O","-outputdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-odir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-hidir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-hiedir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/extra-compilation-artifacts/hie","-stubdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-i","-itest","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/func-test/autogen","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/func-test/autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-optP-include","-optPsingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/func-test/autogen/cabal_macros.h","-pgmc","","-pgmcxx","","-pgma","","-this-unit-id","Complex-0.1.0.0-inplace-func-test","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/single.dist/home/.cabal/store/ghc-/package.db","-package-db","/single.dist/work/dist/packagedb/ghc-","-package-id","","-package-id","","-package-id","","-XHaskell2010"],"modules":[],"src-files":["FuncMain.hs"],"hs-src-dirs":["test"],"src-dir":"/","cabal-file":"Complex.cabal"}]} # cabal build Build profile: -w ghc- -O1 In order, the following will be built: diff --git a/cabal-testsuite/src/Test/Cabal/OutputNormalizer.hs b/cabal-testsuite/src/Test/Cabal/OutputNormalizer.hs index 67b450dd0fb..05bba96e8f2 100644 --- a/cabal-testsuite/src/Test/Cabal/OutputNormalizer.hs +++ b/cabal-testsuite/src/Test/Cabal/OutputNormalizer.hs @@ -15,7 +15,7 @@ import Data.Array ((!)) import Text.Regex.Base import Text.Regex.TDFA -import qualified Data.Foldable as F +import Data.Foldable qualified as F normalizeOutput :: NormalizerEnv -> String -> String normalizeOutput nenv = @@ -138,6 +138,10 @@ normalizeOutput nenv = . resub "\"-pgmcxx\",\"[^\"]+\"" "\"-pgmcxx\",\"\"" + -- Normalize the assembler compiler path embedded in -pgma. + . resub + "\"-pgma\",\"[^\"]+\"" + "\"-pgma\",\"\"" -- Remove cabal version output from show-build-info output . resub ("{\"cabal-lib-version\":\"" ++ posixRegexEscape (display (normalizerCabalVersion nenv)) ++ "\"") diff --git a/changelog.d/11764.md b/changelog.d/11764.md new file mode 100644 index 00000000000..ae133a7fc44 --- /dev/null +++ b/changelog.d/11764.md @@ -0,0 +1,8 @@ +--- +synopsis: Add explicit `pgma` flag for GHC invocation +packages: [Cabal] +prs: 11764 +--- +Add an explicit `pgma` flag to Cabal's GHC invocation logic. Pass the assembler +program explicitly to GHC. This change allows users to specify a custom `as` +program to compile assembly manually.