diff --git a/.gitignore b/.gitignore index 898e24dd..afe0450c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,10 +6,11 @@ builddir/ # Cargo target/ -# Flatpak +# Supported build systems .flatpak-builder .flatpak .fenv +.foundry # Temporary files *.ui.in~ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 975542cf..9d397115 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -51,15 +51,50 @@ If you are building the flatpak manually you will also need flatpak-builder on y ### GNOME Builder -Using [GNOME Builder](https://apps.gnome.org/Builder/) with [flatpak](https://flatpak.org/) is +Using [GNOME Builder](https://apps.gnome.org/Builder/) with [Flatpak](https://flatpak.org/) is the recommended way of building and installing Fractal. You can find help on cloning and building a project in the [docs of Builder](https://builder.readthedocs.io/). -### Flatpak via fenv +To open a build terminal to run commands like [Clippy](#pre-commit), you can use the “+” button at +the left of the header bar of the editor and select “New build terminal”, or use its keyboard +shortcut Shift+Ctrl+Alt+T. The terminal should open in +the `_build` directory. -As an alternative, [fenv](https://gitlab.gnome.org/ZanderBrown/fenv) allows to setup a flatpak -environment from the command line and execute commands in that environment. +### Foundry + +As an alternative, [Foundry](https://gitlab.gnome.org/GNOME/foundry) is a command line tool with +a lot of features similar to an IDE, which we can also use to develop in a Flatpak environment. It +should be available as the `foundry` package in your distribution. + +First, set up the project: + +```sh +foundry init +``` + +Then, you can build and run the application directly: + +```sh +foundry run +``` + +_Note that Foundry will use `.foundry/cache/build` as build directory._ + +To test changes you make to the code, re-run that last command. + +To run commands like [Clippy](#pre-commit) in the build environment, use: + +```sh +foundry devenv -- {COMMAND} +``` + +The command will run in the `.foundry/cache/build` directory by default. + +### fenv + +Another command line alternative is [fenv](https://gitlab.gnome.org/ZanderBrown/fenv), which focuses +only on developing with Flatpak. First, install fenv: @@ -67,7 +102,7 @@ First, install fenv: cargo install --git https://gitlab.gnome.org/ZanderBrown/fenv fenv ``` -After that, setup the project: +After that, set up the project: ```sh # Set up the flatpak environment @@ -88,6 +123,14 @@ _Note that fenv will use `_build` as build directory._ To test changes you make to the code, re-run these two last commands. +To run commands like [Clippy](#pre-commit) in the build environment, use: + +```sh +fenv exec -- {COMMAND} +``` + +The command will run in the current directory by default. + ### Install the flatpak Some features that interact with the system require the app to be installed to test them (i.e. @@ -134,8 +177,17 @@ quick script that makes sure that the code is correctly formatted with `rustfmt` things. Make sure that this script is effectively run before submitting your merge request, otherwise CI will probably fail right away. -You should also run `cargo clippy` as that will catch common errors and improve the quality of your -submissions and is once again checked by our CI. +You should also run [Clippy](https://doc.rust-lang.org/stable/clippy/index.html) as that will catch +common errors and improve the quality of your submissions and is once again checked by our CI. To +reuse the same cache as when building Fractal, you should run the following command in a build +environment: + +```sh +meson compile -C {BUILD_DIRECTORY} src/cargo-clippy +``` + +_ The `-C {BUILD_DIRECTORY}` option can be omitted when the command is run from the build +directory._ ## Commit diff --git a/meson.build b/meson.build index 84c25075..9798bfcb 100644 --- a/meson.build +++ b/meson.build @@ -144,10 +144,14 @@ if profile == 'Devel' message('Pre-commit hook installed') else if cp_bin_result.returncode() != 0 - message('Could not install pre-commit binary: ' + cp_bin_result.stderr()) + message( + 'Could not install pre-commit binary: ' + cp_bin_result.stderr(), + ) endif if cp_hook_result.returncode() != 0 - message('Could not install pre-commit hook: ' + cp_hook_result.stderr()) + message( + 'Could not install pre-commit hook: ' + cp_hook_result.stderr(), + ) endif endif endif diff --git a/src/meson.build b/src/meson.build index 855a0cf8..c48c1f1a 100644 --- a/src/meson.build +++ b/src/meson.build @@ -87,12 +87,13 @@ run_command( # Cargo settings cargo_options = ['--manifest-path', meson.project_source_root() / 'Cargo.toml'] +cargo_build_options = cargo_options if profile == 'Devel' rust_target = 'debug' message('Building in debug mode') else - cargo_options += ['--release'] + cargo_build_options += ['--release'] rust_target = 'release' message('Building in release mode') endif @@ -112,7 +113,7 @@ if not build_env_only command: [ cargo, 'build', - cargo_options, + cargo_build_options, '&&', 'cp', cargo_target_dir / rust_target / meson.project_name(), @@ -120,6 +121,17 @@ if not build_env_only ], ) + # Lint Rust code with clippy + run_target( + 'cargo-clippy', + env: cargo_env, + command: [ + cargo, + 'clippy', + cargo_options, + ], + ) + # Run Rust tests with cargo-nextest custom_target( 'cargo-test', @@ -127,8 +139,9 @@ if not build_env_only output: 'junit.xml', console: true, depends: [resources, ui_resources], - env: cargo_env, command: [ + 'env', + cargo_env, 'cargo-nextest', 'nextest', 'run',