Show More
@@ -1,73 +1,77 b'' | |||||
1 | syntax: glob |
|
1 | syntax: glob | |
2 |
|
2 | |||
3 | *.elc |
|
3 | *.elc | |
4 | *.tmp |
|
4 | *.tmp | |
5 | *.orig |
|
5 | *.orig | |
6 | *.rej |
|
6 | *.rej | |
7 | *~ |
|
7 | *~ | |
8 | *.mergebackup |
|
8 | *.mergebackup | |
9 | *.o |
|
9 | *.o | |
10 | *.so |
|
10 | *.so | |
11 | *.dll |
|
11 | *.dll | |
12 | *.exe |
|
12 | *.exe | |
13 | *.pyd |
|
13 | *.pyd | |
14 | *.pyc |
|
14 | *.pyc | |
15 | *.pyo |
|
15 | *.pyo | |
16 | *$py.class |
|
16 | *$py.class | |
17 | *.swp |
|
17 | *.swp | |
18 | *.prof |
|
18 | *.prof | |
19 | *.zip |
|
19 | *.zip | |
20 | \#*\# |
|
20 | \#*\# | |
21 | .\#* |
|
21 | .\#* | |
22 | tests/artifacts/cache/big-file-churn.hg |
|
22 | tests/artifacts/cache/big-file-churn.hg | |
23 | tests/.coverage* |
|
23 | tests/.coverage* | |
24 | tests/.testtimes* |
|
24 | tests/.testtimes* | |
25 | tests/.hypothesis |
|
25 | tests/.hypothesis | |
26 | tests/hypothesis-generated |
|
26 | tests/hypothesis-generated | |
27 | tests/annotated |
|
27 | tests/annotated | |
28 | tests/exceptions |
|
28 | tests/exceptions | |
29 | tests/*.err |
|
29 | tests/*.err | |
30 | tests/htmlcov |
|
30 | tests/htmlcov | |
31 | build |
|
31 | build | |
32 | contrib/chg/chg |
|
32 | contrib/chg/chg | |
33 | contrib/hgsh/hgsh |
|
33 | contrib/hgsh/hgsh | |
34 | contrib/vagrant/.vagrant |
|
34 | contrib/vagrant/.vagrant | |
35 | dist |
|
35 | dist | |
36 | packages |
|
36 | packages | |
37 | doc/common.txt |
|
37 | doc/common.txt | |
38 | doc/*.[0-9] |
|
38 | doc/*.[0-9] | |
39 | doc/*.[0-9].txt |
|
39 | doc/*.[0-9].txt | |
40 | doc/*.[0-9].gendoc.txt |
|
40 | doc/*.[0-9].gendoc.txt | |
41 | doc/*.[0-9].{x,ht}ml |
|
41 | doc/*.[0-9].{x,ht}ml | |
42 | MANIFEST |
|
42 | MANIFEST | |
43 | MANIFEST.in |
|
43 | MANIFEST.in | |
44 | patches |
|
44 | patches | |
45 | mercurial/__modulepolicy__.py |
|
45 | mercurial/__modulepolicy__.py | |
46 | mercurial/__version__.py |
|
46 | mercurial/__version__.py | |
47 | mercurial/hgpythonlib.h |
|
47 | mercurial/hgpythonlib.h | |
48 | mercurial.egg-info |
|
48 | mercurial.egg-info | |
49 | .DS_Store |
|
49 | .DS_Store | |
50 | tags |
|
50 | tags | |
51 | cscope.* |
|
51 | cscope.* | |
52 | .vscode/* |
|
52 | .vscode/* | |
53 | .idea/* |
|
53 | .idea/* | |
54 | .asv/* |
|
54 | .asv/* | |
55 | .pytype/* |
|
55 | .pytype/* | |
56 | .mypy_cache |
|
56 | .mypy_cache | |
57 | i18n/hg.pot |
|
57 | i18n/hg.pot | |
58 | locale/*/LC_MESSAGES/hg.mo |
|
58 | locale/*/LC_MESSAGES/hg.mo | |
59 | hgext/__index__.py |
|
59 | hgext/__index__.py | |
60 |
|
60 | |||
61 | rust/target/ |
|
61 | rust/target/ | |
62 | rust/*/target/ |
|
62 | rust/*/target/ | |
63 |
|
63 | |||
64 | # Generated wheels |
|
64 | # Generated wheels | |
65 | wheelhouse/ |
|
65 | wheelhouse/ | |
66 |
|
66 | |||
|
67 | syntax: rootglob | |||
|
68 | # See Profiling in rust/README.rst | |||
|
69 | .cargo/config | |||
|
70 | ||||
67 | syntax: regexp |
|
71 | syntax: regexp | |
68 | ^\.pc/ |
|
72 | ^\.pc/ | |
69 | ^\.(pydev)?project |
|
73 | ^\.(pydev)?project | |
70 |
|
74 | |||
71 | # hackable windows distribution additions |
|
75 | # hackable windows distribution additions | |
72 | ^hg-python |
|
76 | ^hg-python | |
73 | ^hg.py$ |
|
77 | ^hg.py$ |
@@ -1,108 +1,121 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 project that provide a (mostly) self-contained "hg" binary, |
|
11 | - hgcli. A project that provide a (mostly) self-contained "hg" binary, | |
12 | for ease of deployment and a bit of speed, using PyOxidizer. See |
|
12 | for ease of deployment and a bit of speed, using PyOxidizer. See | |
13 | hgcli/README.md. |
|
13 | hgcli/README.md. | |
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 |
|
30 | |||
31 | If the environment variable ``HGWITHRUSTEXT=cpython`` is set, the Rust |
|
31 | If the environment variable ``HGWITHRUSTEXT=cpython`` is set, the Rust | |
32 | extension will be used by default unless ``--no-rust``. |
|
32 | extension will be used by default unless ``--no-rust``. | |
33 |
|
33 | |||
34 | One day we may use this environment variable to switch to new experimental |
|
34 | One day we may use this environment variable to switch to new experimental | |
35 | binding crates like a hypothetical ``HGWITHRUSTEXT=hpy``. |
|
35 | binding crates like a hypothetical ``HGWITHRUSTEXT=hpy``. | |
36 |
|
36 | |||
37 | Special features |
|
37 | Special features | |
38 | ================ |
|
38 | ================ | |
39 |
|
39 | |||
40 | You might want to check the `features` section in ``hg-cpython/Cargo.toml``. |
|
40 | You might want to check the `features` section in ``hg-cpython/Cargo.toml``. | |
41 | It may contain features that might be interesting to try out. |
|
41 | It may contain features that might be interesting to try out. | |
42 |
|
42 | |||
43 |
To use features from the Makefile, use the `HG_RUST_FEATURES` environment |
|
43 | To use features from the Makefile, use the `HG_RUST_FEATURES` environment | |
44 | variable: for instance `HG_RUST_FEATURES="some-feature other-feature"` |
|
44 | variable: for instance `HG_RUST_FEATURES="some-feature other-feature"` | |
45 |
|
45 | |||
46 | Profiling |
|
46 | Profiling | |
47 | ========= |
|
47 | ========= | |
48 |
|
48 | |||
49 | Setting the environment variable ``RUST_LOG=trace`` will make hg print |
|
49 | Setting the environment variable ``RUST_LOG=trace`` will make hg print | |
50 | a few high level rust-related performance numbers. It can also |
|
50 | a few high level rust-related performance numbers. It can also | |
51 | indicate why the rust code cannot be used (say, using lookarounds in |
|
51 | indicate why the rust code cannot be used (say, using lookarounds in | |
52 | hgignore). |
|
52 | hgignore). | |
53 |
|
53 | |||
|
54 | Creating a ``.cargo/config`` file with the following content enables | |||
|
55 | debug information in optimized builds. This make profiles more informative | |||
|
56 | with source file name and line number for Rust stack frames and | |||
|
57 | (in some cases) stack frames for Rust functions that have been inlined. | |||
|
58 | ||||
|
59 | [profile.release] | |||
|
60 | debug = true | |||
|
61 | ||||
54 | ``py-spy`` (https://github.com/benfred/py-spy) can be used to |
|
62 | ``py-spy`` (https://github.com/benfred/py-spy) can be used to | |
55 | construct a single profile with rust functions and python functions |
|
63 | construct a single profile with rust functions and python functions | |
56 | (as opposed to ``hg --profile``, which attributes time spent in rust |
|
64 | (as opposed to ``hg --profile``, which attributes time spent in rust | |
57 | to some unlucky python code running shortly after the rust code, and |
|
65 | to some unlucky python code running shortly after the rust code, and | |
58 | as opposed to tools for native code like ``perf``, which attribute |
|
66 | as opposed to tools for native code like ``perf``, which attribute | |
59 | time to the python interpreter instead of python functions). |
|
67 | time to the python interpreter instead of python functions). | |
60 |
|
68 | |||
|
69 | Example usage: | |||
|
70 | ||||
|
71 | $ make PURE=--rust local # Don't forget to recompile after a code change | |||
|
72 | $ py-spy record --native --output /tmp/profile.svg -- ./hg ... | |||
|
73 | ||||
61 | Developing Rust |
|
74 | Developing Rust | |
62 | =============== |
|
75 | =============== | |
63 |
|
76 | |||
64 | The current version of Rust in use is ``1.41.1``, because it's what Debian |
|
77 | The current version of Rust in use is ``1.41.1``, because it's what Debian | |
65 | stable has. You can use ``rustup override set 1.41.1`` at the root of the repo |
|
78 | stable has. You can use ``rustup override set 1.41.1`` at the root of the repo | |
66 | to make it easier on you. |
|
79 | to make it easier on you. | |
67 |
|
80 | |||
68 | Go to the ``hg-cpython`` folder:: |
|
81 | Go to the ``hg-cpython`` folder:: | |
69 |
|
82 | |||
70 | $ cd rust/hg-cpython |
|
83 | $ cd rust/hg-cpython | |
71 |
|
84 | |||
72 | Or, only the ``hg-core`` folder. Be careful not to break compatibility:: |
|
85 | Or, only the ``hg-core`` folder. Be careful not to break compatibility:: | |
73 |
|
86 | |||
74 | $ cd rust/hg-core |
|
87 | $ cd rust/hg-core | |
75 |
|
88 | |||
76 | Simply run:: |
|
89 | Simply run:: | |
77 |
|
90 | |||
78 | $ cargo build --release |
|
91 | $ cargo build --release | |
79 |
|
92 | |||
80 | It is possible to build without ``--release``, but it is not |
|
93 | It is possible to build without ``--release``, but it is not | |
81 | recommended if performance is of any interest: there can be an order |
|
94 | recommended if performance is of any interest: there can be an order | |
82 | of magnitude of degradation when removing ``--release``. |
|
95 | of magnitude of degradation when removing ``--release``. | |
83 |
|
96 | |||
84 | For faster builds, you may want to skip code generation:: |
|
97 | For faster builds, you may want to skip code generation:: | |
85 |
|
98 | |||
86 | $ cargo check |
|
99 | $ cargo check | |
87 |
|
100 | |||
88 | For even faster typing:: |
|
101 | For even faster typing:: | |
89 |
|
102 | |||
90 | $ cargo c |
|
103 | $ cargo c | |
91 |
|
104 | |||
92 | You can run only the rust-specific tests (as opposed to tests of |
|
105 | You can run only the rust-specific tests (as opposed to tests of | |
93 | mercurial as a whole) with:: |
|
106 | mercurial as a whole) with:: | |
94 |
|
107 | |||
95 | $ cargo test --all |
|
108 | $ cargo test --all | |
96 |
|
109 | |||
97 | Formatting the code |
|
110 | Formatting the code | |
98 | ------------------- |
|
111 | ------------------- | |
99 |
|
112 | |||
100 | We use ``rustfmt`` to keep the code formatted at all times. For now, we are |
|
113 | We use ``rustfmt`` to keep the code formatted at all times. For now, we are | |
101 | using the nightly version because it has been stable enough and provides |
|
114 | using the nightly version because it has been stable enough and provides | |
102 | comment folding. |
|
115 | comment folding. | |
103 |
|
116 | |||
104 | To format the entire Rust workspace:: |
|
117 | To format the entire Rust workspace:: | |
105 |
|
118 | |||
106 | $ cargo +nightly fmt |
|
119 | $ cargo +nightly fmt | |
107 |
|
120 | |||
108 | This requires you to have the nightly toolchain installed. |
|
121 | This requires you to have the nightly toolchain installed. |
General Comments 0
You need to be logged in to leave comments.
Login now