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

Ability to tell jbuilder where to place build artifacts. #291

Closed
jordwalke opened this issue Oct 22, 2017 · 13 comments · Fixed by ocaml/opam-repository#12323
Closed

Ability to tell jbuilder where to place build artifacts. #291

jordwalke opened this issue Oct 22, 2017 · 13 comments · Fixed by ocaml/opam-repository#12323
Assignees

Comments

@jordwalke
Copy link
Contributor

We're building a project workflow, and many build/cache optimizations are opened up if we are able to tell jbuilder, where to place the artifacts (as opposed to having it be hardcoded to the _build directory). I'm curious how difficult this feature would be to add.
The feature would not merely allow customization of the name of the build directory _build vs. _jbuilder etc, but would allow passing of an arbitrary location on the file system. We could then invoke jbuilder like jbuilder build --buildDest=/myPathTo/buildDir. I believe Crate has a similar feature fwiw.

@rgrinberg
Copy link
Member

--buildDest would specify the build root right?

I think that this feature would be easy to add. The difficulty I see here is convincing the maintainers that this feature is desirable.

@jordwalke
Copy link
Contributor Author

@rgrinberg I'm not sure what you mean by "build root". The requested feature is that --buildDest would determine where jbuilder places the "root of the build directory" which is currently always at _build.

To make things simple, you could require that all invocations of jbuilder supply the same --buildDest or do not supply one at all (in which case --buildDest would default to ./_build).

@jordwalke
Copy link
Contributor Author

To explain some more about why this is a really compelling feature for us: We're building a tool that allows packages to mark themselves as supporting out of source builds, and ones that do get to share original source files, and build artifacts across many/all projects on the system (in addition to sharing them across the network which will be supported anyways). If jbuilder supports this then projects that use jbuilder will get a significant speedup in our workflow. We want to showcase how fast building multiple projects can be, and jbuilder with out-of-source builds support would make a great demonstration of this. @rgrinberg what would you imagine an objection would be?
I can imagine file watching might become more difficult, but I would absolutely be willing to give up file watching for this feature.

@ghost
Copy link

ghost commented Mar 20, 2018

This seems like a reasonable feature to support. I would use --build-dir for the option name though.

Implementation-wise, all we need to do is change Path.to_string and Path.reach to take into account the selected build directory. Though to make sure we catch all cases, we should generalize the use of the Path module. There are still a few cases in the code where we access _build directly. So I suggest to do things in this order:

  • move Path to stdune (@rgrinberg already suggested this)
  • use Path.t instead of strings for all filenames in Io, Process, etc... and do the conversion to a string as late as possible, i.e. just before call to the stdlib/unix functions
  • add a global variable for the build directory and use it for Path.to_string/Path.reach

@rgrinberg
Copy link
Member

rgrinberg commented Mar 21, 2018 via email

@jordwalke
Copy link
Contributor Author

Yeah, Rudi is right that for this feature, the important part is being able to set this automatically by the environment so that tooling can make sure that all packages build into the correct location without having to make every package owner of every dependency update their build config.

@ghost
Copy link

ghost commented Mar 21, 2018

Yep, using this feature of cmdliner seems good

@rgrinberg rgrinberg self-assigned this Apr 23, 2018
@rgrinberg
Copy link
Member

Okay, I'll try and to tackle this. It's easy enough but we do need to decide how to untangle some deps.

For example, Path relies on s-expressions to throw errors. I think it's a good pattern, so I propose moving it to stdune. This will also open the way for us to add sexp converters directly to stdune modules.

We just still need to decide what to do with Code_error. I think we can just change the meaning of this exception to be a "general programming error" rather than a jbuilder specific programming error. Then we can move it to Stdune.Exn (or Stdune.Sexp?).

@rgrinberg
Copy link
Member

rgrinberg commented Apr 23, 2018

First step in #716

@rgrinberg
Copy link
Member

@diml one property that might be interesting to enforce is to make sure that global variable for build root isn't set after it was already accessed. I'm thinking of something like:

let build_root = ref None

let set_build_root br =
  assert (!build_root = None);
  build_root := br

let build_root () =
  match !build_root with
  | None -> build_root := Some ""; ""
  | Some d -> d

This is to address the possible inconsistencies that might arise from more than 1 build_root being visible to the the rest of the code. The chances of this are slim, but perhaps this extra safety is useful?

The only issue that I see with this is that we'll need to make all those constant paths that are present around the codebase to be lazy about initializing themselves.

But perhaps it would be useful to have a Path submodule like so:

module Static : sig
  val aliases : t Lazy.t
  val db : t Lazy.t
  val log : t Lazy.t
  ...
end

@ghost
Copy link

ghost commented Apr 25, 2018

Agreed, but I think build_root should just raise rather than set the root to "". this will make it easier to track places that try to access it before it is set.

For Static, it seems to me that it should go in dune rather that stdune. I would just use unit -> t rather than t Lazy.t.

@jordwalke
Copy link
Contributor Author

This is a great feature, thank you!

@rgrinberg
Copy link
Member

Fixed in master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants