Debian Codegraph @

book/src/building-from-source.md

raw symbols SCIP
1 ## Building from source
2
3 - [Configuring Helix's runtime files](#configuring-helixs-runtime-files)
4 - [Linux and macOS](#linux-and-macos)
5 - [Windows](#windows)
6 - [Multiple runtime directories](#multiple-runtime-directories)
7 - [Note to packagers](#note-to-packagers)
8 - [Validating the installation](#validating-the-installation)
9 - [Configure the desktop shortcut](#configure-the-desktop-shortcut)
10 - [Building the Debian package](#building-the-debian-package)
11
12 Requirements:
13
14 Clone the Helix GitHub repository into a directory of your choice. The
15 examples in this documentation assume installation into either `~/src/` on
16 Linux and macOS, or `%userprofile%\src\` on Windows.
17
18 - The [Rust toolchain](https://www.rust-lang.org/tools/install)
19 - The [Git version control system](https://git-scm.com/)
20 - A C++14 compatible compiler to build the tree-sitter grammars, for example GCC or Clang
21
22 If you are using the `musl-libc` standard library instead of `glibc` the following environment variable must be set during the build to ensure tree-sitter grammars can be loaded correctly:
23
24 ```sh
25 RUSTFLAGS="-C target-feature=-crt-static"
26 ```
27
28 1. Clone the repository:
29
30 ```sh
31 git clone https://github.com/helix-editor/helix
32 cd helix
33 ```
34
35 2. Compile from source:
36
37 ```sh
38 # Reproducible
39 cargo install --path helix-term --locked
40 ```
41 ```sh
42 # Optimized
43 cargo install \
44 --profile opt \
45 --config 'build.rustflags=["-C", "target-cpu=native"]' \
46 --path helix-term \
47 --locked
48 ```
49
50 Either command will create the `hx` executable and construct the tree-sitter
51 grammars in the local `runtime` folder.
52
53 > 💡 If you do not want to fetch or build grammars, set an environment variable `HELIX_DISABLE_AUTO_GRAMMAR_BUILD`
54
55 > 💡 Tree-sitter grammars can be fetched and compiled if not pre-packaged. Fetch
56 > grammars with `hx --grammar fetch` and compile them with
57 > `hx --grammar build`. This will install them in
58 > the `runtime` directory within the user's helix config directory (more
59 > [details below](#multiple-runtime-directories)).
60
61 > 💡 If you only want to build _some_ grammars, see [`use-grammars`](./languages.md#choosing-grammars)
62
63 ### Configuring Helix's runtime files
64
65 #### Linux and macOS
66
67 The **runtime** directory is one below the Helix source, so either export a
68 `HELIX_RUNTIME` environment variable to point to that directory and add it to
69 your `~/.bashrc` or equivalent:
70
71 ```sh
72 export HELIX_RUNTIME=~/src/helix/runtime
73 ```
74
75 Or, create a symbolic link:
76
77 ```sh
78 ln -Tsf $PWD/runtime ~/.config/helix/runtime
79 ```
80
81 #### Windows
82
83 Either set the `HELIX_RUNTIME` environment variable to point to the runtime files using the Windows setting (search for
84 `Edit environment variables for your account`) or use the `setx` command in
85 Cmd:
86
87 ```sh
88 setx HELIX_RUNTIME "%userprofile%\src\helix\runtime"
89 ```
90
91 > 💡 `%userprofile%` resolves to your user directory like
92 > `C:\Users\Your-Name\` for example.
93
94 Or, create a symlink in `%appdata%\helix\` that links to the source code directory:
95
96 | Method | Command |
97 | ---------- | -------------------------------------------------------------------------------------- |
98 | PowerShell | `New-Item -ItemType Junction -Target "runtime" -Path "$Env:AppData\helix\runtime"` |
99 | Cmd | `cd %appdata%\helix` <br/> `mklink /D runtime "%userprofile%\src\helix\runtime"` |
100
101 > 💡 On Windows, creating a symbolic link may require running PowerShell or
102 > Cmd as an administrator.
103
104 #### Multiple runtime directories
105
106 When Helix finds multiple runtime directories it will search through them for files in the
107 following order:
108
109 1. `runtime/` sibling directory to `$CARGO_MANIFEST_DIR` directory (this is intended for
110 developing and testing helix only).
111 2. `runtime/` subdirectory of OS-dependent helix user config directory.
112 3. `$HELIX_RUNTIME`
113 4. Distribution-specific fallback directory (set at compile time—not run time—
114 with the `HELIX_DEFAULT_RUNTIME` environment variable)
115 5. `runtime/` subdirectory of path to Helix executable.
116
117 This order also sets the priority for selecting which file will be used if multiple runtime
118 directories have files with the same name.
119
120 #### Note to packagers
121
122 If you are making a package of Helix for end users, to provide a good out of
123 the box experience, you should set the `HELIX_DEFAULT_RUNTIME` environment
124 variable at build time (before invoking `cargo build`) to a directory which
125 will store the final runtime files after installation. For example, say you want
126 to package the runtime into `/usr/lib/helix/runtime`. The rough steps a build
127 script could follow are:
128
129 1. `export HELIX_DEFAULT_RUNTIME=/usr/lib/helix/runtime`
130 1. `cargo build --profile opt --locked`
131 1. `cp -r runtime $BUILD_DIR/usr/lib/helix/`
132 1. `cp target/opt/hx $BUILD_DIR/usr/bin/hx`
133
134 This way the resulting `hx` binary will always look for its runtime directory in
135 `/usr/lib/helix/runtime` if the user has no custom runtime in `~/.config/helix`
136 or `HELIX_RUNTIME`.
137
138 ### Validating the installation
139
140 To make sure everything is set up as expected you should run the Helix health
141 check:
142
143 ```sh
144 hx --health
145 ```
146
147 For more information on the health check results refer to
148 [Health check](https://github.com/helix-editor/helix/wiki/Healthcheck).
149
150 ### Configure the desktop shortcut
151
152 If your desktop environment supports the
153 [XDG desktop menu](https://specifications.freedesktop.org/menu-spec/menu-spec-latest.html)
154 you can configure Helix to show up in the application menu by copying the
155 provided `.desktop` and icon files to their correct folders:
156
157 ```sh
158 cp contrib/Helix.desktop ~/.local/share/applications
159 cp contrib/helix.png ~/.icons # or ~/.local/share/icons
160 ```
161 It is recommended to convert the links in the `.desktop` file to absolute paths to avoid potential problems:
162
163 ```sh
164 sed -i -e "s|Exec=hx %F|Exec=$(readlink -f ~/.cargo/bin/hx) %F|g" \
165 -e "s|Icon=helix|Icon=$(readlink -f ~/.icons/helix.png)|g" ~/.local/share/applications/Helix.desktop
166 ```
167
168 To use another terminal than the system default, you can modify the `.desktop`
169 file. For example, to use `kitty`:
170
171 ```sh
172 sed -i "s|Exec=hx %F|Exec=kitty hx %F|g" ~/.local/share/applications/Helix.desktop
173 sed -i "s|Terminal=true|Terminal=false|g" ~/.local/share/applications/Helix.desktop
174 ```
175
176 ### Building the Debian package
177
178 If the `.deb` file provided on the release page uses a `libc` version higher
179 than that used by your Debian, Ubuntu, or Mint system, you can build the package
180 from source to match your system's dependencies.
181
182 Install `cargo-deb`, the tool used for building the `.deb` file:
183
184 ```sh
185 cargo install cargo-deb
186 ```
187
188 After cloning and entering the Helix repository as previously described,
189 use the following command to build the release binary and package it into a `.deb` file in a single step.
190
191 ```sh
192 cargo deb -- --locked
193 ```
194
195 > 💡 This locks you into the `--release` profile. But you can also build helix in any way you like.
196 > As long as you leave a `target/release/hx` file, it will get packaged with `cargo deb --no-build`
197
198 > 💡 Don't worry about the following:
199 > ```
200 > warning: Failed to find dependency specification
201 > ```
202 > Cargo deb just reports which packaged files it didn't derive dependencies for. But
203 > so far the dependency deriving seams very good, even if some of the grammar files are skipped.
204
205 You can find the resulted `.deb` in `target/debian/`. It should contain everything it needs, including the
206
207 - completions for bash, fish, zsh
208 - .desktop file
209 - icon (though desktop environments might use their own since the name of the package is correctly `helix`)
210 - launcher to the binary with the runtime