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