Skip to content

Add the -dynamic flag and update build instructions #2668

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

Merged
merged 5 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ jobs:
echo "tests: false" >> cabal.project.local
echo "benchmarks: false" >> cabal.project.local

- name: Disable -dynamic
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we disable it here?

Copy link
Member

@hasufell hasufell Jan 31, 2022

Choose a reason for hiding this comment

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

Release builds are static (makes distribution easier), but we tell users to build dynamic. ..it's all quite confusing 😄

Afaiu static builds work fine as long as you use an official GHC bindist (does it work across ubuntu vs fedora bindists?)...otherwise TH may break.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We want to build static binaries for ease of distribution. Sadly static binaries are no good for loading code dynamically, which is needed for compiling TH code.

Copy link
Member

Choose a reason for hiding this comment

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

At this point tbh i am not sure if makes sense provide static binaries for linux/macOS if we are asking users build from source, showing a warning every time they open hls, which only can be removed doing it.
Given how extended is the use of TH in the ecosystem, only very beginners and ejem exotic code bases :-P are not using it.

Well i suppose we can keep them with the hope a better solution comes from ghc sooner or later.

Copy link
Member

Choose a reason for hiding this comment

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

Afaiu static builds work fine as long as you use an official GHC bindist (does it work across ubuntu vs fedora bindists?)...otherwise TH may break.

Yeah i guess those are the users who had th working but have to close the warning or build hls from source without needing it.

run: |
echo "package haskell-language-server" >> cabal.project.local
echo " flags: -dynamic" >> cabal.project.local

- uses: ./.github/actions/setup-build
with:
ghc: ${{ matrix.ghc }}
Expand Down
14 changes: 7 additions & 7 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,34 +165,34 @@ Using an explicit `hie.yaml` to configure the cradle can resolve the problem, se
Static binaries use the GHC linker for dynamically loading dependencies when typechecking TH code, and this can run into issues when loading shared objects linked against mismatching system libraries, or into GHC linker bugs (mainly the Mach linker used in Mac OS, but also potentially the ELF linker).
Dynamically linked binaries (including`ghci`) use the system linker instead of the GHC linker and avoid both issues.

The easiest way to obtain a dynamically linked HLS binary is to build it locally. With `cabal` this can be done as follows:
The easiest way to obtain a dynamically linked HLS binary is to build HLS locally. With `cabal` this can be done as follows:

```bash
cabal update && cabal install pkg:haskell-language-server --ghc-options="-dynamic"
cabal update && cabal install pkg:haskell-language-server"
```

If you are compiling with a ghc version with a specific `cabal-ghc${ghcVersion}.project` in the repo you will have to use it. For example for ghc-9.0.x:

```bash
cabal update && cabal install pkg:haskell-language-server --project-file=cabal-ghc90.project --ghc-options="-dynamic"
cabal update && cabal install pkg:haskell-language-server --project-file=cabal-ghc90.project"
```

With `stack` you also need add the ghc option `-dynamic`.
Or with `stack`:

```bash
stack install haskell-language-server --stack-yaml=stack-${ghcVersion}.yaml --ghc-options="-dynamic"
stack install haskell-language-server --stack-yaml=stack-${ghcVersion}.yaml"
```

You also can leverage `ghcup compile hls`:

```bash
ghcup compile hls -g master --ghc 8.10.7 -- --ghc-options="-dynamic"
ghcup compile hls -v 1.6.1.0 --ghc 8.10.7
```

as it uses cabal underneath you might need to use a specific cabal.project for some ghc versions:

```bash
ghcup compile hls -g master --ghc 9.0.2 --project-file cabal-ghc90.project -- --ghc-options="-dynamic"
ghcup compile hls -v 1.6.1.0 --ghc 9.0.2 --cabal-project cabal-ghc90.project
```

### Preprocessors
Expand Down
14 changes: 14 additions & 0 deletions haskell-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ flag brittany
default: True
manual: True

flag dynamic
description: Build with the dyn rts
default: True
manual: True

common example-plugins
hs-source-dirs: plugins/default/src
other-modules: Ide.Plugin.Example,
Expand Down Expand Up @@ -364,6 +369,15 @@ executable haskell-language-server
-Wno-unticked-promoted-constructors
if flag(pedantic)
ghc-options: -Werror
if !os(windows) && flag(dynamic)
-- We want to link against the dyn rts just like official GHC binaries do;
-- the linked rts determines how external libs are loaded dynamically by TH.
-- The standard way of doing this is via the --enable-dynamic-executables Cabal option
-- Unfortunately it doesnt' work, see https://github.com/haskell/haskell-language-server/issues/2659
-- One can use --ghc-options=-dynamic but this gets applied to the dependencies as well,
-- which results in massive rebuilds and incompatibilities with profiling.
-- So instead we set the -dynamic flag diretly here.
ghc-options: -dynamic

build-depends:
, aeson
Expand Down