Skip to content

Concatenation of mains from conditional branches #6973

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

Closed
georgefst opened this issue Jul 19, 2020 · 3 comments
Closed

Concatenation of mains from conditional branches #6973

georgefst opened this issue Jul 19, 2020 · 3 comments

Comments

@georgefst
Copy link

I have an executable which requires slightly different top-level code on different platforms. I have:

    if os(windows)
        main-is: Windows.hs
    if os(linux)
        main-is: Linux.hs

which I thought was a relatively nice solution, but unfortunately I get the rather nonsensical error:

cabal: Windows.hsLinux.hs doesn't exist

Obviously there are various ways to work around this, but it would be great if it just worked.

@georgefst
Copy link
Author

georgefst commented Jul 20, 2020

Investigating slightly further:

  • This actually works fine with repl, build, run, but not install.
  • The lack of an 'else' branch isn't the problem - changing if os(linux) to else makes no difference.
  • Neither is the mismatch of file and module name - changing everything to Main.hs just gives cabal: Main.hsMain.hs doesn't exist.

@phadej
Copy link
Collaborator

phadej commented Jul 20, 2020

Duplicate of #3313

A workaround is to have dummy Main.is

module Main (main) where
import RealMain (main)

and put RealMains into different source-directories:

main-is: Main.hs

-- most sources are here
hs-source-dirs: src/

-- but RealMain has multiple implementations:
if os(windows)
  hs-source-dirs: windows/
If os(linux)
  hs-source-dirs: linux/

other-modules: RealMain

...

@phadej phadej closed this as completed Jul 20, 2020
@georgefst
Copy link
Author

Ah thanks, I did do a quick search but missed that one somehow.

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

No branches or pull requests

2 participants