chore(just): add library and Rust version checks

This commit is contained in:
Michael Aaron Murphy 2024-03-06 20:03:34 +01:00 committed by Michael Murphy
parent b65cb1a038
commit f0603d648f
4 changed files with 63 additions and 18 deletions

View file

@ -2,6 +2,7 @@
members = ["app", "page", "pages/*"]
default-members = ["app"]
resolver = "2"
rust-version = "1.71.0"
[workspace.dependencies.libcosmic]
git = "https://github.com/pop-os/libcosmic"

View file

@ -1,12 +1,15 @@
import 'scripts/cargo.just'
import 'scripts/cosmic.just'
# Project metadata
name := 'cosmic-settings'
appid := 'com.system76.CosmicSettings'
# File paths
rootdir := ''
prefix := '/usr'
default-schema-target := clean(rootdir / prefix) / 'share' / 'cosmic'
# File paths
bin-src := cargo-target-dir / 'release' / name
bin-dest := clean(rootdir / prefix) / 'bin' / name
@ -20,6 +23,7 @@ metainfo := appid + '.metainfo.xml'
metainfo-src := 'resources' / metainfo
metainfo-dst := clean(rootdir / prefix) / 'share' / 'metainfo' / metainfo
# Build recipes
[private]
default: build-release
@ -34,11 +38,18 @@ uninstall:
find 'resources'/'default_schema' -type f -exec echo {} \; | rev | cut -d'/' -f-3 | rev | xargs -d '\n' -I {} rm -rf {{default-schema-target}}/{}
find 'resources'/'icons' -type f -exec echo {} \; | rev | cut -d'/' -f-3 | rev | xargs -d '\n' -I {} rm {{iconsdir}}/{}
# Vendor Cargo dependencies locally
vendor:
mkdir -p .cargo
cargo vendor --sync Cargo.toml \
| head -n -1 > .cargo/config
echo 'directory = "vendor"' >> .cargo/config
tar pcf vendor.tar vendor
rm -rf vendor
# Dependencies
cmd-depends := "
cargo
cmake
"
lib-depends := "
expat
fontconfig
freetype2
libinput
libudev
wayland-client
xkbcommon
"

View file

@ -1,3 +1,13 @@
import "common.just"
# Return an error if the system does not contain the minimum required Rust version.
min-rust-version := '>=' + `grep rust-version Cargo.toml | cut -d' ' -f3 | cut -c 2-7`
rust-version-check := if semver_matches(`rustc --version | cut -c 7-12`, min-rust-version) == "false" {
error('Requires rustc version ' + min-rust-version)
} else {
"passed"
}
cargo-target-dir := env('CARGO_TARGET_DIR', 'target')
# Use mold linker if clang and mold exists.
@ -17,6 +27,7 @@ linker-arg := if clang-path != '' {
export RUSTFLAGS := linker-arg + env_var_or_default('RUSTFLAGS', '')
# Compile with debug profile
[no-cd]
build-debug *args:
cargo build {{args}}
@ -34,10 +45,12 @@ check *args:
check-json: (check '--message-format=json')
# Remove Cargo build artifacts
[no-cd]
clean:
cargo clean
# Also remove .cargo and vendored dependencies
[no-cd]
clean-dist: clean
rm -rf .cargo vendor vendor.tar target
@ -49,8 +62,17 @@ run *args:
test *args:
cargo test {{args}}
# Vendor Cargo dependencies locally
[no-cd]
vendor:
mkdir -p .cargo
cargo vendor | head -n -1 > .cargo/config
echo 'directory = "vendor"' >> .cargo/config
tar pcf vendor.tar vendor
rm -rf vendor
# Extracts vendored dependencies
[private]
[no-cd, private]
vendor-extract:
rm -rf vendor
tar pxf vendor.tar

View file

@ -1,17 +1,28 @@
rootdir := ''
prefix := '/usr'
# Installation command
[private]
[no-cd, private]
install-cmd options src dest:
install {{options}} {{src}} {{dest}}
[private]
[no-cd, private]
install-bin src dest: (install-cmd '-Dm0755' src dest)
[private]
[no-cd, private]
install-file src dest: (install-cmd '-Dm0644' src dest)
# Check if required dependencies are installed on the system
dep-check:
#!/bin/sh
echo "{{lib-depends}}" | while read -r lib; do
if [ -n "${lib}" ]; then
just dep-lib "${lib}" || exit 1
fi
done
echo "{{cmd-depends}}" | while read -r cmd; do
if [ -n "${cmd}" ]; then
just dep-cmd "${cmd}" || exit 1
fi
done
# Errors if a command does not exist
[private]
dep-cmd cmd:
@ -20,7 +31,7 @@ dep-cmd cmd:
# Errors if a library does not exist
[private]
dep-lib lib:
@pkg-config --libs {{lib}} >/dev/null 2>&1 || (just print-error 'missing dependency' 'library' {{lib}}; exit 1)
@pkg-config --exists {{lib}} || (just print-error 'missing dependency' 'library' {{lib}}; exit 1)
# Display a formatted error for the user.
[private]