Skip to content

Conversation

@AltGr
Copy link
Collaborator

@AltGr AltGr commented Apr 23, 2021

Adds a simple script that generates completely static builds of learn-ocaml, learn-ocaml-client and learn-ocaml-server.

The building uses Docker, Alpine and Musl, targetting only x86_64/linux at the moment.

@AltGr
Copy link
Collaborator Author

AltGr commented Apr 23, 2021

It's a stand-alone script at the moment, but the process is pretty simple so that shouldn't be hard to include in the CI.

@AltGr
Copy link
Collaborator Author

AltGr commented May 3, 2021

I am puzzled by the CI failure: the patches add a Makefile target but should cause no changes on normal builds 🤔
(apart from the relaxed constraint on the dune version, maybe, but the failing CI run uses the latest version anyway)

@erikmd
Copy link
Collaborator

erikmd commented May 3, 2021

Hi @AltGr, thanks!

My understanding is that:

  • the only job that fails is "not that serious" (it is only the one that does docker build -t … -f Dockerfile.test-client which just intends to verify that the learn-ocaml-client.opam file alone is OK in terms of dependencies)
  • then note that in the repo there is no learn-ocaml-client.opam.locked file, so this may confirm this test is "more fragile" (maybe we might want to add one such file at some point)
  • also I had experienced a similar weird failure (at linking time in another job… so it's not necessarily related, but nevermind) that I fixed by bumping the version of ocaml's alpine image that was very old → see PR fix: runtime error in docker packaging #385 where I basically replaced FROM ocaml/opam2:alpine-3.7 with FROM ocaml/opam:alpine-3.13-ocaml-4.05
  • and finally it seems the initial branch point for Static builds #388 is anterior w.r.t. the merge of fix: runtime error in docker packaging #385 (and I believe the GitHub Actions workflow do not trigger an implied "hypothetical merge" for the test, unlike Travis e.g.)

All things put together, I'd suggest you just rebase the branch on latest master, and I guess it should be very OK then :)

AltGr added 3 commits May 4, 2021 08:52
To enable: `ln -s static-linking.sexp src/main/linking.sexp`

This still links dynamically to glibc and pthreads, but should already
considerably improve portability. Next to do is use musl instead of glibc.

Before:
```
% ldd _build/default/src/main/learnocaml_server_main.exe
        linux-vdso.so.1 (0x00007fff743ee000)
        libssl.so.1.1 => /usr/lib/x86_64-linux-gnu/libssl.so.1.1 (0x00007f29aeb43000)
        libcrypto.so.1.1 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1 (0x00007f29ae84f000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f29ae82d000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f29ae6e9000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f29ae6e3000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f29ae51e000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f29af80e000)
```
After:
```
% ldd _build/default/src/main/learnocaml_server_main.exe
        linux-vdso.so.1 (0x00007ffcdddd5000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f90e8f0e000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f90e8dca000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f90e8dc4000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f90e8bff000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f90e9e50000)
```
Dune 2 is not compatible with OCaml 4.05 which we depend on at this stage; there
is the hack to still have it with compiling a secondary, more recent OCaml on
the switch but I really like *not* to do that. And dune 1 seems to work fine.
`make static-binaries` will generate `learnocaml`, `learnocaml-client` and
`learnocaml-server` in at the project root
@AltGr AltGr force-pushed the static-builds branch from 73ef4c3 to 58a8ed0 Compare May 4, 2021 06:53
Linking in the client docker builds seem to fail with the most recent dune
version...
@AltGr
Copy link
Collaborator Author

AltGr commented May 4, 2021

Thanks for the help! I traced it back to the dune version, funny because my intention was to remove the lower constraint on it (for 4.05 compat without falling into the convoluted and costly double OCaml installation), but the previous constraint was actually an =, and it seems we fail with too recent versions as well.

That would need to be investigated, but I guess we'll get into it when we upgrade the supported OCaml version anyway; for now I just put back an upper limit.

@AltGr
Copy link
Collaborator Author

AltGr commented May 4, 2021

On static builds for other targets:

  • OSX: that will target only x86_64 for now, since we're at the moment stuck with OCaml 4.05 which isn't compatilbe with the newer M1.
  • Windows: I tried to run the scripts I had used for cross-compilation a few years back; unfortunately it won't be that easy to make them work. The opam-cross-windows repository I used does not work out of the box anymore (various compilation errors, for example with gcc10 and older OCaml, but there were further ones down the line) ; and it's only from 4.07 on, but if it's just for the client it shouldn't be a huge issue. Native builds through CI may be the better approach there.

@AltGr
Copy link
Collaborator Author

AltGr commented Jun 1, 2021

Closing as superseded by #391

@AltGr AltGr closed this Jun 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind: feature New user-facing feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants