##// END OF EJS Templates
rust: update README to reflect use of `regex` crate...
Raphaël Gomès -
r45091:c13cbc38 default
parent child Browse files
Show More
@@ -1,109 +1,119 b''
1 1 ===================
2 2 Mercurial Rust Code
3 3 ===================
4 4
5 5 This directory contains various Rust code for the Mercurial project.
6 6 Rust is not required to use (or build) Mercurial, but using it
7 7 improves performance in some areas.
8 8
9 9 There are currently three independent rust projects:
10 10 - chg. An implementation of chg, in rust instead of C.
11 11 - hgcli. A experiment for starting hg in rust rather than in python,
12 12 by linking with the python runtime. Probably meant to be replaced by
13 13 PyOxidizer at some point.
14 14 - hg-core (and hg-cpython): implementation of some
15 15 functionality of mercurial in rust, e.g. ancestry computations in
16 16 revision graphs, status or pull discovery. The top-level ``Cargo.toml`` file
17 17 defines a workspace containing these crates.
18 18
19 19 Using Rust code
20 20 ===============
21 21
22 22 Local use (you need to clean previous build artifacts if you have
23 23 built without rust previously)::
24 24
25 25 $ make PURE=--rust local # to use ./hg
26 26 $ ./tests/run-tests.py --rust # to run all tests
27 27 $ ./hg debuginstall | grep -i rust # to validate rust is in use
28 28 checking Rust extensions (installed)
29 29 checking module policy (rust+c-allow)
30 30 checking "re2" regexp engine Rust bindings (installed)
31 31
32 32
33 33 If the environment variable ``HGWITHRUSTEXT=cpython`` is set, the Rust
34 34 extension will be used by default unless ``--no-rust``.
35 35
36 36 One day we may use this environment variable to switch to new experimental
37 37 binding crates like a hypothetical ``HGWITHRUSTEXT=hpy``.
38 38
39 Using the full ``hg status`` extension
40 --------------------------------------
39 Using the fastest ``hg status``
40 -------------------------------
41 41
42 42 The code for ``hg status`` needs to conform to ``.hgignore`` rules, which are
43 all translated into regex. For compatibility and ease of development reasons
44 the Re2 regex engine is in use until we figure out if the ``regex`` crate has
45 similar enough behavior. This implies that you need to install ``Re2``
46 following Google's guidelines: https://github.com/google/re2/wiki/Install
43 all translated into regex.
44
45 In the first version, for compatibility and ease of development reasons, the
46 Re2 regex engine was chosen until we figured out if the ``regex`` crate had
47 similar enough behavior.
47 48
49 Now that that work has been done, the default behavior is to use the ``regex``
50 crate, that provides a significant performance boost compared to the standard
51 Python + C path in many commands such as ``status``, ``diff`` and ``commit``,
52
53 However, the ``Re2`` path remains slightly faster for our use cases and remains
54 a better option for getting the most speed out of your Mercurial.
55
56 If you want to use ``Re2``, you need to install ``Re2`` following Google's
57 guidelines: https://github.com/google/re2/wiki/Install
48 58 Then, use ``HG_RUST_FEATURES=with-re2`` when building ``hg`` to use the full
49 59 status code.
50 60
51 61 Developing Rust
52 62 ===============
53 63
54 64 The current version of Rust in use is ``1.34.2``, because it's what Debian
55 65 stable has. You can use ``rustup override set 1.34.2`` at the root of the repo
56 66 to make it easier on you.
57 67
58 68 Go to the ``hg-cpython`` folder::
59 69
60 70 $ cd rust/hg-cpython
61 71
62 72 Or, only the ``hg-core`` folder. Be careful not to break compatibility::
63 73
64 74 $ cd rust/hg-core
65 75
66 76 Simply run::
67 77
68 78 $ cargo build --release
69 79
70 80 It is possible to build without ``--release``, but it is not
71 81 recommended if performance is of any interest: there can be an order
72 82 of magnitude of degradation when removing ``--release``.
73 83
74 84 For faster builds, you may want to skip code generation::
75 85
76 86 $ cargo check
77 87
78 88 For even faster typing::
79 89
80 90 $ cargo c
81 91
82 92 You can run only the rust-specific tests (as opposed to tests of
83 93 mercurial as a whole) with::
84 94
85 95 $ cargo test --all
86 96
87 97 Formatting the code
88 98 -------------------
89 99
90 100 We use ``rustfmt`` to keep the code formatted at all times. For now, we are
91 101 using the nightly version because it has been stable enough and provides
92 102 comment folding.
93 103
94 104 To format the entire Rust workspace::
95 105
96 106 $ cargo +nightly fmt
97 107
98 108 This requires you to have the nightly toolchain installed.
99 109
100 110 Additional features
101 111 -------------------
102 112
103 113 As mentioned in the section about ``hg status``, code paths using ``re2`` are
104 114 opt-in.
105 115
106 116 For example::
107 117
108 118 $ cargo check --features with-re2
109 119
General Comments 0
You need to be logged in to leave comments. Login now