Skip to content
This repository has been archived by the owner on Aug 25, 2022. It is now read-only.

Replace dynlink method by a 2-stage build #171

Merged
merged 1 commit into from
Jun 17, 2019

Conversation

TheLortex
Copy link
Member

Hi, this is quite a heavy PR. I can try to minimize the diff if you want.

Why

The dynlink method to load config.ml feels quite fragile, as it requires mirage and config.ml to be built with the same code / options. When compiling using dune, these assumptions can be broken:

  • config.ml can be built with a local instance of the mirage source code.
  • Link-time optimizations might not be enabled for mirage but are enabled for config.ml.

Proposal

Instead of dynlinking config.ml, we can perform a 2-stage build of the configuration !
(1) Locally build config.ml
(2) Execute config.ml, which calls some entry function in Functoria_app

There are several ways of doing it:

  • Breaking changes for both config.ml and mirage:
    • Separate Functoria_app.Make in two functors, one that builds the config.ml and one that is called by the built config.ml
    • Change register ... to a more appropriate name
  • Breaking changes for mirage:
    • Only perform the separation of Make and have register ... as the entry point of (2)
  • No breaking changes:
    • Keep everything under Make and hack with the names that are currently used.

I've implemented the intermediate solution. This is probably far from perfect but I'd like to have feedback on that :)

@TheLortex TheLortex requested review from samoht and avsm and removed request for samoht May 10, 2019 09:48
@cfcs
Copy link

cfcs commented May 14, 2019

@TheLortex I'm super excited about this since I think it can pave the way for external device types/implementations. I cannot get this to build though, can you link to the corresponding mirage branch?

@TheLortex
Copy link
Member Author

The PR currently breaks API with Mirage, but it's not necessary, I'm waiting for comments on this.

There are two branches of https://github.com/TheLortex/mirage that implement the change of this PR:

app/functoria_app.ml Outdated Show resolved Hide resolved
app/functoria_app.ml Outdated Show resolved Hide resolved
app/functoria_app.ml Outdated Show resolved Hide resolved
app/functoria_app.mli Outdated Show resolved Hide resolved
Copy link
Member

@samoht samoht left a comment

Choose a reason for hiding this comment

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

I've added a few more comments, but otherwise that looks good.

app/functoria_app.ml Outdated Show resolved Hide resolved
app/functoria_app.ml Outdated Show resolved Hide resolved
app/functoria_app.ml Outdated Show resolved Hide resolved
app/functoria_app.ml Outdated Show resolved Hide resolved

let register ?packages ?keys ?(init=default_init) name jobs =
(* Compile the configuration file. *)
let compile file_ml_path =
Copy link
Member

Choose a reason for hiding this comment

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

This function is slightly too big and convoluted. Could you add a bit of documentation describing 1) which files are created (and where) 2) what is expected to go into dune.config and what will be the result and 3) extract a few helpers functions to make the body of the function straightforward (as it should be :-) ).

This could be added either here or in the mli but an example of dune.config should definitely go into the mli.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have refactored this function, separated code and added some documentation !
Regarding dune.config it's probably good to document it in the readme (that needs an update anyway)

tests/lib/test_app.ml Outdated Show resolved Hide resolved
tests/lib/test_app.ml Show resolved Hide resolved
app/functoria_app.ml Outdated Show resolved Hide resolved
| `Exited 0 -> Ok (Fpath.(to_string (target_dir / file)))
| `Exited _
| `Signaled _ ->
Format.fprintf Format.str_formatter "error while executing %a\n%s"
Copy link
Member

Choose a reason for hiding this comment

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

This is:

let err = Fmt.strf "error while executing %a\n%s" Bos.Cmd.pp cmd out in
Error (`Invalid_config_ml  x)

It would even be better to move the creation of error values in separate functions (so it's easier to spot the different failure modes in one go) but this is not necessary to do for the given PR.
and | Signaled _ -> err_invalid_config_ml cmd out`

Copy link
Member Author

Choose a reason for hiding this comment

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

I haven't separated functions but I updated it according to your review

TheLortex added a commit to TheLortex/functoria that referenced this pull request Jun 5, 2019
@samoht
Copy link
Member

samoht commented Jun 17, 2019

Looks good, merging!

@samoht samoht merged commit 319adb8 into mirage:master Jun 17, 2019
@TheLortex TheLortex deleted the no-dynlink branch July 8, 2019 13:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants