Skip to content

Commit cd055b2

Browse files
pepeiborramergify-bot
authored and
mergify-bot
committed
Add the -dynamic flag and update build instructions (#2668)
* Add the -dynamic flag and update build instructions * Disable dynamic in release build * tweak wording * add a comment * Disable dynamic on Windows (cherry picked from commit 3f12824)
1 parent f4022c5 commit cd055b2

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

.github/workflows/build.yml

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ jobs:
4848
echo "tests: false" >> cabal.project.local
4949
echo "benchmarks: false" >> cabal.project.local
5050
51+
- name: Disable -dynamic
52+
run: |
53+
echo "package haskell-language-server" >> cabal.project.local
54+
echo " flags: -dynamic" >> cabal.project.local
55+
5156
- uses: ./.github/actions/setup-build
5257
with:
5358
ghc: ${{ matrix.ghc }}

docs/troubleshooting.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -165,34 +165,34 @@ Using an explicit `hie.yaml` to configure the cradle can resolve the problem, se
165165
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).
166166
Dynamically linked binaries (including`ghci`) use the system linker instead of the GHC linker and avoid both issues.
167167

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

170170
```bash
171-
cabal update && cabal install pkg:haskell-language-server --ghc-options="-dynamic"
171+
cabal update && cabal install pkg:haskell-language-server"
172172
```
173173
174174
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:
175175
176176
```bash
177-
cabal update && cabal install pkg:haskell-language-server --project-file=cabal-ghc90.project --ghc-options="-dynamic"
177+
cabal update && cabal install pkg:haskell-language-server --project-file=cabal-ghc90.project"
178178
```
179179

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

182182
```bash
183-
stack install haskell-language-server --stack-yaml=stack-${ghcVersion}.yaml --ghc-options="-dynamic"
183+
stack install haskell-language-server --stack-yaml=stack-${ghcVersion}.yaml"
184184
```
185185
186186
You also can leverage `ghcup compile hls`:
187187
188188
```bash
189-
ghcup compile hls -g master --ghc 8.10.7 -- --ghc-options="-dynamic"
189+
ghcup compile hls -v 1.6.1.0 --ghc 8.10.7
190190
```
191191
192192
as it uses cabal underneath you might need to use a specific cabal.project for some ghc versions:
193193
194194
```bash
195-
ghcup compile hls -g master --ghc 9.0.2 --project-file cabal-ghc90.project -- --ghc-options="-dynamic"
195+
ghcup compile hls -v 1.6.1.0 --ghc 9.0.2 --cabal-project cabal-ghc90.project
196196
```
197197
198198
### Preprocessors

haskell-language-server.cabal

+14
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ flag brittany
208208
default: True
209209
manual: True
210210

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

368382
build-depends:
369383
, aeson

0 commit comments

Comments
 (0)