Skip to content

docs: standalone foreign libs are not Windows-only - #9320

Open
andreabedini wants to merge 2 commits into
masterfrom
andreabedini-standalone-foreign-libs
Open

andreabedini wants to merge 2 commits into
masterfrom
andreabedini-standalone-foreign-libs

Conversation

@andreabedini

@andreabedini andreabedini commented Oct 9, 2023 •

Copy link
Copy Markdown
Collaborator

When describing the options: field for foreign libraries, the user guide currenlty says:

Options for building the foreign library, typically specific to the specified type of foreign library. Currently we only support standalone here. A standalone dynamic library is one that does not have any dependencies on other (Haskell) shared libraries; without the standalone option the generated library would have dependencies on the Haskell runtime library (libHSrts), the base library (libHSbase), etc. Currently, standalone must be used on Windows and must not be used on any other platform.

The phrase "standalone must be used on Windows and must not be used on any other platform" lacks enough details to let the user (or FWIW future contributors :P) understand what the issue is and what happens otherwise.

E.g.

  • When I tried to produce a standalone library on linux, the only issue I ran into was the old RPATH hack we have since removed (in Remove RPATH workaround #9164). If boot packages are built with -fPIC, producing a standalone foreign library seems to work without issues.

  • I do not have any knowledge of what can happen not using standalone on Windows (there's even a runtime assertion so one cannot check without modifying cabal). If it is something intrinsic to linking on window, I am wondering: would it make sense to make this automatic? is it worth having the user explictly write options: standalone?

The origin of the phrase seems to be Edsko's commit introducing foreign-libraries: 382143a. The commit message does not provide any further explanation other than "it is not supported":

Add support for foreign libraries.

A stanza for a platform library looks something like

    platform-library test-package
      type:                native-shared

      if os(Windows)
        options: standalone
        mod-def-file: TestPackage.def

      other-modules:       MyPlatformLib.Hello
                           MyPlatformLib.SomeBindings
      build-depends:       base >=4.7 && <4.9
      hs-source-dirs:      src
      c-sources:           csrc/MyPlatformLibWrapper.c
      default-language:    Haskell2010

where native-shared means that we want to build a native shared library
(.so on Linux, .dylib on OSX, .dll on Windows). The parser also
recognizes native-static but this is not currently supported anywhere.
The standalone option means that the we merge all library dependencies
into the dynamic library (i.e., ghc options -shared -static), rather
than make the created dynamic library just record its dependencies (ghc
options -shared -dynamic); it is currently compulsory on Windows and
unsupported anywhere else. The mod-def-file can be used to specify a
module definition file, and is also Windows specific.

There is a bit of refactoring in Build: gbuild is the old buildOrReplExe
and now deals with both executables and platform libraries.

EDIT: what about macOS? We cannot just ignore it.

EDIT 2: AFAIU this just relies on passing the right flags to GHC, so it's GHC doing the linking. In that case, whether it is supported or not is GHC responsibility more than cabal's.

Comment thread doc/cabal-package.rst Outdated
lib-version-info: 6:3:2

if os(Windows)
-- standalone *must* be used on Windows.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens otherwise?

Comment thread doc/cabal-package.rst Outdated
(``libHSbase``), etc. Currently, ``standalone`` *must* be used on Windows
and *must not* be used on any other platform.
(``libHSbase``), etc.
The ``standalone`` option *must* be used on Windows (FIXME: why? is so why is this not automatic?).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Linux, ghc boot packages need to have been compiled with -fPIC otherwise they won't be able to be statically linked in.

@andreabedini

Copy link
Copy Markdown
Collaborator Author

Tagging @bgamari and @angerman as linking experts.

@andreabedini andreabedini self-assigned this Oct 9, 2023
@andreabedini

Copy link
Copy Markdown
Collaborator Author

Ah, the good old

Error:     Ambiguous module name ‘System.Directory’:
      it was found in multiple packages:
      directory-1.3.8.1 directory-1.3.8.1
  |
3 | import System.Directory
  | ^^^^^^^^^^^^^^^^^^^^^^^

<interactive>:338:31: error:
    Not in scope: ‘Main.main’
    No module named ‘Main’ is imported.

@andreabedini andreabedini changed the title Update cabal-package.rst w.r.t standalone foreign librs Update cabal-package.rst w.r.t standalone foreign libs Oct 12, 2023
@andreabedini
andreabedini force-pushed the andreabedini-standalone-foreign-libs branch from 5375e31 to 568a42b Compare November 21, 2023 02:54
@andreabedini

Copy link
Copy Markdown
Collaborator Author

@BinderDavid @malteneus Would you mind looking at this from a documentation point-of-view?
@Mikolaj @ulysses4ever @Kleidukos What should we do here? I think standalone foreign-libs work on Linux but I haven't managed to track down the origin of the original statement.

@andreabedini
andreabedini marked this pull request as ready for review November 21, 2023 02:56
@andreabedini

Copy link
Copy Markdown
Collaborator Author

These are some notes from the investigation I did some months ago
https://gist.github.com/andreabedini/a3b012345124854c2fe58380dfe3d4ae

Comment thread doc/cabal-package-description-file.rst Outdated
Comment thread doc/cabal-package-description-file.rst Outdated
@angerman

Copy link
Copy Markdown
Collaborator

We should probably note that option: standalone might change in the future on windows if and once we support dynamic libraries? (Again assuming my understanding is correct).

This does highlight an issue I experienced with linking static windows libraries when going from 8.10 to 9.6 (and thus also newer cabal) I think.

@ulysses4ever

Copy link
Copy Markdown
Collaborator

@andreabedini do you see a path forward here? @angerman were all of your comments addressed?

@ulysses4ever

Copy link
Copy Markdown
Collaborator

@ulysses4ever What should we do here? I think standalone foreign-libs work on Linux but I haven't managed to track down the origin of the original statement.

I have not a slightest idea about foreign libs, I'm sorry to say!

@andreabedini

Copy link
Copy Markdown
Collaborator Author

I found this GHC ticket which seems relevant.

@andreabedini andreabedini added merge me Tell Mergify Bot to merge and removed attention: needs-review merge me Tell Mergify Bot to merge labels Dec 2, 2024
@andreabedini
andreabedini force-pushed the andreabedini-standalone-foreign-libs branch from 568a42b to d2cb800 Compare July 28, 2026 03:23
Copilot AI review requested due to automatic review settings July 28, 2026 03:23
@andreabedini andreabedini changed the title Update cabal-package.rst w.r.t standalone foreign libs docs: standalone foreign libs are not Windows-only Jul 28, 2026
@andreabedini andreabedini added the merge me Tell Mergify Bot to merge label Jul 28, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Cabal user guide’s description of the foreign-library options: field to remove the claim that standalone is forbidden on non-Windows platforms, and to better frame the Windows-specific requirements.

Changes:

  • Adjusted the narrative text for options: standalone to drop “must not be used on any other platform”.
  • Added an inline comment in the example if os(Windows) stanza to call out the Windows requirement.
Comments suppressed due to low confidence (1)

doc/cabal-package-description-file.rst:2231

  • This paragraph still doesn’t clearly communicate that the restriction is specifically that non-standalone foreign libraries are rejected on Windows by Cabal (see Configure.hs:3135–3141). Consider wording it as a Cabal limitation and explicitly noting that the option is otherwise optional, which aligns with the current implementation (no non-Windows prohibition).
   the ``standalone`` option the generated library would have dependencies
   on the Haskell runtime library (``libHSrts``), the base library
   (``libHSbase``), etc. The ``standalone`` option *must* be used on Windows.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread doc/cabal-package-description-file.rst Outdated
@mergify mergify Bot added the ready and waiting Mergify is waiting out the cooldown period label Jul 28, 2026
@mergify mergify Bot added merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days waiting too long automatically set by Mergify to trigger a warning labels Jul 30, 2026
@andreabedini
andreabedini force-pushed the andreabedini-standalone-foreign-libs branch from d2cb800 to a5c50bd Compare August 6, 2026 06:01
@Mikolaj

Mikolaj commented Aug 6, 2026

Copy link
Copy Markdown
Member

@andreabedini: the UI says "All comments must be resolved."

andreabedini and others added 2 commits October 9, 2026 17:23
Correct the foreign-library documentation: the standalone option is
required on Windows but is permitted (and meaningful) on other
platforms too, so drop the inaccurate "must not be used on any other
platform" claim.
…tion

Match the wording of the configure-time error in
Distribution.Simple.Configure rather than implying an inherent Windows
requirement.
@andreabedini
andreabedini force-pushed the andreabedini-standalone-foreign-libs branch from 00cda47 to 7638c5b Compare October 9, 2026 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days merge me Tell Mergify Bot to merge ready and waiting Mergify is waiting out the cooldown period waiting too long automatically set by Mergify to trigger a warning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants