Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows, foreign-library, Cabal-3.10.3.0 regression in linker #9982

Open
mpilgrem opened this issue May 6, 2024 · 5 comments
Open

Windows, foreign-library, Cabal-3.10.3.0 regression in linker #9982

mpilgrem opened this issue May 6, 2024 · 5 comments

Comments

@mpilgrem
Copy link
Collaborator

mpilgrem commented May 6, 2024

I have a simple package foo with Cabal file:

cabal-version:  2.2
name:           foo
version:        0.1.0.0
foreign-library foo
  type:             native-shared
  other-modules:    Lib
  hs-source-dirs:   src
  build-depends:    base >=4.7 && <5
  default-language: Haskell2010
  if os(windows)
    options:        standalone

With GHC 9.6.4/Cabal-3.10.1.0 it builds fine:

❯ stack --snapshot ghc-9.6.4 build
foo> configure
foo> Configuring foo-0.1.0.0...
foo> build with ghc-9.6.4
foo> Preprocessing foreign library 'foo' for foo-0.1.0.0..
foo> Building foreign library 'foo' for foo-0.1.0.0..
foo> [1 of 1] Compiling Lib
foo> [1 of 2] Compiling Lib [Flags changed]
foo> [2 of 2] Linking .stack-work\dist\ab060f89\build\foo\foo.dll

With GHC 9.6.5/Cabal-3.10.3.0 the build fails in the linker:

❯ stack --snapshot ghc-9.6.5 build
foo> configure
foo> Configuring foo-0.1.0.0...
foo> build with ghc-9.6.5
foo> Preprocessing foreign library 'foo' for foo-0.1.0.0..
foo> Building foreign library 'foo' for foo-0.1.0.0..
foo> [1 of 1] Compiling Lib
foo> [1 of 2] Compiling Lib [Flags changed]
foo> [2 of 2] Linking .stack-work\dist\eebe39f7\build\foo\foo.dll
foo> lld: error: unknown argument: -rpath
foo> lld: error: unknown argument: -rpath
foo> clang: error: linker command failed with exit code 1 (use -v to see invocation)
foo> ghc-9.6.5.exe: `clang.exe' failed in phase `Linker'. (Exit code: 1)

Error: [S-7282]
       Stack failed to execute the build plan.

       While executing the build plan, Stack encountered the error:

       [S-7011]
       While building package foo-0.1.0.0 (scroll up to its section to see the error) using:
       D:\sr\setup-exe-cache\x86_64-windows\Cabal-simple_7psHxtdj_3.10.3.0_ghc-9.6.5.exe --verbose=1 --builddir=.stack-work\dist\eebe39f7 build --ghc-options " -fdiagnostics-color=always"
       Process exited with code: ExitFailure 1

Is this a regression introduced in Cabal-3.10.3.0? I wondered if it was related to:

EDIT: I am pretty sure that this is a regession between Cabal-3.10.1.0 and Cabal-3.10.3.0 because my example builds if I force Stack to build using GHC 9.6.5 but with Cabal-3.10.1.0, using:

cabal-version:  2.2
name:           foo
version:        0.1.0.0
build-type:     Custom

custom-setup
  setup-depends:   base >= 4.7 && < 5
                 , Cabal ==3.10.1.0
                 , Cabal-syntax ==3.10.1.0

foreign-library foo
  type:             native-shared
  other-modules:    Lib
  hs-source-dirs:   src
  build-depends:    base >=4.7 && <5
  default-language: Haskell2010
  if os(windows)
    options:        standalone

EDIT2: Using the same method, it appears to me to be a regression introduced between Cabal-3.10.2.1 and Cabal-3.10.3.0.

(EDIT 3: The good news is this is not a problem for GHC 9.10.0.20240426/Cabal-3.12.0.0.)

@mpilgrem
Copy link
Collaborator Author

mpilgrem commented May 6, 2024

A difference between the two builds above is that, in the linking step, Cabal calls GHC 9.6.5 with additional arguments not present in the GHC 9.6.4 example:

"-dynload deploy" 
"-optl-Wl,-rpath,D:\sr\programs\x86_64-windows\msys2-20230526\mingw64\lib" 
"-optl-Wl,-rpath,D:\sr\programs\x86_64-windows\msys2-20230526\mingw64\bin" 

@mpilgrem
Copy link
Collaborator Author

mpilgrem commented May 6, 2024

Looking at: https://downloads.haskell.org/~ghc/9.6.5/docs/users_guide/shared_libs.html#finding-shared-libraries-at-runtime, I get the impression that -dynload deploy may be a GHC option that is not applicable on Windows.

@mpilgrem mpilgrem changed the title Windows, foreign-library, GHC 9.6.5/Cabal-3.10.3.0: lld: error: unknown argument: -rpath Windows, foreign-library, Cabal-3.10.3.0 regression in linker May 6, 2024
@juhp
Copy link
Collaborator

juhp commented May 29, 2024

Is there a corresponding ghc issue open?
(I am thinking in terms of fixing for 9.6.6 and 9.8.3 etc)

@mpilgrem
Copy link
Collaborator Author

mpilgrem commented May 29, 2024

I don't think so - looks to me like a regression introduced into Cabal, not GHC. EDIT: unless you mean something to warn the GHC developers that there is this problem with that version of Cabal?

@jasagredo
Copy link
Collaborator

This seems to work for me:

➜ cabal build
Resolving dependencies...
Build profile: -w ghc-9.6.6 -O1
In order, the following will be built (use -v for more details):
 - bb-0.1.0.0 (flib:bb) (first run)
Configuring foreign library 'bb' for bb-0.1.0.0...
Preprocessing foreign library 'bb' for bb-0.1.0.0...
Building foreign library 'bb' for bb-0.1.0.0...
[1 of 1] Compiling MyLib            ( src\MyLib.hs, C:\Users\Javier\bb\dist-newstyle\build\x86_64-windows\ghc-9.6.6\bb-0.1.0.0\f\bb\build\bb\bb-tmp\MyLib.o )
[1 of 2] Compiling MyLib            ( src\MyLib.hs, C:\Users\Javier\bb\dist-newstyle\build\x86_64-windows\ghc-9.6.6\bb-0.1.0.0\f\bb\build\bb\bb-tmp\MyLib.o ) [Flags changed]
[2 of 2] Linking C:\\Users\\Javier\\bb\\dist-newstyle\\build\\x86_64-windows\\ghc-9.6.6\\bb-0.1.0.0\\f\\bb\\build\\bb\\bb.dll

With your .cabal description above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants