Page MenuHomePhabricator

rust: add a README

Authored by valentin.gatienbaron on Jan 20 2020, 6:36 PM.



In particular to explain how to build any of the rust. It's neither
obvious, nor easy to find out, nor easy to determine if you did it
right without some documentation.

Diff Detail

rHG Mercurial
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Alphare accepted this revision.Jan 21 2020, 4:32 AM
Alphare added a subscriber: Alphare.
Alphare added inline comments.

I think you're missing the -l option for


I would add a mention of using cargo c(heck) for faster iteration and using cargo test --all to run the Rust tests, but this patch is already good enough on its own.

pulkit added inline comments.

IIRC, it's now possible to use HGMODULEPOLICY=rust. @gracinet that's possible now right?

Alphare added inline comments.Jan 21 2020, 7:28 AM

HGMODULEPOLICY=rust+c to select it at runtime yes. But for not for make local AFAIK.

My general feeling is that I'd like to deprecate HGWITHRUSTEXT.

We now have python --rust [build|install|etc] and the coincidental make local PURE=--rust (works because $PURE, while meant to be for --pure is inserted blindly at the right place in the command.

Maybe this is a good time to decide of a better make variable ? EXTENSION_TYPE ? COMPILE_OPTIONS ? BUILD_OPTIONS ?

It's obviously a good thing to have official instructions, thank you Valentin for raising the subject.


HGMODULEPOLICY is for runtime, it can be rust+c or rust+c-allow.
In the first form, not having the Rust extension is a failure, in the second, there's a fallback.

"deprecate" was a bit too strong. Actually I'd like to downgrade HGWITHRUSTEXT to be something that'll be useful to play with alternative ways of building the Rust extension(s). Example: if someone wants to experiment with PyO3.

valentin.gatienbaron marked an inline comment as done.Jan 21 2020, 9:35 AM

I didn't mention --rust because the toplevel readme doesn't mention, so I don't really know if that's really how mercurial is intended to be built or an implementation detail.


When I tested, setting HGMODULEPOLICY didn't work, perhaps because of what Raphael said.


Well, one can use -l to run rust tests, but it's not mandatory?

gracinet added inline comments.Jan 21 2020, 10:10 AM

Both Raphaël and I were saying the same thin, perhaps a bit partially.

Here's the whole picture:

  • options to make or govern what is built (HGWITHRUSTEXT also).
  • among the built extensions, what is actually used at runtime depends on the module policy, which is read from mercurial/ and can be overridden by HGMODULEPOLICY ,
  • at build time, a default policy value is set in mercurial/ For the record, this is rust+c-allow for local builds with Rust and rust+c for other Rust builds.

This policy system is actuallly not specific to Rust, it's also in use with the C extensions, the major difference being that C extensions are built by default.

For example, if one does not build the C extensions and use HGMODULEPOLICY=c, that's a hard error. With HGMODULEPOLICY=allow, one gets a fallback to the pure implementation.

Same with Rust: rust+c gives a hard error is Rust isn't built, while rust+c-allow fallbacks to C extensions only

pulkit accepted this revision.Jan 21 2020, 11:02 AM
This revision is now accepted and ready to land.Jan 21 2020, 11:02 AM
This revision was automatically updated to reflect the committed changes.