Skip to content

Commit b65385c

Browse files
committed
Add script to build ocaml-lsp-server
Signed-off-by: Stephen Sherratt <[email protected]>
1 parent 70ae3f5 commit b65385c

File tree

4 files changed

+110
-11
lines changed

4 files changed

+110
-11
lines changed

.github/workflows/build.yml

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
contents: write
5858
strategy:
5959
matrix:
60-
os: [ubuntu-latest, macos-13, macos-14]
60+
os: [ubuntu-latest, macos-13]
6161
ocaml: ["5.2.0", "5.1.1"]
6262
include:
6363
- os: ubuntu-latest
@@ -70,11 +70,6 @@ jobs:
7070
ocaml: "5.2.0"
7171
linking: dynamic
7272
target_triple: x86_64-apple-darwin
73-
- os: macos-14
74-
version: "1.19.0"
75-
ocaml: "5.2.0"
76-
linking: dynamic
77-
target_triple: aarch64-apple-darwin
7873
- os: ubuntu-latest
7974
version: "1.18.0"
8075
ocaml: "5.1.1"
@@ -85,11 +80,6 @@ jobs:
8580
ocaml: "5.1.1"
8681
linking: dynamic
8782
target_triple: x86_64-apple-darwin
88-
- os: macos-14
89-
version: "1.18.0"
90-
ocaml: "5.1.1"
91-
linking: dynamic
92-
target_triple: aarch64-apple-darwin
9383

9484
runs-on: ${{ matrix.os }}
9585

@@ -115,3 +105,42 @@ jobs:
115105
allowUpdates: true
116106
artifacts: "*.tar.gz"
117107

108+
109+
ocaml-lsp-server-build-script:
110+
name: Build ocaml-lsp-server binaries from the build script (rather than the flake)
111+
permissions:
112+
contents: write
113+
strategy:
114+
matrix:
115+
os: [macos-14]
116+
ocaml: ["5.2.0", "5.1.1"]
117+
include:
118+
- os: macos-14
119+
version: "1.19.0"
120+
ocaml: "5.2.0"
121+
linking: dynamic
122+
target_triple: aarch64-apple-darwin
123+
- os: macos-14
124+
version: "1.18.0"
125+
ocaml: "5.1.1"
126+
linking: dynamic
127+
target_triple: aarch64-apple-darwin
128+
129+
runs-on: ${{ matrix.os }}
130+
131+
steps:
132+
- name: Set script name
133+
run: |
134+
echo "BUILD_SCRIPT=./build-scripts/ocaml-lsp-server.${{ matrix.version }}-ocaml.${{ matrix.ocaml }}.sh" >> $GITHUB_ENV
135+
- name: Set-up OCaml
136+
uses: ocaml/setup-ocaml@v3
137+
with:
138+
ocaml-compiler: 5
139+
- uses: actions/checkout@v4
140+
- name: Build ocaml-lsp-server
141+
run: |
142+
$BUILD_SCRIPT ${{ github.ref_name }} ${{ matrix.target_triple }} $(pwd)
143+
- uses: ncipollo/release-action@v1
144+
with:
145+
allowUpdates: true
146+
artifacts: "*.tar.gz"

build-scripts/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Build Scripts
2+
3+
## Why not just use nix?
4+
5+
It's necessary to produce binaries which are statically-linked with muslc as
6+
they can be used on all distros of linux (including distros that don't link
7+
with the gnu linker such as alpine and nixos). While it's possible to also
8+
produce MacOS binaries with the same nix derivations, we found that aarch64
9+
binaries for MacOS don't work correctly when built with nix due to [this
10+
issue](https://discuss.ocaml.org/t/corrupted-compiled-interface-after-dune-build/14919).
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
TAG=$1
5+
TARGET=$2
6+
OUTPUT=$3
7+
8+
OCAML_VERSION=5.1.1
9+
OCAML_LSP_SERVER_VERSION=1.18.0
10+
11+
TMP_DIR="$(mktemp -d -t ocaml-binary-packages-build.XXXXXXXXXX)"
12+
trap 'rm -rf "$TMP_DIR"' EXIT
13+
14+
cd "$TMP_DIR"
15+
opam switch create . "ocaml.$OCAML_VERSION"
16+
eval "$(opam env)"
17+
opam install -y "ocaml-lsp-server.$OCAML_LSP_SERVER_VERSION"
18+
19+
ARCHIVE_NAME="ocaml-lsp-server.$OCAML_LSP_SERVER_VERSION+binary-ocaml-$OCAML_VERSION-built-$TAG-$TARGET"
20+
21+
mkdir -p "$ARCHIVE_NAME"
22+
cp _opam/bin/ocamllsp "$ARCHIVE_NAME"
23+
cat > "$ARCHIVE_NAME/README.md" <<EOF
24+
# ocaml-lsp-server binary distribution
25+
26+
See https://github.com/ocaml-dune/ocaml-binary-packages for more information.
27+
EOF
28+
tar --format=posix -cvf "$ARCHIVE_NAME.tar" "$ARCHIVE_NAME"
29+
gzip -9 "$ARCHIVE_NAME.tar"
30+
mv "$ARCHIVE_NAME.tar.gz" $OUTPUT
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
TAG=$1
5+
TARGET=$2
6+
OUTPUT=$3
7+
8+
OCAML_VERSION=5.2.0
9+
OCAML_LSP_SERVER_VERSION=1.19.0
10+
11+
TMP_DIR="$(mktemp -d -t ocaml-binary-packages-build.XXXXXXXXXX)"
12+
trap 'rm -rf "$TMP_DIR"' EXIT
13+
14+
cd "$TMP_DIR"
15+
opam switch create . "ocaml.$OCAML_VERSION"
16+
eval "$(opam env)"
17+
opam install -y "ocaml-lsp-server.$OCAML_LSP_SERVER_VERSION"
18+
19+
ARCHIVE_NAME="ocaml-lsp-server.$OCAML_LSP_SERVER_VERSION+binary-ocaml-$OCAML_VERSION-built-$TAG-$TARGET"
20+
21+
mkdir -p "$ARCHIVE_NAME"
22+
cp _opam/bin/ocamllsp "$ARCHIVE_NAME"
23+
cat > "$ARCHIVE_NAME/README.md" <<EOF
24+
# ocaml-lsp-server binary distribution
25+
26+
See https://github.com/ocaml-dune/ocaml-binary-packages for more information.
27+
EOF
28+
tar --format=posix -cvf "$ARCHIVE_NAME.tar" "$ARCHIVE_NAME"
29+
gzip -9 "$ARCHIVE_NAME.tar"
30+
mv "$ARCHIVE_NAME.tar.gz" $OUTPUT

0 commit comments

Comments
 (0)