Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build system rehaul, use of Docker for CI & artifact generation on Github #299

Merged
merged 13 commits into from
Aug 4, 2022

Conversation

AltGr
Copy link
Contributor

@AltGr AltGr commented Jul 29, 2022

No description provided.

@AltGr AltGr force-pushed the french_law-build branch 4 times, most recently from f8abb1c to 2b9ea0d Compare July 29, 2022 15:36
@denismerigoux
Copy link
Contributor

Wouahou ! So how does this work ? Will the generated files be updated nightly by a bot ? Or appear in a source code release attached to the GitHub page ? I put those generated assets under Git because I wanted for somebody that wanted to just use Catala to be able to use the assets directly without having to install the compiler to generate them.

@AltGr
Copy link
Contributor Author

AltGr commented Jul 29, 2022

Aah I didn't know!

But indeed, providing them as artifacts would be pretty easy: they are already generated by the CI so extracting them from the Docker image and feeding them to Github artifacts / release assets should be fairly straightforward.

Is there already a list of artifacts that we should extract in that way ?

@denismerigoux
Copy link
Contributor

So for me, ideally:

  • All of french_law plus their runtime dependency as a source code zip ;
  • Linux/Windows/Mac x86 executables of the Catala compiler (without Z3) + Clerk ;
  • A Javascript binary of the Catala compiler (without JS)
    You can take a look at the assets I put in the last release.

A push-button release process would be amazing, I would release more often that today with that.

@AltGr
Copy link
Contributor Author

AltGr commented Jul 29, 2022

Ok I'll handle that

@denismerigoux
Copy link
Contributor

See #219 where I talked a bit about this

The files where manually generated through Makefile rules, and
versionned (with an outdated version).

The issue was that we had:
- `dune` building Catala
- Makefiles calling `catala` to build and copy the `french_law/ocaml/law_source`
  files
- then `dune` again to build `french_law`

The result was that `dune build` (without running `make` first) would
return a weird error.

The proposed solution adds ad-hoc dune rules to call the catala
binary, so that it can handle the whole pipeline correctly. If OCaml
is purely a backend, though, a simpler solution that makes us less
dependent on dune would be to handle the compilation of `french_law`
manually.

The dune rules are set to 'promote' the files so that it preserves the
fact that they are versionned (but with no confusion of the build system
about where they should come from anymore)
(plus other small Makefile improvements)
Dune has 2 default build profiles: `dev` and `release`, which change things like warnings-as-errors, and debug in jsoo build mode.

We need to be in release mode when we generate the javascript artifacts (e.g. `make website-assets`), so the master `Makefile` had `--profile=release` for the `dune` commands building them. However, that rebuilds _the whole tree of dependencies_ in release mode, which means `make all` might rebuild everything several times, as the `release` flag is turned off and on. I had conflicting plugins that weren't rebuilt with the correct flag. And let's not imagine the `make -j` case…

This is the best solution I can think of for the time being:
- set the Makefile to use dune's `release` profile by default
- this ensure consistency and avoids surprises with e.g. bad (slower) artifacts
  generated for the website
- devs can use `dune` directly when working, or set `DUNE_PROFILE` manually if
  they need it

I am not sure yet about CI, though, since we want warnings-as-errors but also
useful artifacts. Might best to build twice…
(they're no longer reformatted, at the moment, though)
We have an obvious limitation: static builds won't support plugins. We
could resort to the classic method and do normal builds but on an old
distrib to dodge compatibility issues.

That would still be compatible with statically linking the more specific
libs, like e.g. z3.
@AltGr AltGr force-pushed the french_law-build branch 3 times, most recently from a852317 to e56a4b4 Compare August 3, 2022 17:26
@AltGr AltGr changed the title Generate french_law artifacts through dune & CI Docker image cleanup Build system rehaul, use of Docker for CI & artifact generation on Github Aug 3, 2022
@AltGr
Copy link
Contributor Author

AltGr commented Aug 3, 2022

Should now be OK; generation of the artifacts is only activated on the master branch but I tested it here. (I removed node's node_modules & python's env since then)

Compared to the first version, I leveraged dune's "promotion" feature which means I was able to keep the french_law artifacts in-tree as before while working around the issue of them getting stale or dune getting confused.

Copy link
Contributor

@denismerigoux denismerigoux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks awesome, a well-deserved overhaul of the build system. I raised a few nitpicks, you can merge after dealing with them.

Makefile Show resolved Hide resolved
build_release.sh Show resolved Hide resolved
@@ -16,9 +16,20 @@
ANSITerminal)
(modules clerk_driver))

(rule
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's that for ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid a failure when the custom_linking.sexp file doesn't exist (we default it to a file containing just ())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(we could also statically add the file to the source tree; the upside of that would be that it is harder to get confused because you had a stale file sitting there; but it's not very pretty)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok and the custom_linking.sexp is produced by the build_release.sh script. Maybe that would be worth a comment in the dune file. I'm in favor of not adding custom_linking.sexp to the build tree.

examples/aides_logement/dune Outdated Show resolved Hide resolved
@@ -0,0 +1 @@
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You did that to speed up the build, because we don't need to format generated files ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah indeed that's something I wanted to discuss with you!
It feels a bit strange to me to reformat just-generated files; that also adds a run-time dependency to ocamlformat for running these rules. And it complicated things (we don't want ocamlformat and dune to compete on the resulting file).

No big speedup here (but in the case of the Python files, autopep8 is very slow)

But I guess there were reasons to do this in the first place so I am open to finding a workaround if needed!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason for running ocamlformat is code readability.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to at least read the input type declarations to know what to feed your program. And since the pretty-printing in the backends is not ideal we run ocamlformat afterwards. @EmileRolley even calls directly ocamlformat in his new api_web backend plugin.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed! Just discussed the matter quickly with @EmileRolley and we agreed to disable it and focus on improving our pretty-printer on cases where readability is bad (from a quick check, it seems o.k. on type definitions). Otherwise, our pretty-printer will be completely untested: if we don't want to bother, and use OCamlformat, I'd say go all the way, simplify our pretty-printer into a bare-printer and call ocamlformat as a lib.

What do you think ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with relying on our pretty-printer and improving it as needed, dropping ocamlformat altogether. Using ocamlformat as a lib is tempting but would introduce a lot of complexity as we use only a small portion of the OCaml AST. A textual pretty-printer would be simpler for maintainers to come and just change a tidbit while not having to understand everything. Plus that way we don't have to keep in sync with ocamlformat's AST changes, while OCaml textual syntax is somewhat backwards-compatible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 that was our conclusion with @EmileRolley as well, even though printing and re-parsing is not very intellectually satisfying, generating an OCaml AST is totally impractical. My proposition on this point was meant as "use ocamlformat as a lib, but still going to/from string" — which isn't really an improvement, only a workaround for the potential dependency problem.

french_law/ocaml/law_source/aides_logement.ml Outdated Show resolved Hide resolved
french_law/ocaml/law_source/dune Outdated Show resolved Hide resolved
generate_website_assets.sh Outdated Show resolved Hide resolved
@AltGr AltGr force-pushed the french_law-build branch 2 times, most recently from 1bfbf3e to d4d7491 Compare August 4, 2022 16:08
@AltGr AltGr merged commit fb2e48d into CatalaLang:master Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants