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

Add Dev Container Configuration Files #6228

Merged
merged 12 commits into from
Sep 14, 2023
Merged

Add Dev Container Configuration Files #6228

merged 12 commits into from
Sep 14, 2023

Conversation

benz0li
Copy link
Contributor

@benz0li benz0li commented Sep 5, 2023

  • Any changes that could be relevant to users have been recorded in ChangeLog.md.
  • The documentation has been updated, if necessary

No updates to ChangeLog.md and documentation required.

@benz0li
Copy link
Contributor Author

benz0li commented Sep 5, 2023

I tried to be minimally invasive, i.e.

  • Did not touch the LICENCE of Stack (the software)
    • Created a separate LICENCE file in the .devcontainer folder
      ℹ️ Mentioning that The code in this directory is not part of Stack (the software) and,...

I hope this is fine and the instructions in the additional README.md in the .devcontainer folder are sufficient.

@mpilgrem What do you think? Any objections? Or additions?

@benz0li
Copy link
Contributor Author

benz0li commented Sep 5, 2023

See jgm/pandoc#9039 (comment) ff for the discussion about adding Dev Containers to the Pandoc repository.

@benz0li benz0li marked this pull request as draft September 5, 2023 09:59
@benz0li
Copy link
Contributor Author

benz0li commented Sep 5, 2023

The Haskell extension errors in the default Dev Container configuration: Failed to find the GHC version of this Cabal project. Error when calling cabal exec -v0 -- ghc --print-libdir.

cabal exec -v0 -- ghc --print-libdir
Error: cabal: Could not resolve dependencies:
[__0] trying: stack-2.12.0 (user goal)
[__1] trying: pantry-0.9.2 (dependency of stack)
[__2] trying: digest-0.0.1.7 (dependency of pantry)
[__3] rejecting: digest:+pkg-config (conflict: pkg-config package zlib-any,
not found in the pkg-config database)
[__3] rejecting: digest:-pkg-config (manual flag can only be changed
explicitly)
[__3] fail (backjumping, conflict set: digest, digest:pkg-config)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: digest, stack, digest:pkg-config,
pantry
Try running with --minimize-conflict-set to improve the error message.

Quick fix: Set constraint digest ==0.0.1.3 in cabal.config.
❓ Proper fix?

@benz0li
Copy link
Contributor Author

benz0li commented Sep 5, 2023

@mpilgrem
Copy link
Member

mpilgrem commented Sep 5, 2023

@benz0li, I understand that GitHub Codespaces is a cloud-based x86_64-based Linux-based development environment service that GitHub users can pay for, and a repository (like Stack's) can assist those Codespaces users by providing a configuration (usually located in a .devcontainer directory) that encourages consistency of development experience. That is, essentially, where my own understanding ends.

So, some questions:

  • is there a good reason to have a different form of licence (MIT v BSD 3-Clause) for the .devcontainer configuration?
  • are there any particularly 'opinionated' aspects to this configuration that are worthy of identification/discussion here? (Nothing against opinions, as such - I would just like to understand what might be 'debatable'.)

Finally, when this is settled, it would be good to add something (some pointer to the specific README) to (a) CONTRIBUTING.md and (b) the *.md files in docs\maintainers.

@mpilgrem
Copy link
Member

mpilgrem commented Sep 5, 2023

@benz0li, I did not follow your cabal.config comment/question. I think Stack's cabal.config is currently up to date. EDIT: Often, when there are digest problems, it seems to be because the tool pkg-config is missing from the environment.

@benz0li
Copy link
Contributor Author

benz0li commented Sep 6, 2023

@benz0li, I did not follow your cabal.config comment/question. I think Stack's cabal.config is currently up to date.

Please open in Codespaces or VS Code (using https://github.com/benz0li/commercialhaskell-stack/tree/add-dev-containers) with the default Dev Container configuration; wait until all VS Code extensions are installed; open file src/Stack.hs.
👉 See the error message from the VS Code Haskell extension as mentioned in #6228 (comment).

Should one be able to build Stack with Cabal (the tool) as well?
ℹ️ If no, this error message is probably a result of this fact. If yes, then something is wrong with Stack's cabal.config.

EDIT: Often, when there are digest problems, it seems to be because the tool pkg-config is missing from the environment.

That is not the case. See #6212 (comment) ff.

@benz0li
Copy link
Contributor Author

benz0li commented Sep 6, 2023

@benz0li, I understand that GitHub Codespaces is a cloud-based x86_64-based Linux-based development environment service that GitHub users can pay for, and a repository (like Stack's) can assist those Codespaces users by providing a configuration (usually located in a .devcontainer directory) that encourages consistency of development experience. That is, essentially, where my own understanding ends.

These Dev Container configuration can also be run locally/'remotely (SSH)' with VS Code using Docker/Podman on both Linux/x86_64 and Linux/AArch64.
ℹ️ I run it on my MacBook Pro M2 (arm64 aka AArch64) using Docker Desktop.

Dev Containers end "it works on my computer"-debates quickly because there is a Dev Container config to reproduce the issue.

@benz0li
Copy link
Contributor Author

benz0li commented Sep 6, 2023

  • is there a good reason to have a different form of licence (MIT v BSD 3-Clause) for the .devcontainer configuration?

No. The MIT license is just my preferred OSS licence.

I could also use the BSD 3-Clause with .devcontainer/scripts/fix-chsh.sh as an exception, or not providing a LICENSE file at all.
In case of the latter, you must mention copyright and license statement of .devcontainer/scripts/fix-chsh.sh in Stacks license.
ℹ️ That is the reason I chose to provide a separate license.

  • are there any particularly 'opinionated' aspects to this configuration that are worthy of identification/discussion here? (Nothing against opinions, as such - I would just like to understand what might be 'debatable'.)

These Dev Containers are based on the same docker images that 'are used'/'are going to be used' to build the statically linked Linux amd64 and arm64 binary releases of stack.
👉 Because the Dev Containers and the build process use the same image(s), troubleshooting is much easier if something goes wrong.

Debatable is the fact, that an unofficial build of GHC is used in these images. This was already discussed in #6142.

Finally, when this is settled, it would be good to add something (some pointer to the specific README) to (a) CONTRIBUTING.md and (b) the *.md files in docs\maintainers.

Agreed.

@benz0li
Copy link
Contributor Author

benz0li commented Sep 6, 2023

Tips

It has been suggested that a project must have been successfully built before the VS code extension (and HLS) is first activated on the project, for HLS to work reliably.

Stack and Visual Studio Code - The Haskell Tool Stack: Haskell Language Server > Tips

This is exactly what [at least newer versions of] HLS try to do in the background – and fail with this repository.

I have successfully built stack (using stack); HLS still fails with the same error message.

@mpilgrem
Copy link
Member

mpilgrem commented Sep 6, 2023

@benz0li, on building Stack (lib:stack, exe:stack - I have not yet tried other components its Cabal file) with Cabal (the tool), I have no problem locally with the following in the root directory of the Stack project (in the master branch) on Windows 11:

> cabal --version
cabal-install version 3.10.1.0
compiled using version 3.10.1.0 of the Cabal library
> cabal update
...
> cabal build --with-compiler C:\Users\mike\AppData\Local\Programs\stack\x86_64-windows\ghc-9.4.6\bin\ghc.exe
...

EDIT: The following also fine locally:

cabal build stack:test:stack-test --with-compiler C:\Users\mike\AppData\Local\Programs\stack\x86_64-windows\ghc-9.4.6\bin\ghc.exe
cabal build stack:exe:stack-integration-test --flags integration-tests --with-compiler C:\Users\mike\AppData\Local\Programs\stack\x86_64-windows\ghc-9.4.6\bin\ghc.exe

@benz0li
Copy link
Contributor Author

benz0li commented Sep 6, 2023

Well, well, well...

Fixed for default config (and only the default config) by downgrading pkg-config from 1.9.x to 1.8.1.


HLS still does not work, though:

Failed to run ["cabal","v2-repl","lib:stack"] in directory "/workspaces/stack". Consult the logs for full command and error.
Failed command: cabal --builddir=/home/vscode/.cache/hie-bios/dist-stack-7d4030fb4073a5f963b4594938e6876d v2-repl --with-compiler /home/vscode/.cache/hie-bios/wrapper-b54f81dea4c0e6d1626911c526bc4e36 --with-hc-pkg /home/vscode/.cache/hie-bios/ghc-pkg-2e9e7382b10dc1de912243f849341f70 lib:stack
Build profile: -w ghc-9.4.6 -O1
In order, the following will be built (use -v for more details):
 - stack-2.12.0 (first run)
Preprocessing library for stack-2.12.0..

Error: setup: can't find source for Build_stack in src, src/unix/,
/home/vscode/.cache/hie-bios/dist-stack-7d4030fb4073a5f963b4594938e6876d/build/aarch64-linux/ghc-9.4.6/stack-2.12.0/build/autogen,
/home/vscode/.cache/hie-bios/dist-stack-7d4030fb4073a5f963b4594938e6876d/build/aarch64-linux/ghc-9.4.6/stack-2.12.0/build/global-autogen

Error: cabal: repl failed for stack-2.12.0.



Process Environment:
HIE_BIOS_GHC: /usr/local/lib/ghc-9.4.6/bin/ghc-9.4.6
HIE_BIOS_GHC_ARGS: -B/usr/local/lib/ghc-9.4.6/lib

@mpilgrem
Copy link
Member

mpilgrem commented Sep 6, 2023

Build_stack is a module that is auto-generated by Cabal - see stack.cabal and the (custom-setup) Setup.hs (function generateBuildModule). So, HLS will not find its source code in Stack's repository. The module is only compiled when Cabal flag hide-dependency-versions is False (False by default; True when a release version of Stack is built).

This is maybe a known problem - see #6224 which mentions a work-around. I have not yet got to the bottom of #6224.

@benz0li
Copy link
Contributor Author

benz0li commented Sep 6, 2023

So, HLS will not find its source code in Stack's repository.

Is there a way to tell HLS to ignore this module? With a 'cradle' - an hie.yaml file - in the project's root directory?

@mpilgrem Thank you for all the feedback. Highly appreciated.

@benz0li
Copy link
Contributor Author

benz0li commented Sep 6, 2023

Until further notice, the Haskell Language Server and the VS Code Haskell extension is not installed (= disabled) for all Dev Container configurations. Due to #6154.

With the 'Default' configuration, Haskell now builds using both Stack and Cabal.

@mpilgrem
Copy link
Member

mpilgrem commented Sep 6, 2023

@benz0li, on a cradle for HLS, I've not commited one to the repository because I think it forces a choice of either Stack or Cabal (the tool). That seemed to me to be inappropriate to impose, even for Stack's own repository.

@benz0li
Copy link
Contributor Author

benz0li commented Sep 7, 2023

Downgraded pkg-config from 1.9.x to 1.8.1 in all affected glcr.b-data.ch/ghc/ghc-musl images: benz0li/ghc-musl@c492963

@mpilgrem
Copy link
Member

mpilgrem commented Sep 8, 2023

@benz0li, for your information, in the master branch, I have reorganised directories in Stack's repository (#6231) but that should not affect your pull request, which does not touch those directories.

@mpilgrem
Copy link
Member

mpilgrem commented Sep 8, 2023

@benz0li, for your information, I have added some information about how to use HLS with the Stack project here: https://docs.haskellstack.org/en/latest/CONTRIBUTING/#haskell-language-server.

@benz0li
Copy link
Contributor Author

benz0li commented Sep 11, 2023

@benz0li, for your information, I have added some information about how to use HLS with the Stack project here: https://docs.haskellstack.org/en/latest/CONTRIBUTING/#haskell-language-server.

Haskell extension + HLS work fine with the proposed cradle for Stack. I have updated the instructions accordingly:
https://github.com/benz0li/commercialhaskell-stack/tree/add-dev-containers/.devcontainer#haskell-language-server-hls

I tried the following cradle for Cabal:

cradle:
  cabal:
  - path: "./src"
    component: "lib:stack"
  - path: "./app"
    component: "stack:exe:stack"
  - path: "./tests/integration"
    component: "stack:exe:stack-integration-test"
  - path: "./tests/unit"
    component: "stack:test:stack-unit-test"

But this still leads to the error described in #6228 (comment).

@mpilgrem
Copy link
Member

@benz0li, regarding:

But this still leads to the error described in #6228 (comment).

Somehow, after an initial stack build, HLS knows how to find generated module Build_stack (the source code is in the build/global-autogen directory of stack path --dist-dir; the build artefacts in the build directory) but it seems (from your experience) that there is no analogue in the case of Cabal (the tool). I do not know enough about Cabal (the tool) or HLS to know why.

@benz0li
Copy link
Contributor Author

benz0li commented Sep 11, 2023

I do not know enough about Cabal (the tool) or HLS to know why.

@mpilgrem No worries.

I will try a few more things. If I do not find a solution, I might ask over at https://github.com/haskell/haskell-language-server.

@mpilgrem
Copy link
Member

mpilgrem commented Sep 11, 2023

@benz0li, I got HLS to work with the Stack project on Windows with Cabal, but it was 'ugly'. This is what I did:

  1. Installed Cabal 3.8.1.0 with GHCup, and ran cabal update (because Cabal does not do that automatically, like Stack does).

  2. Noted that HLS was treating ./Setup.hs as if it were a Cabal script file - so added the following 'Cabal script' comment to its head, to stop HLS from complaining about a missing {- cabal: start (EDIT: This only works with a simple cradle):

    {- cabal:
    build-depends:   Cabal < 3.12
                   , base >=4.14.3.0 && <5
                   , filepath
    -}
  3. Noted that HLS was looking somewhere in (in my case) in --builddir=C:\Users\mpilgre\AppData\Local\hie-bios\dist-stack-31d950a719134407968bb13e4dd138b2 for Build_stack.hs, so ran:

    stack exec --no-ghc-package-path -- cabal --builddir=C:\Users\mpilgre\AppData\Local\hie-bios\dist-stack-31d950a719134407968bb13e4dd138b2 build
    

    As I am a Stack user on Windows, I need stack exec to provide (a) GHC and (b) MSYS2 in the environment. I need to specify --no-ghc-package-path because Cabal objects if GHC_PACKAGE_PATH is set.

  4. Now HLS works with VS Code. However, I have to run VS Code in the same environment:

    stack exec --no-ghc-package-path -- code .
    

@benz0li
Copy link
Contributor Author

benz0li commented Sep 12, 2023

Finally, when this is settled, it would be good to add something (some pointer to the specific README) to (a) CONTRIBUTING.md and (b) the *.md files in docs\maintainers.

@mpilgrem As #6235 looks good I will think about the above now.

@benz0li
Copy link
Contributor Author

benz0li commented Sep 13, 2023

Added hlint and yamllint to the Dev Containers and re-enabled the VS Code Haskell extension in the default config.

After merging the latest changes from branch master, the HLS works fine in the default Dev Container.

- A 'Full Rebuild Container' resets the home directory on Codespaces
- Pip may be used to install MkDocs
@benz0li
Copy link
Contributor Author

benz0li commented Sep 13, 2023

I think the current .devcontainer/README.md should go to docs/maintainers/devcontainers.md.

Then, I suggest .devcontainer/README.md to contain

See [haskellstack.org > Stack's code (advanced) > Maintainers > Dev Containers](https://doc.haskellstack.org)
or [../doc/maintainers/devcontainers.md](../doc/maintainers/devcontainers.md) for
more information.

@mpilgrem Can you make a suggestion how and where in CONTRIBUTING.md to refer to docs/maintainers/devcontainers.md?

@mpilgrem
Copy link
Member

@benz0li, regarding:

Can you make a suggestion how and where in CONTRIBUTING.md to refer to docs/maintainers/devcontainers.md?

My suggestion on 'where' is to give it its own section near the end, after the section on 'Haskell Language Server'.

My suggestion on 'how', is about 'assumed knowledge' of the reader: imagine you are writing to help somebody who is about to start a course on computer science at university. Hyperlinks to where they can read more to understand the context may assist.

@benz0li
Copy link
Contributor Author

benz0li commented Sep 14, 2023

@mpilgrem Please review.

Thank you.

EDIT: Any (other) tool I have missed?

- Add info about PATH and precedence of executables
- Enable Oh My Zsh plugins screen tmux vscode
@mpilgrem mpilgrem marked this pull request as ready for review September 14, 2023 18:35
@mpilgrem
Copy link
Member

@benz0li, thanks! I'll merge. It maybe that when I see how the *.md render on the website that I tweak them for editorial consistency, but I can do that separately.

@mpilgrem mpilgrem merged commit ceb366d into commercialhaskell:master Sep 14, 2023
12 checks passed
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

Successfully merging this pull request may close these issues.

2 participants