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