Commit
Author: Kevin Schoon [kevinschoon@gmail.com]
Hash: c9d56a23bbad04f2ae3114fb666c19bcb8c88fdc
Timestamp: Wed, 09 Sep 2020 21:43:07 +0000 (4 years ago)

+61 -31 +/-5 browse
improve build support, add complete script
1diff --git a/bin/dune b/bin/dune
2index b262513..06efa69 100644
3--- a/bin/dune
4+++ b/bin/dune
5 @@ -9,3 +9,7 @@
6 (section man)
7 (files ../doc/note.1)
8 )
9+ (install
10+ (section share)
11+ (files ../completion/note.bash)
12+ )
13 diff --git a/completion/note.bash b/completion/note.bash
14new file mode 100644
15index 0000000..6dd1cf4
16--- /dev/null
17+++ b/completion/note.bash
18 @@ -0,0 +1,11 @@
19+ # TODO: Core.Command completion is terrible
20+ function _jsautocom_742571 {
21+ export COMP_CWORD
22+ COMP_WORDS[0]=note
23+ if type readarray > /dev/null
24+ then readarray -t COMPREPLY < <("${COMP_WORDS[@]}")
25+ else IFS="
26+ " read -d "" -A COMPREPLY < <("${COMP_WORDS[@]}")
27+ fi
28+ }
29+ complete -F _jsautocom_742571 note
30 diff --git a/docker/Dockerfile.debian b/docker/Dockerfile.debian
31index 2071df3..b0069bb 100644
32--- a/docker/Dockerfile.debian
33+++ b/docker/Dockerfile.debian
34 @@ -26,11 +26,11 @@ USER opam
35
36 RUN cd /src \
37 && eval "$(opam env)" \
38- # && dune subst \
39- # && dune build
40+ && dune subst \
41+ && dune build
42
43- #FROM debian:stable
44+ FROM debian:stable
45
46- #COPY --from=0 /src/_build/default/bin/note.exe /usr/bin/note
47+ COPY --from=0 /src/_build/default/bin/note.exe /usr/bin/note
48
49- #ENTRYPOINT ["/usr/bin/note"]
50+ ENTRYPOINT ["/usr/bin/note"]
51 diff --git a/scripts/generate_build_artifact.sh b/scripts/generate_build_artifact.sh
52new file mode 100755
53index 0000000..8f1c588
54--- /dev/null
55+++ b/scripts/generate_build_artifact.sh
56 @@ -0,0 +1,41 @@
57+ #!/bin/bash
58+ # Generate a compiled build artifact. This is a hack because
59+ # to the best of my knowledge the distribution story for OCaml
60+ # binaries is terrible AFAICT. Dynamic linking means we need to
61+ # compile against the oldest version of GLIBC we wish to support.
62+ # We also link against Alpine muslc for convenience. It is not
63+ # possible to compile Mach-O Darwin executables from Linux, again,
64+ # AFAICT. ARM binaries would be nice too. TODO: Use a Docker buildx
65+ # workflow or perferably something without Docker at all.
66+ set -e
67+
68+ DOCKER_FILE="$1"
69+ PREFIX="$2"
70+
71+ _usage() {
72+ echo "USAGE: "
73+ echo "generate_build_artifact.sh DOCKERFILE PREFIX"
74+ }
75+
76+ [[ -z "$DOCKER_FILE" ]] || [[ -z "$PREFIX" ]] && {
77+ _usage
78+ exit 1
79+ }
80+
81+ # TODO: Capture more build specifics
82+ VERSION="$(git describe --always)"
83+
84+ dune clean
85+ dune build
86+
87+ PKG="note-$PREFIX-$VERSION"
88+ mkdir -p "pkg/$PKG"
89+ cp -rLv _build/install/default/* "pkg/$PKG/"
90+ rm -vf "pkg/$PKG/bin/note"
91+ docker build -t "$PKG" -f "$DOCKER_FILE" .
92+ container_id="$(docker create $PKG)"
93+ docker cp "$container_id:/usr/bin/note" "pkg/$PKG/bin/note"
94+ docker rm "$container_id" 1>/dev/null
95+
96+ tar -C "pkg/$PKG" -czvf "pkg/$PKG.tar.gz" .
97+ md5sum "pkg/$PKG.tar.gz" > "pkg/$PKG.tar.gz.md5"
98 diff --git a/scripts/generate_build_artifacts.sh b/scripts/generate_build_artifacts.sh
99deleted file mode 100755
100index 3fdb786..0000000
101--- a/scripts/generate_build_artifacts.sh
102+++ /dev/null
103 @@ -1,26 +0,0 @@
104- #!/bin/bash
105- set -e
106-
107- VERSION="$(git describe --always)"
108-
109- # TODO: Capture more build specifics
110-
111- [[ ! -d "pkg" ]] && mkdir pkg
112-
113- dune clean
114-
115- GLIBC_PKG="note-glibc-$VERSION"
116- MUSL_PKG="note-musl-$VERSION"
117-
118- docker build -t "$GLIBC_PKG" -f docker/Dockerfile.debian .
119- # docker build -t "$MUSL_PKG" -f docker/Dockerfile.alpine .
120-
121- glibc_container_id="$(docker create $GLIBC_PKG)"
122- #musl_container_id="$(docker create $MUSL_PKG)"
123-
124- docker cp "$glibc_container_id:/usr/bin/note" "pkg/$GLIBC_PKG"
125- docker rm "$glibc_container_id" 1>/dev/null
126- chmod 755 "pkg/$GLIBC_PKG"
127- #docker cp "$musl_container_id:/usr/bin/note" "$MUSL_PKG"
128- #docker rm "$musl_container_id" 1>/dev/null
129- #chmod 755 "$MUSL_PKG"