Skip to content

Commit

Permalink
Merge pull request #7 from luleyleo/rework-build-system
Browse files Browse the repository at this point in the history
Rework build system
  • Loading branch information
luleyleo authored Sep 30, 2024
2 parents bc065b5 + 634fbc9 commit 3c04314
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ debian/*
flatpak/
.flatpak-builder/
assets/locale/
build-aux/Makefile
12 changes: 12 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ You can check for warnings with
just check
```

You can install the `.Devel` flatpak with

```sh
just install-flatpak
```

You can install the regular flatpak with

```sh
just release=true install-flatpak
```

And you can update the translation messages with

```sh
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Clapgrep

One app to search through all your files, powered by ripgrep.
One app to search through all your files

<a href="https://flathub.org/apps/de.leopoldluley.Clapgrep">
<img src="https://flathub.org/assets/badges/flathub-badge-en.png" width="240"/>
</a>

## Description

Expand Down
11 changes: 11 additions & 0 deletions assets/de.leopoldluley.Clapgrep.Devel.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Desktop Entry]
Name=Clapgrep Devel
Comment=One app to search through all your files, powered by ripgrep
Exec=clapgrep %u
Terminal=false
Type=Application
StartupNotify=true
Icon=de.leopoldluley.Clapgrep.Devel
Categories=Utility;FileTools;
Keywords=grep;ripgrep;search;pdf;
MimeType=inode/directory;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions build-aux/de.leopoldluley.Clapgrep.Devel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"$schema": "https://raw.githubusercontent.com/flatpak/flatpak-builder/1.4.4/data/flatpak-manifest.schema.json",
"id": "de.leopoldluley.Clapgrep.Devel",
"runtime": "org.gnome.Platform",
"runtime-version": "46",
"sdk": "org.gnome.Sdk",
"sdk-extensions": [
"org.freedesktop.Sdk.Extension.rust-stable"
],
"command": "clapgrep",
"finish-args": [
"--share=ipc",
"--socket=fallback-x11",
"--socket=wayland",
"--device=dri",
"--filesystem=host:ro"
],
"cleanup": [
"/include",
"/lib/pkgconfig",
"/man",
"/share/doc",
"/share/gtk-doc",
"/share/man",
"/share/pkgconfig",
"*.la",
"*.a"
],
"build-options": {
"append-path": "/usr/lib/sdk/rust-stable/bin"
},
"modules": [
{
"name": "blueprint-compiler",
"buildsystem": "meson",
"cleanup": [
"*"
],
"sources": [
{
"type": "git",
"url": "https://gitlab.gnome.org/jwestman/blueprint-compiler",
"tag": "v0.14.0"
}
]
},
{
"name": "clapgrep",
"buildsystem": "simple",
"build-options": {
"env": {
"CARGO_HOME": "/run/build/clapgrep/cargo",
"APP_ID": "de.leopoldluley.Clapgrep.Devel"
}
},
"build-commands": [
"make --file=build-aux/Makefile"
],
"sources": [
{
"type": "dir",
"path": ".."
},
"./cargo-sources.json"
]
}
]
}
3 changes: 2 additions & 1 deletion build-aux/de.leopoldluley.Clapgrep.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"buildsystem": "simple",
"build-options": {
"env": {
"CARGO_HOME": "/run/build/clapgrep/cargo"
"CARGO_HOME": "/run/build/clapgrep/cargo",
"APP_ID": "de.leopoldluley.Clapgrep"
}
},
"build-commands": [
Expand Down
5 changes: 4 additions & 1 deletion build-aux/fun.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env sh

flatpak-builder --run $(dirname $0)/../flatpak $(dirname $0)/de.leopoldluley.Clapgrep.json env CARGO_HOME=/run/build/clapgrep/cargo "$@"
flatpak-builder --run \
$(dirname $0)/../flatpak \
$(dirname $0)/de.leopoldluley.Clapgrep.json \
env CARGO_HOME=/run/build/clapgrep/cargo APP_ID=$APP_ID "$@"
2 changes: 1 addition & 1 deletion gnome/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod search_model;
mod search_result;
mod search_window;

const APP_ID: &str = "de.leopoldluley.Clapgrep";
const APP_ID: &str = env!("APP_ID");

fn setup_gettext() {
let mut text_domain = gettextrs::TextDomain::new(APP_ID);
Expand Down
47 changes: 27 additions & 20 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
name := 'clapgrep'
appid := 'de.leopoldluley.Clapgrep'
frontend := 'clapgrep-gnome'
release := 'false'

appid := if release == 'true' { 'de.leopoldluley.Clapgrep' } else { 'de.leopoldluley.Clapgrep.Devel' }
bin-target := if release == 'true' { 'release' } else { 'debug' }
release-flag := if release == 'true' { '--release' } else { '' }

export APP_ID := appid

rootdir := ''
prefix := '/usr'

base-dir := absolute_path(clean(rootdir / prefix))

bin-src := 'target' / 'release' / frontend
bin-dst := base-dir / 'bin' / name
bin-src := 'target' / bin-target / 'clapgrep-gnome'
bin-dst := base-dir / 'bin' / 'clapgrep'

desktop := appid + '.desktop'
desktop-src := 'assets' / desktop
desktop-dst := base-dir / 'share' / 'applications' / desktop

metainfo := appid + '.metainfo.xml'
metainfo := 'de.leopoldluley.Clapgrep.metainfo.xml'
metainfo-src := 'assets' / metainfo
metainfo-dst := base-dir / 'share' / 'metainfo' / metainfo

Expand All @@ -27,19 +31,23 @@ icon-svg-dst := icons-dst / 'scalable' / 'apps' / appid + '.svg'
po-src := 'assets' / 'locale'
po-dst := base-dir / 'share' / 'locale'

default:
just --list

clean:
cargo clean

build *args: build-translations
cargo build --package {{frontend}} {{args}}
cargo build --package clapgrep-gnome {{args}} {{release-flag}}

check *args:
check *args: build
cargo clippy --all-features {{args}}

run *args: build-translations
env RUST_BACKTRACE=full cargo run --package {{frontend}} {{args}}
run *args: build
env RUST_BACKTRACE=full cargo run --package clapgrep-gnome {{args}}

ci: setup-flatpak-repos
echo "skip:" > build-aux/Makefile
flatpak-builder --keep-build-dirs --disable-updates --build-only --ccache --force-clean flatpak build-aux/{{appid}}.json
echo Check formatting:
./build-aux/fun.sh cargo fmt --all -- --check --verbose
Expand All @@ -48,26 +56,25 @@ ci: setup-flatpak-repos
echo Check code with Clippy:
./build-aux/fun.sh cargo clippy --workspace --all-targets --all-features -- -D warnings

install:
install: build
mkdir -p {{po-dst}}
install -Dm0755 {{bin-src}} {{bin-dst}}
install -Dm0755 {{desktop-src}} {{desktop-dst}}
install -Dm0755 {{metainfo-src}} {{metainfo-dst}}
install -Dm0755 {{icon-svg-src}} {{icon-svg-dst}}
cp -r {{po-src}} {{po-dst}}

make-makefile:
echo "# This file was generated by 'just make-makefile'" > build-aux/Makefile
echo ".PHONY: all" >> build-aux/Makefile
echo "all:" >> build-aux/Makefile
just -n build --release 2>&1 | sed 's/^/\t/' | sed 's/\$/$$/g' >> build-aux/Makefile
just -n --set prefix /app install 2>&1 | sed 's/^/\t/' >> build-aux/Makefile
make-makefile target='build-aux/Makefile':
echo "# This file was generated by 'just make-makefile'" > {{target}}
echo ".PHONY: install" >> {{target}}
echo "install:" >> {{target}}
just -n release={{release}} prefix=/app install 2>&1 | sed 's/^/\t/' | sed 's/\$/$$/g' >> {{target}}

prepare-flatpak: make-makefile
make-cargo-sources:
python3 build-aux/flatpak-cargo-generator.py ./Cargo.lock -o build-aux/cargo-sources.json

install-flatpak: setup-flatpak-repos
flatpak-builder flatpak-build gnome/de.leopoldluley.Clapgrep.json --force-clean --install --user
install-flatpak: setup-flatpak-repos make-makefile make-cargo-sources
flatpak-builder flatpak-build build-aux/{{appid}}.json --force-clean --install --user

setup-flatpak-repos:
flatpak remote-add --user --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo
Expand Down
6 changes: 3 additions & 3 deletions build-aux/Makefile → makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# This file was generated by 'just make-makefile'
.PHONY: all
all:
.PHONY: install
install:
cat po/LINGUAS | while read lang; do mkdir -p assets/locale/$$lang/LC_MESSAGES; msgfmt -o assets/locale/$$lang/LC_MESSAGES/de.leopoldluley.Clapgrep.mo po/$$lang.po; done
cargo build --package clapgrep-gnome --release
cargo build --package clapgrep-gnome --release
mkdir -p /app/share/locale
install -Dm0755 target/release/clapgrep-gnome /app/bin/clapgrep
install -Dm0755 assets/de.leopoldluley.Clapgrep.desktop /app/share/applications/de.leopoldluley.Clapgrep.desktop
Expand Down

0 comments on commit 3c04314

Please sign in to comment.