##// END OF EJS Templates
rust-readme: rst fixes
Georges Racinet -
r51280:5d20fc23 default
parent child Browse files
Show More
@@ -1,124 +1,126 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 four independent Rust projects:
9 There are currently four independent Rust projects:
10
10 - chg. An implementation of chg, in Rust instead of C.
11 - chg. An implementation of chg, in Rust instead of C.
11 - hgcli. A project that provides a (mostly) self-contained "hg" binary,
12 - hgcli. A project that provides a (mostly) self-contained "hg" binary,
12 for ease of deployment and a bit of speed, using PyOxidizer. See
13 for ease of deployment and a bit of speed, using PyOxidizer. See
13 hgcli/README.md.
14 ``hgcli/README.md``.
14 - hg-core (and hg-cpython): implementation of some
15 - hg-core (and hg-cpython): implementation of some
15 functionality of mercurial in Rust, e.g. ancestry computations in
16 functionality of mercurial in Rust, e.g. ancestry computations in
16 revision graphs, status or pull discovery. The top-level ``Cargo.toml`` file
17 revision graphs, status or pull discovery. The top-level ``Cargo.toml`` file
17 defines a workspace containing these crates.
18 defines a workspace containing these crates.
18 - rhg: a pure Rust implementation of Mercurial, with a fallback mechanism for
19 - rhg: a pure Rust implementation of Mercurial, with a fallback mechanism for
19 unsupported invocations. It reuses the logic `hg-core` but completely forgoes
20 unsupported invocations. It reuses the logic ``hg-core`` but
20 interaction with Python. See `rust/rhg/README.md` for more details.
21 completely forgoes interaction with Python. See
22 ``rust/rhg/README.md`` for more details.
21
23
22 Using Rust code
24 Using Rust code
23 ===============
25 ===============
24
26
25 Local use (you need to clean previous build artifacts if you have
27 Local use (you need to clean previous build artifacts if you have
26 built without rust previously)::
28 built without rust previously)::
27
29
28 $ make PURE=--rust local # to use ./hg
30 $ make PURE=--rust local # to use ./hg
29 $ ./tests/run-tests.py --rust # to run all tests
31 $ ./tests/run-tests.py --rust # to run all tests
30 $ ./hg debuginstall | grep -i rust # to validate rust is in use
32 $ ./hg debuginstall | grep -i rust # to validate rust is in use
31 checking Rust extensions (installed)
33 checking Rust extensions (installed)
32 checking module policy (rust+c-allow)
34 checking module policy (rust+c-allow)
33
35
34 If the environment variable ``HGWITHRUSTEXT=cpython`` is set, the Rust
36 If the environment variable ``HGWITHRUSTEXT=cpython`` is set, the Rust
35 extension will be used by default unless ``--no-rust``.
37 extension will be used by default unless ``--no-rust``.
36
38
37 One day we may use this environment variable to switch to new experimental
39 One day we may use this environment variable to switch to new experimental
38 binding crates like a hypothetical ``HGWITHRUSTEXT=hpy``.
40 binding crates like a hypothetical ``HGWITHRUSTEXT=hpy``.
39
41
40 Special features
42 Special features
41 ================
43 ================
42
44
43 In the future, compile-time opt-ins may be added
45 In the future, compile-time opt-ins may be added
44 to the `features` section in ``hg-cpython/Cargo.toml``.
46 to the ``features`` section in ``hg-cpython/Cargo.toml``.
45
47
46 To use features from the Makefile, use the `HG_RUST_FEATURES` environment
48 To use features from the Makefile, use the ``HG_RUST_FEATURES`` environment
47 variable: for instance `HG_RUST_FEATURES="some-feature other-feature"`
49 variable: for instance ``HG_RUST_FEATURES="some-feature other-feature"``.
48
50
49 Profiling
51 Profiling
50 =========
52 =========
51
53
52 Setting the environment variable ``RUST_LOG=trace`` will make hg print
54 Setting the environment variable ``RUST_LOG=trace`` will make hg print
53 a few high level rust-related performance numbers. It can also
55 a few high level rust-related performance numbers. It can also
54 indicate why the rust code cannot be used (say, using lookarounds in
56 indicate why the rust code cannot be used (say, using lookarounds in
55 hgignore).
57 hgignore).
56
58
57 Creating a ``.cargo/config`` file with the following content enables
59 Creating a ``.cargo/config`` file with the following content enables
58 debug information in optimized builds. This make profiles more informative
60 debug information in optimized builds. This make profiles more informative
59 with source file name and line number for Rust stack frames and
61 with source file name and line number for Rust stack frames and
60 (in some cases) stack frames for Rust functions that have been inlined.
62 (in some cases) stack frames for Rust functions that have been inlined::
61
63
62 [profile.release]
64 [profile.release]
63 debug = true
65 debug = true
64
66
65 ``py-spy`` (https://github.com/benfred/py-spy) can be used to
67 ``py-spy`` (https://github.com/benfred/py-spy) can be used to
66 construct a single profile with rust functions and python functions
68 construct a single profile with rust functions and python functions
67 (as opposed to ``hg --profile``, which attributes time spent in rust
69 (as opposed to ``hg --profile``, which attributes time spent in rust
68 to some unlucky python code running shortly after the rust code, and
70 to some unlucky python code running shortly after the rust code, and
69 as opposed to tools for native code like ``perf``, which attribute
71 as opposed to tools for native code like ``perf``, which attribute
70 time to the python interpreter instead of python functions).
72 time to the python interpreter instead of python functions).
71
73
72 Example usage:
74 Example usage::
73
75
74 $ make PURE=--rust local # Don't forget to recompile after a code change
76 $ make PURE=--rust local # Don't forget to recompile after a code change
75 $ py-spy record --native --output /tmp/profile.svg -- ./hg ...
77 $ py-spy record --native --output /tmp/profile.svg -- ./hg ...
76
78
77 Developing Rust
79 Developing Rust
78 ===============
80 ===============
79
81
80 The current version of Rust in use is ``1.61.0``, because it's what Debian
82 The current version of Rust in use is ``1.61.0``, because it's what Debian
81 testing has. You can use ``rustup override set 1.61.0`` at the root of the repo
83 testing has. You can use ``rustup override set 1.61.0`` at the root of the repo
82 to make it easier on you.
84 to make it easier on you.
83
85
84 Go to the ``hg-cpython`` folder::
86 Go to the ``hg-cpython`` folder::
85
87
86 $ cd rust/hg-cpython
88 $ cd rust/hg-cpython
87
89
88 Or, only the ``hg-core`` folder. Be careful not to break compatibility::
90 Or, only the ``hg-core`` folder. Be careful not to break compatibility::
89
91
90 $ cd rust/hg-core
92 $ cd rust/hg-core
91
93
92 Simply run::
94 Simply run::
93
95
94 $ cargo build --release
96 $ cargo build --release
95
97
96 It is possible to build without ``--release``, but it is not
98 It is possible to build without ``--release``, but it is not
97 recommended if performance is of any interest: there can be an order
99 recommended if performance is of any interest: there can be an order
98 of magnitude of degradation when removing ``--release``.
100 of magnitude of degradation when removing ``--release``.
99
101
100 For faster builds, you may want to skip code generation::
102 For faster builds, you may want to skip code generation::
101
103
102 $ cargo check
104 $ cargo check
103
105
104 For even faster typing::
106 For even faster typing::
105
107
106 $ cargo c
108 $ cargo c
107
109
108 You can run only the rust-specific tests (as opposed to tests of
110 You can run only the rust-specific tests (as opposed to tests of
109 mercurial as a whole) with::
111 mercurial as a whole) with::
110
112
111 $ cargo test --all
113 $ cargo test --all
112
114
113 Formatting the code
115 Formatting the code
114 -------------------
116 -------------------
115
117
116 We use ``rustfmt`` to keep the code formatted at all times. For now, we are
118 We use ``rustfmt`` to keep the code formatted at all times. For now, we are
117 using the nightly version because it has been stable enough and provides
119 using the nightly version because it has been stable enough and provides
118 comment folding.
120 comment folding.
119
121
120 To format the entire Rust workspace::
122 To format the entire Rust workspace::
121
123
122 $ cargo +nightly fmt
124 $ cargo +nightly fmt
123
125
124 This requires you to have the nightly toolchain installed.
126 This requires you to have the nightly toolchain installed.
General Comments 0
You need to be logged in to leave comments. Login now