Skip to content

Commit 2e57957

Browse files
olafurpgdonsbotvarungandhi-src
authored
Add Haskell bindings for SCIP (#16)
Co-authored-by: Don Stewart <[email protected]> Co-authored-by: Varun Gandhi <[email protected]>
1 parent b5da5d6 commit 2e57957

File tree

9 files changed

+5513
-1
lines changed

9 files changed

+5513
-1
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
bindings/typescript/scip.ts linguist-generated=true
22
bindings/go/scip/scip.pb.go linguist-generated=true
33
bindings/rust/src/scip.rs linguist-generated=true
4+
bindings/haskell/src/Proto/**.hs linguist-generated=true
45
yarn.lock linguist-generated=true

.github/workflows/haskell.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Haskell
2+
on:
3+
pull_request:
4+
paths:
5+
- '.github/workflows/**'
6+
- '**.hs'
7+
- '**.cabal'
8+
9+
jobs:
10+
ci:
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
ghc: [8.10.7]
15+
runs-on: ubuntu-latest
16+
container:
17+
# Ubuntu with ghcup already installed
18+
image: ghcr.io/facebookincubator/hsthrift/ci-base:ghcup
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v2
22+
- name: Install additional tools
23+
run: |
24+
apt-get update
25+
apt install -y unzip
26+
- name: Install GHC ${{ matrix.ghc }}
27+
run: ghcup install ghc ${{ matrix.ghc }} --set
28+
- name: Install cabal-install 3.6
29+
run: ghcup install cabal 3.6.0.0 --set
30+
- name: Add GHC and cabal to PATH
31+
run: echo "$HOME/.ghcup/bin" >> "$GITHUB_PATH"
32+
- name: Install protoc
33+
run: |
34+
PROTOC_ZIP=protoc-3.14.0-linux-x86_64.zip
35+
curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.14.0/"$PROTOC_ZIP"
36+
unzip -o "$PROTOC_ZIP" -d /usr/local bin/protoc
37+
unzip -o "$PROTOC_ZIP" -d /usr/local 'include/*'
38+
rm -f $PROTOC_ZIP
39+
- name: Populate hackage index
40+
run: cabal update
41+
working-directory: bindings/haskell
42+
- name: Build proto-lens-protoc wrapper
43+
run: cabal install proto-lens-protoc
44+
working-directory: bindings/haskell
45+
- name: Generate Haskell
46+
run: protoc --plugin=protoc-gen-haskell="$HOME/.cabal/bin/proto-lens-protoc" --haskell_out=src --proto_path=../.. scip.proto
47+
working-directory: bindings/haskell
48+
- name: Build source
49+
run: cabal build
50+
working-directory: bindings/haskell

Development.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
- [bindings/](./bindings/): Contains a mix of generated and hand-written
66
bindings for different languages.
7-
- The TypeScript and Rust bindings are auto-generated.
7+
- The TypeScript, Rust and Haskell bindings are auto-generated.
88
- The Go bindings include protoc-generated code as well as extra
99
functionality, such as for converting a SCIP index into an LSIF index.
1010
This is used by the CLI below as well as the
@@ -24,6 +24,7 @@
2424
```
2525
./dev/proto-generate.sh
2626
```
27+
For the Haskell bindings, see `bindings/haskell/README.md`.
2728
2. Regenerating snapshots after making changes to the CLI.
2829
```
2930
go test ./cmd -update-snapshots

bindings/haskell/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist-newstyle/

bindings/haskell/LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../LICENSE

bindings/haskell/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[![CI](https://github.com/sourcegraph/scip/actions/workflows/haskell.yml/badge.svg)](https://github.com/sourcegraph/scip/actions/workflows/haskell.yml/badge.svg)
2+
3+
# Haskell bindings for SCIP
4+
5+
These bindings use [Google's proto-lens generator for Haskell](https://github.com/google/proto-lens).
6+
7+
Building: see the following workflow file for most up to date:
8+
https://github.com/sourcegraph/scip/blob/main/.github/workflows/haskell.yml
9+
10+
First, get a working GHC environment:
11+
12+
```sh
13+
# Linux
14+
GHCUPVERSION=0.1.17.4
15+
curl --proto '=https' --tlsv1.2 -sSf https://downloads.haskell.org/~ghcup/$GHCUPVERSION/x86_64-linux-ghcup-$GHCUPVERSION > /usr/bin/ghcup && \
16+
chmod +x /usr/bin/ghcup
17+
ghcup install ghc 8.10.7 --set
18+
ghcup install cabal 3.6.0.0 --set
19+
```
20+
21+
```sh
22+
# macOS
23+
GHCUPVERSION=0.1.17.4
24+
curl --proto '=https' --tlsv1.2 -sSf https://downloads.haskell.org/~ghcup/$GHCUPVERSION/x86_64-apple-darwin-ghcup-$GHCUPVERSION > /usr/local/bin/ghcup && \
25+
chmod +x /usr/local/bin/ghcup
26+
ghcup install ghc 8.10.7 --set
27+
ghcup install cabal 3.6.0.0 --set
28+
```
29+
30+
Next, install Google's `protoc` compiler. See: https://github.com/google/proto-lens/blob/master/docs/installing-protoc.md
31+
32+
Then install the haskell generator from the proto-lens packages:
33+
34+
```
35+
cabal install proto-lens-protoc
36+
```
37+
38+
Finally, generate the source files manually in `src/*`
39+
40+
```sh
41+
# working directory: bindings/haskell
42+
protoc --plugin=protoc-gen-haskell=`which proto-lens-protoc` --haskell_out=src --proto_path=../.. scip.proto
43+
```
44+
45+
Build the library as normal:
46+
47+
```
48+
# working directory: bindings/haskell
49+
cabal build
50+
```

bindings/haskell/scip.cabal

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
cabal-version: 3.6
2+
3+
name: scip
4+
version: 0.1.0.0
5+
synopsis: Haskell bindings for SCIP Code Intelligence Protocol
6+
license: Apache-2.0
7+
license-file: LICENSE
8+
author: SCIP Maintainers
9+
maintainer: [email protected]
10+
homepage: https://github.com/sourcegraph/scip
11+
category: Language
12+
build-type: Simple
13+
14+
library
15+
ghc-options: -Wall
16+
exposed-modules:
17+
Proto.Scip,
18+
Proto.Scip_Fields
19+
hs-source-dirs: src
20+
default-language: Haskell2010
21+
build-depends:
22+
proto-lens-runtime ^>= 0.7.0.0,
23+
base ^>= 4.14.0.0

0 commit comments

Comments
 (0)