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 a feature for Haskell (GHC) #470

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions .github/workflows/test-all.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
"git-lfs",
"github-cli",
"go",
"haskell",
"hugo",
"java",
"kubectl-helm-minikube",
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
git-lfs: ./**/git-lfs/**
github-cli: ./**/github-cli/**
go: ./**/go/**
haskell: ./**/haskell/**
hugo: ./**/hugo/**
java: ./**/java/**
kubectl-helm-minikube: ./**/kubectl-helm-minikube/**
Expand Down
7 changes: 7 additions & 0 deletions src/haskell/NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@


## OS Support

This Feature should work on recent versions of Debian/Ubuntu-based distributions with the `apt` package manager installed.

`bash` is required to execute the `install.sh` script.
54 changes: 54 additions & 0 deletions src/haskell/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"id": "haskell",
"version": "0.0.1",
brendandburns marked this conversation as resolved.
Show resolved Hide resolved
"name": "Glasgow Haskell Compiler",
"documentationURL": "https://github.com/brendandburns/ghc-feature",
brendandburns marked this conversation as resolved.
Show resolved Hide resolved
"description": "Installs the Glasgow Haskell Compiler",
"options": {
"version": {
"type": "string",
"proposals": [

Choose a reason for hiding this comment

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

I'm not too familiar with how features work. My feeling is that this list can become outdated quickly. For HLS, it already is. Would it not be enough to choose between recommended and latest? Can the user enter manual strings regardless?

"latest",
"recommended",
"9.4.4",
"9.2.7"
],
"default": "recommended",
"description": "Select or enter a GHC Version to install"
},
"cabal_version": {
brendandburns marked this conversation as resolved.
Show resolved Hide resolved
"type": "string",
"proposals": [
"latest",
"recommended",
"3.6.2.0"
],
"default": "recommended",
"description": "Select or enter a Cabal Version to install"
},
"hls_version": {
brendandburns marked this conversation as resolved.
Show resolved Hide resolved
"type": "string",
"proposals": [
"latest",
"recommended",
"1.9.0.0"
],
"default": "recommended",
"description": "Select or enter a Haskell Language Server Version to install"
},
"stack_version": {
brendandburns marked this conversation as resolved.
Show resolved Hide resolved
"type": "string",
"proposals": [
"latest",
"recommended",
"2.9.3"
],
"default": "recommended",
"description": "Select or enter a Stack Version to install"
}
},
"mounts": [],
brendandburns marked this conversation as resolved.
Show resolved Hide resolved
"installsAfter": [
"ghcr.io/devcontainers/features/common-utils"
]
}
23 changes: 23 additions & 0 deletions src/haskell/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -e

BOOTSTRAP_HASKELL_GHC_VERSION="${VERSION:-"recommended "}"

# Maybe install curl, gcc, make
for x in curl gcc make; do
which $x > /dev/null || (apt update && apt install $x -y -qq)
done
Comment on lines +12 to +15
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be better to use a generic snippet to check other Features to do this.

Copy link
Author

Choose a reason for hiding this comment

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

I don't quite follow this comment, can you clarify?

Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

I believe @eitsupi is referring to using check_packages helper function instead of this logic.
https://github.com/devcontainers/features/blob/main/src/docker-in-docker/install.sh#LL86-L91C2

I think it would be nice to use check_packages in this Feature as well for consistency.
(Would also need to copy apt_get_update along with check_packages)

Copy link
Author

Choose a reason for hiding this comment

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

Hrm, I'm not sure that those scripts do exactly what I want to do here. For example, they won't work correctly on a non-debian image where gcc is already installed.

Additionally, copying functions from one install.sh to another doesn't seem to be a great practice, is there a way to share common script snippets between features?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure that those scripts do exactly what I want to do here. For example, they won't work correctly on a non-debian image where gcc is already installed.

Note that this repository is focused on debian-based containers at this time. Most Features will only work with debian-based images.

"image": "mcr.microsoft.com/devcontainers/base:ubuntu", // Any generic, debian-based image.

Additionally, copying functions from one install.sh to another doesn't seem to be a great practice, is there a way to share common script snippets between features?

See devcontainers/spec#209


curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | BOOTSTRAP_HASKELL_NONINTERACTIVE=1 BOOTSTRAP_HASKELL_MINIMAL=1 sh
brendandburns marked this conversation as resolved.
Show resolved Hide resolved

GHCUP_DIR=~/.ghcup/bin
brendandburns marked this conversation as resolved.
Show resolved Hide resolved

${GHCUP_DIR}/ghcup install ghc $BOOTSTRAP_HASKELL_GHC_VERSION

Choose a reason for hiding this comment

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

I suggest to not do all this manually, but use the bootstrap script, which allows fine grained control via env vars.

E.g.

curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | BOOTSTRAP_HASKELL_NONINTERACTIVE=1 BOOTSTRAP_HASKELL_CABAL_VERSION=$CABALVERSION BOOTSTRAP_HASKELL_INSTALL_HLS=1 BOOTSTRAP_HASKELL_ADJUST_BASHRC=1 sh

This will also try do adjust shell config to add ~/.ghcup/bin to PATH and most importantly install stack installation hooks that make sure HLS actually works with stack (there are ABI issues). See https://www.haskell.org/ghcup/guide/#strategy-2-stack-hooks-new-recommended

Right now the bootstrap script assumes you want latest of stack and HLS, but I can add environment variables to control that as well.

Choose a reason for hiding this comment

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

Oh and the bootstrap script also creates a ~/.ghcup/env file that can be sourced to get the correct PATH.

${GHCUP_DIR}/ghcup install cabal $CABAL_VERSION
${GHCUP_DIR}/ghcup install hls $HLS_VERSION
${GHCUP_DIR}/ghcup install stack $STACK_VERSION

${GHCUP_DIR}/ghcup set ghc $BOOTSTRAP_HASKELL_GHC_VERSION
${GHCUP_DIR}/ghcup set cabal $CABAL_VERSION
${GHCUP_DIR}/ghcup set hls $HLS_VERSION
${GHCUP_DIR}/ghcup set stack $STACK_VERSION
12 changes: 12 additions & 0 deletions test/haskell/custom_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

set -e

# Optional: Import test library
source dev-container-features-test-lib

# Definition specific tests
check "version" ~/.ghcup/bin/ghc --version | grep 9.2.6

Choose a reason for hiding this comment

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

So is ~/.ghcup/bin in PATH?

# Report result
reportResults
14 changes: 14 additions & 0 deletions test/haskell/default_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -e

# Optional: Import test library
source dev-container-features-test-lib

# Definition specific tests
EXPECTED_VERSION=$(~/.ghcup/bin/ghcup list | grep "ghc " | grep recommended | awk '{print $3}')
samruddhikhandale marked this conversation as resolved.
Show resolved Hide resolved
echo ${EXPECTED_VERSION}
check "version" ~/.ghcup/bin/ghc --version | grep "${EXPECTED_VERSION}"

# Report result
reportResults
17 changes: 17 additions & 0 deletions test/haskell/scenarios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"custom_version": {
"image": "ubuntu:focal",
"features": {
"haskell": {
"version": "9.2.6"
}
}
},
"default_version": {
"image": "ubuntu:jammy",
"features": {
"haskell": {
}
brendandburns marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
12 changes: 12 additions & 0 deletions test/haskell/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

set -e

# Optional: Import test library
source dev-container-features-test-lib

# Definition specific tests
check "version" ~/.ghcup/bin/ghcup list

# Report result
reportResults