-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build with docker and sh rather than nix (#10)
After this change, all linux packages will be built inside docker containers and macos packages will be built with shell scripts that run directly in the github action. The main reason is that it allows us to use opam for package management rather than nix, which means that newly released packages become available the instant they are released, rather than needing to wait for new versions to land in nix's package repo. Another issue that this solves is that some macos builds of ocaml-lsp-server don't work properly when built with nix (read more [here](https://discuss.ocaml.org/t/corrupted-compiled-interface-after-dune-build/14919)). Signed-off-by: Stephen Sherratt <[email protected]>
- Loading branch information
Showing
18 changed files
with
260 additions
and
620 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,3 @@ | ||
# Build Scripts | ||
|
||
## Why not just use nix? | ||
|
||
It's necessary to produce binaries which are statically-linked with muslc as | ||
they can be used on all distros of linux (including distros that don't link | ||
with the gnu linker such as alpine and nixos). While it's possible to also | ||
produce MacOS binaries with the same nix derivations, we found that aarch64 | ||
binaries for MacOS don't work correctly when built with nix due to [this | ||
issue](https://discuss.ocaml.org/t/corrupted-compiled-interface-after-dune-build/14919). | ||
Shell scripts and dockerfiles for building packages. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
FROM alpine:3.20.3 AS build | ||
|
||
ARG TAG | ||
ARG TARGET | ||
ARG OCAML_VERSION | ||
ARG OCAML_LSP_SERVER_VERSION | ||
|
||
ENV PACKAGE=ocaml-lsp-server | ||
ENV ARCHIVE_NAME="$PACKAGE.$OCAML_LSP_SERVER_VERSION+binary-ocaml-$OCAML_VERSION-built-$TAG-$TARGET" | ||
|
||
RUN apk update && apk add \ | ||
clang \ | ||
make \ | ||
opam \ | ||
bash \ | ||
rsync \ | ||
gzip \ | ||
; | ||
|
||
ENV USERNAME=user | ||
ENV HOME=/home/$USERNAME | ||
RUN adduser -D $USERNAME | ||
USER $USERNAME | ||
WORKDIR $HOME | ||
|
||
RUN opam init --disable-sandboxing --auto-setup --bare | ||
|
||
# Build ocamllsp | ||
RUN mkdir switch | ||
WORKDIR switch | ||
RUN opam switch create . "ocaml.$OCAML_VERSION" | ||
RUN opam install -y --deps-only "$PACKAGE.$OCAML_LSP_SERVER_VERSION" | ||
RUN opam source "$PACKAGE.$OCAML_LSP_SERVER_VERSION" --dir=app | ||
WORKDIR app | ||
COPY statically-link.diff ./statically-link.diff | ||
RUN patch -p1 < statically-link.diff | ||
RUN opam install -y "./$PACKAGE.opam" | ||
|
||
# Make the package | ||
RUN mkdir -p "$ARCHIVE_NAME/bin" | ||
RUN cp ../_opam/bin/ocamllsp "$ARCHIVE_NAME/bin" | ||
COPY static/README.md "$ARCHIVE_NAME/README.md" | ||
RUN mkdir -p out | ||
RUN tar -cvf "out/$ARCHIVE_NAME.tar" "$ARCHIVE_NAME" | ||
RUN gzip -9 "out/$ARCHIVE_NAME.tar" | ||
|
||
|
||
FROM scratch AS export | ||
COPY --from=build /home/user/switch/app/out / |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Build scripts for ocaml-lsp-server | ||
|
||
The shell scripts build dynamically-linked binaries of ocamllsp, suitable for | ||
macOS (provided they were built on macOS of course). The dockerfiles build | ||
statically-linked binaries suitable for linux, regardless of distro. | ||
|
||
## Dockerfile | ||
|
||
Creates a package archive containing a statically-linked ocamllsp binary in the | ||
`out` directory (which will be created if necessary). | ||
|
||
Example usage: | ||
``` | ||
$ docker buildx build . --target=export --output type=local,dest=$(pwd)/out/ --build-arg TAG=2024-11-21.0 --build-arg TARGET=x86_64-unknown-linux-musl --build-arg OCAML_VERSION=5.1.1 --build-arg OCAML_LSP_SERVER_VERSION=1.18.0 | ||
``` | ||
|
||
It will put the package archive in the `out` directory. | ||
|
||
## build.sh | ||
|
||
Creates a package archive containing a dynamically-linked ocamllsp binary at | ||
the absolute path specified by `$OUTPUT`. | ||
|
||
Example usage: | ||
``` | ||
$ TAG=2024-11-21.0 TARGET=aarch64-apple-darwin OCAML_VERSION=5.1.1 OCAML_LSP_SERVER_VERSION=1.18.0 OUTPUT=$(pwd)/ocaml-lsp-server.1.18.0+binary-ocaml-5.1.1-built-2024-11-21.0-aarch64-apple-darwin.tar.gz ./build.sh | ||
``` |
7 changes: 0 additions & 7 deletions
7
...ts/ocaml-lsp-server.1.18.0-ocaml.5.1.1.sh → build-scripts/ocaml-lsp-server/build.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
out |
Oops, something went wrong.