diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fc477e2880e4bd5b23a92544df27f0ad3fbf9431..da17c7eacec6dbc7c4409f5ed2361582a319521f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,10 +10,11 @@ clippy: tags: - docker-amd64 before_script: + - curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin/ - apt-get update && apt-get install -y --no-install-recommends libudev-dev - rustup component add clippy script: - - make checks + - just check test: image: "rust:latest" @@ -21,10 +22,11 @@ test: tags: - docker-amd64 before_script: + - curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin/ - apt-get update && apt-get install -y --no-install-recommends libudev-dev script: - rustc --version && cargo --version # Print version info for debugging - - cargo test --workspace --verbose + - just test windows: image: "rust:latest" @@ -34,11 +36,11 @@ windows: RUST_BUILDER: cargo stage: build before_script: - - echo "Download dependencies" + - curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin/ - apt-get update && apt-get --assume-yes install gcc-mingw-w64 zip - rustup target add x86_64-pc-windows-gnu script: - - make release-windows-x86_64-pc-windows-gnu + - just release x86_64-pc-windows-gnu artifacts: paths: - release/ @@ -51,15 +53,13 @@ linux_x86_64: RUST_BUILDER: cargo stage: build before_script: - - echo "Download dependencies" + - curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin/ - apt-get update && apt-get --assume-yes install libssl-dev libudev-dev desktop-file-utils - - echo "Setup appimagetool" - - wget https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-$(uname -m).AppImage -O /usr/local/bin/appimagetool - - chmod +x /usr/local/bin/appimagetool - rustup target add x86_64-unknown-linux-gnu - cargo install cargo-deb + - just setup-appimage /usr/local/bin script: - - make release-linux-x86_64-unknown-linux-gnu + - just release x86_64-unknown-linux-gnu artifacts: paths: - release/ @@ -76,16 +76,14 @@ linux_aarch64: PB2_MSPM0: 1 stage: build before_script: - - echo "Download dependencies" + - curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin/ - dpkg --add-architecture ${CROSS_ARCH} - apt-get update && apt-get --assume-yes install libssl-dev:${CROSS_ARCH} libudev-dev:${CROSS_ARCH} desktop-file-utils gcc-aarch64-linux-gnu - - echo "Setup appimagetool" - - wget https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-$(uname -m).AppImage -O /usr/local/bin/appimagetool - - chmod +x /usr/local/bin/appimagetool - rustup target add aarch64-unknown-linux-gnu - cargo install cargo-deb + - just setup-appimage /usr/local/bin script: - - PKG_CONFIG_PATH="/usr/lib/aarch64-linux-gnu/pkgconfig/:${PKG_CONFIG_PATH}" make release-linux-aarch64-unknown-linux-gnu + - PKG_CONFIG_PATH="/usr/lib/aarch64-linux-gnu/pkgconfig/:${PKG_CONFIG_PATH}" just release aarch64-unknown-linux-gnu artifacts: paths: - release/ @@ -101,16 +99,14 @@ linux_arm: CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER: arm-linux-gnueabihf-gcc stage: build before_script: - - echo "Download dependencies" + - curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin/ - dpkg --add-architecture ${CROSS_ARCH} - apt-get update && apt-get --assume-yes install libssl-dev:${CROSS_ARCH} libudev-dev:${CROSS_ARCH} desktop-file-utils gcc-arm-linux-gnueabihf - - echo "Setup appimagetool" - - wget https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-$(uname -m).AppImage -O /usr/local/bin/appimagetool - - chmod +x /usr/local/bin/appimagetool - rustup target add armv7-unknown-linux-gnueabihf - cargo install cargo-deb + - just setup-appimage /usr/local/bin script: - - PKG_CONFIG_PATH="/usr/lib/arm-linux-gnueabihf/pkgconfig/:${PKG_CONFIG_PATH}" make release-linux-armv7-unknown-linux-gnueabihf + - PKG_CONFIG_PATH="/usr/lib/arm-linux-gnueabihf/pkgconfig/:${PKG_CONFIG_PATH}" just release armv7-unknown-linux-gnueabihf artifacts: paths: - release/ @@ -123,7 +119,7 @@ darwin: variables: RUST_BUILDER: cargo before_script: - - brew install create-dmg rustup git-lfs + - brew install create-dmg rustup git-lfs just - git lfs install - git lfs fetch - git lfs checkout @@ -131,9 +127,9 @@ darwin: - rustup target add x86_64-apple-darwin aarch64-apple-darwin script: - rustc --version - - make release-darwin-x86_64-apple-darwin - - make release-darwin-aarch64-apple-darwin - - make release-darwin-universal-apple-darwin + - just release x86_64-apple-darwin + - just release aarch64-apple-darwin + - just release universal-apple-darwin artifacts: paths: - release/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 415add8179ec2b04d5f75c77b1d78b0aea59b36b..b128ffb86143bfefe03a897b02297a48c39a9bf7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,6 +6,7 @@ The following dependencies are required to work with the codebase. 1. [git-lfs](https://git-lfs.com/): Since this is a Git LFS repository, a lot of weird errors regarding missing assets will come up cloning the repository without installing `git-lfs`. 2. [rust](https://www.rust-lang.org/): I personally use [rustup](https://rustup.rs/) to manage Rust versions, but development can be done without Rustup as well since everything builds with stable Rust. +3. [just](https://github.com/casey/just?tab=readme-ov-file#installation): A task runner to make life easier ### Platform Dependencies @@ -28,13 +29,13 @@ dnf install openssl-devel systemd-devel -y - GUI ``` -cargo run -p bb-imager-gui +just run-gui ``` - CLI ``` -cargo run -p bb-imager-cli +just run-cli ``` # Submitting PRs diff --git a/Makefile b/Makefile deleted file mode 100644 index 7ef6c64d5bc0f793bf1b95ef80873486f6cd7f36..0000000000000000000000000000000000000000 --- a/Makefile +++ /dev/null @@ -1,43 +0,0 @@ -CARGO_PATH = $(shell which cargo) -RUST_BUILDER ?= $(CARGO_PATH) -APPIMAGETOOL ?= $(shell which appimagetool) -RUST_BUILDER_NAME = $(lastword $(subst /, , $(RUST_BUILDER))) -CROSS_UTIL ?= $(shell which cross-util) - -# Features related stuff -RUST_FEATURE_ARGS = -PB2_MSPM0 ?= - -VERSION ?= $(shell grep 'version =' Cargo.toml | sed 's/version = "\(.*\)"/\1/') - -RELEASE_DIR ?= $(CURDIR)/release -RELEASE_DIR_LINUX ?= ${RELEASE_DIR}/linux -RELEASE_DIR_WINDOWS ?= ${RELEASE_DIR}/windows -RELEASE_DIR_DARWIN ?= ${RELEASE_DIR}/darwin - -GUI_ASSETS = $(CURDIR)/bb-imager-gui/assets -GUI_ASSETS_LINUX = ${GUI_ASSETS}/packages/linux -GUI_ASSETS_DARWIN = ${GUI_ASSETS}/packages/darwin - -SERVICE_ASSETS = $(CURDIR)/bb-imager-service/assets - -# Includes -include bb-imager-gui/Makefile -include bb-imager-cli/Makefile -include bb-imager-service/Makefile - -clean: - $(CARGO_PATH) clean - rm -rf release - -release-linux-%: package-cli-linux-xz-% package-cli-linux-deb-% package-gui-linux-appimage-% package-gui-linux-deb-% $(if $(PB2_MSPM0), package-service-linux-deb-% package-service-linux-xz-%); - -release-darwin-%: package-cli-darwin-zip-% package-gui-darwin-dmg-%; - -release-windows-%: package-cli-windows-zip-% package-gui-windows-zip-%; - -checks-clippy-%: - $(info "Running clippy checks for $*") - $(CARGO_PATH) clippy -p $* --all-targets --all-features --no-deps - -checks: checks-clippy-bb-imager checks-clippy-bb-imager-cli checks-clippy-bb-imager-gui checks-clippy-bb-imager-service diff --git a/PACKAGING.md b/PACKAGING.md index 0a927159b8593c06614e25c54c1abcfcce4d0ce5..8e4036a5bcd70c8e3b9649338249bc02e0f9d02d 100644 --- a/PACKAGING.md +++ b/PACKAGING.md @@ -1,58 +1,39 @@ # Packaging -## Dependencies +## Task system -The following dependencies are only required to build a package locally. It can be skipped during general development. +- This project uses [just](https://just.systems/) as the task runner. For most people, running `just` should be enough get a grasp regarding how to build and run the project. -### Deb Packaging - -The project uses [cargo-deb](https://crates.io/crates/cargo-deb) to build the Debian package. - -``` -cargo install cargo-deb -``` - -### AppImage Packaging - -- The project uses [appimagetool](https://github.com/AppImage/appimagetool) for building the AppImage. +## Building -``` -wget https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-$(uname -m).AppImage -O $HOME/.local/bin/appimagetool -chmod +x $HOME/.local/bin/appimagetool -``` +The repo contains a `Makefile` to help create the different supported packages. -### DMG Packaging +## Deb Package -- The project uses [create-dmg](https://github.com/create-dmg/create-dmg) to build DMG package for MacOS +1. The project uses [cargo-deb](https://crates.io/crates/cargo-deb) to build the Debian package. It can be installed with a just recipe ``` -brew install create-dmg +just setup-deb ``` -## Building - -The repo contains a `Makefile` to help create the different supported packages. - -## Deb Package - -Ensure [dependencies](#deb-packaging) are installed. +2. Build the packages - CLI ``` -make package-cli-linux-deb-{target} +just package-cli-linux-deb {target} ``` - GUI ``` -make package-gui-linux-deb-{target} +just package-gui-linux-deb {target} ``` - Service ``` -make package-service-linux-deb-{target} +just package-service-linux-deb {target} ``` Where `target` is the platform you are building for. Currently, the following targets have been tested: @@ -64,10 +45,16 @@ For different host/target pair, see [Cross Compilation](#cross-compilation) ## AppImage -Ensure [dependencies](#appimage-dependencies) are installed. AppImage is only supported for the GUI. +1. The project uses [appimagetool](https://github.com/AppImage/appimagetool) for building the AppImage. + +``` +just setup-appimage +``` + +2. Build the package ``` -make package-gui-linux-appimage-{target} +just package-gui-linux-appimage {target} ``` Where `target` is the platform you are building for. Currently, the following targets have been tested: @@ -84,13 +71,13 @@ Just a tarball of everything. Useful for creating packages that need to be maint - CLI ``` -make package-cli-linux-xz-{target} +just package-cli-linux-xz {target} ``` - Service ``` -make package-service-linux-xz-{target} +just package-service-linux-xz {target} ``` Where `target` is the platform you are building for. Currently, the following targets have been tested: @@ -105,13 +92,13 @@ For different host/target pair, see [Cross Compilation](#cross-compilation) - CLI ``` -make package-cli-windows-zip-{target} +just package-cli-windows-zip {target} ``` - GUI ``` -make package-gui-windows-zip-{target} +just package-gui-windows-zip {target} ``` Where `target` is the platform you are building for. Currently, the following targets have been tested: @@ -121,10 +108,16 @@ For different host/target pair, see [Cross Compilation](#cross-compilation) ## MacOS DMG -Ensure [dependencies](#dmg-dependencies) are installed. DMG is only supported for the GUI. +1. The project uses [create-dmg](https://github.com/create-dmg/create-dmg) to build DMG package for MacOS + +``` +just setup-dmg +``` + +2. Build the package. ``` -make package-gui-darwin-dmg-{target} +just package-gui-darwin-dmg {target} ``` Where `target` is the platform you are building for. Currently, the following targets have been tested: @@ -139,7 +132,7 @@ MacOS Package cannot be built on a non-MacOS host. Zipped package for CLI. Useful for creating out of tree packages. Only supported for CLI. ``` -make package-cli-darwin-zip-{target} +just package-cli-darwin-zip {target} ``` Where `target` is the platform you are building for. Currently, the following targets have been tested: @@ -155,5 +148,5 @@ Cross Compilation for linux is supported using [cross](https://github.com/cross- ``` cargo install cross --git https://github.com/cross-rs/cross -RUST_BUILDER=$(which cross) make {target} +RUST_BUILDER=$(which cross) just {recipe} {target} ``` diff --git a/bb-imager-cli/Makefile b/bb-imager-cli/Makefile deleted file mode 100644 index 3127aeebc99eac51894346a3d02fe96f47d1e22d..0000000000000000000000000000000000000000 --- a/bb-imager-cli/Makefile +++ /dev/null @@ -1,67 +0,0 @@ -RUST_CLI_FEATURE_ARGS = $(RUST_FEATURE_ARGS) - -PACKAGE_NAME_CLI = bb-imager-cli -RELEASE_DIR_CLI = ${RELEASE_DIR}/${PACKAGE_NAME_CLI}/${VERSION} - -# Enable CLI specific features -ifdef PB2_MSPM0 - RUST_CLI_FEATURE_ARGS += -F pb2_mspm0 -endif - -build-cli-%: - $(info "Building CLI for $*") - $(RUST_BUILDER) build --release --target $* -p bb-imager-cli $(RUST_CLI_FEATURE_ARGS) - -# Special rule for macos universal binary -build-cli-universal-apple-darwin: build-cli-aarch64-apple-darwin build-cli-x86_64-apple-darwin - $(info "Building CLI for universal-apple-darwin") - mkdir -p target/universal-apple-darwin/release - lipo -create target/x86_64-apple-darwin/release/bb-imager-cli target/aarch64-apple-darwin/release/bb-imager-cli -output target/universal-apple-darwin/release/bb-imager-cli - -package-cli-linux-xz-%: build-cli-% manpage shell-completion-bash shell-completion-zsh - $(info "Create CLI xz $*") - install -D target/$*/release/bb-imager-cli -t ${RELEASE_DIR_CLI}/bb-imager-cli-tempdir/usr/bin/ - install -D -m 644 target/man/* -t ${RELEASE_DIR_CLI}/bb-imager-cli-tempdir/usr/share/man/man1/ - install -D -m 644 target/shell-completion/_bb-imager-cli -t ${RELEASE_DIR_CLI}/bb-imager-cli-tempdir/usr/share/zsh/site-functions/ - install -D -m 644 target/shell-completion/bb-imager-cli.bash -t ${RELEASE_DIR_CLI}/bb-imager-cli-tempdir/usr/share/bash-completion/completions/bb-imager-cli - cd ${RELEASE_DIR_CLI}/bb-imager-cli-tempdir && tar cfJ ${RELEASE_DIR_CLI}/${PACKAGE_NAME_CLI}-$*.tar.xz * - rm -rf ${RELEASE_DIR_CLI}/bb-imager-cli-tempdir - -package-cli-linux-deb-%: build-cli-% manpage shell-completion-bash shell-completion-zsh - $(info "Create CLI Linux deb $*") -ifeq ($(RUST_BUILDER_NAME), cross) - $(CROSS_UTIL) run --target $* -- "cargo deb --target $* -p bb-imager-cli --no-build -o ${RELEASE_DIR_CLI}/${PACKAGE_NAME_CLI}-$*.deb --no-strip" -else - $(RUST_BUILDER) deb --target $* -p bb-imager-cli --no-build -o ${RELEASE_DIR_CLI}/${PACKAGE_NAME_CLI}-$*.deb --no-strip -endif - -package-cli-darwin-zip-%: build-cli-% manpage shell-completion-zsh - $(info "Create CLI Darwin zip $*") - mkdir -p ${RELEASE_DIR_CLI}/bb-imager-cli-tempdir - cp -r target/man ${RELEASE_DIR_CLI}/bb-imager-cli-tempdir/ - cp -r target/shell-completion ${RELEASE_DIR_CLI}/bb-imager-cli-tempdir/ - cp target/$*/release/bb-imager-cli ${RELEASE_DIR_CLI}/bb-imager-cli-tempdir/ - # Required to get the desired directory structure - cd ${RELEASE_DIR_CLI}/bb-imager-cli-tempdir && zip -r ${RELEASE_DIR_CLI}/${PACKAGE_NAME_CLI}-$*.zip * - rm -rf ${RELEASE_DIR_CLI}/bb-imager-cli-tempdir/ - -package-cli-windows-zip-%: build-cli-% shell-completion-powershell - $(info "Create CLI Windows zip $*") - mkdir -p ${RELEASE_DIR_CLI}/bb-imager-cli-tempdir - cp target/$*/release/bb-imager-cli.exe ${RELEASE_DIR_CLI}/bb-imager-cli-tempdir/ - cp -r target/shell-completion ${RELEASE_DIR_CLI}/bb-imager-cli-tempdir/ - # Required to get the desired directory structure - cd ${RELEASE_DIR_CLI}/bb-imager-cli-tempdir/ && zip -r ${RELEASE_DIR_CLI}/${PACKAGE_NAME_CLI}-$*.zip * - rm -rf ${RELEASE_DIR_CLI}/bb-imager-cli-tempdir - -manpage: - $(info "Generate CLI Manpages") - rm -rf target/man - mkdir -p target/man - $(CARGO_PATH) xtask $(RUST_CLI_FEATURE_ARGS) cli-man target/man - gzip target/man/* - -shell-completion-%: - $(info "Generate CLI Shell Completion") - mkdir -p target/shell-completion - $(CARGO_PATH) xtask $(RUST_CLI_FEATURE_ARGS) cli-shell-complete $* target/shell-completion diff --git a/bb-imager-cli/justfile b/bb-imager-cli/justfile new file mode 100644 index 0000000000000000000000000000000000000000..1a629fd9110976388d6c7aacf99a6d705c536905 --- /dev/null +++ b/bb-imager-cli/justfile @@ -0,0 +1,81 @@ +_RUST_CLI_FEATURE_ARGS := if PB2_MSPM0 == '1' { '-F pb2_mspm0' } else { '' } + +_PACKAGE_NAME_CLI := 'bb-imager-cli' + +_RELEASE_DIR_CLI := _RELEASE_DIR / _PACKAGE_NAME_CLI / VERSION + +# Build universal macos GUI binary +_build-cli-universal-apple-darwin: (build-cli 'aarch64-apple-darwin') (build-cli 'x86_64-apple-darwin') + mkdir -p target/universal-apple-darwin/release + lipo -create target/x86_64-apple-darwin/release/bb-imager-cli target/aarch64-apple-darwin/release/bb-imager-cli -output target/universal-apple-darwin/release/bb-imager-cli + + +# Release build for Beagle Board Imager CLI. Should be used for final testing +[group('build')] +build-cli TARGET=_HOST_TARGET: + @echo "Build Beagle Board Imager CLI for {{TARGET}}" + {{ if TARGET == 'universal-apple-darwin' { \ + 'just _build-cli-universal-apple-darwin' \ + } else { \ + RUST_BUILDER + ' build --release --target ' + TARGET + ' -p bb-imager-cli ' + _RUST_GUI_FEATURE_ARGS \ + } }} + + +# Run CLI for quick testing on host. Flags can be used to modify the build +[group('run')] +run-cli FLAGS='': + @echo "Run CLI on host for quick testing" + {{RUST_BUILDER}} run -p bb-imager-cli {{_RUST_CLI_FEATURE_ARGS}} {{FLAGS}} + + +# Generate Manpage for CLI +generate-cli-manpage: + @echo "Generate CLI Manpage" + rm -rf target/man + mkdir -p target/man + {{_CARGO_PATH}} xtask {{_RUST_CLI_FEATURE_ARGS}} cli-man target/man + gzip target/man/* + + +# Generate Shell completion for CLI +generate-shell-completion SHELL: + @echo "Generate {{SHELL}} completion for CLI" + mkdir -p target/shell-completion + {{_CARGO_PATH}} xtask {{_RUST_CLI_FEATURE_ARGS}} cli-shell-complete {{SHELL}} target/shell-completion + + +# Create compressed CLI package for Linux +[group('packaging')] +package-cli-linux-xz TARGET=_HOST_TARGET: (build-cli TARGET) generate-cli-manpage (generate-shell-completion 'bash') (generate-shell-completion 'zsh') + @echo "Create compressed CLI Package for Linux" + install -D target/{{TARGET}}/release/bb-imager-cli -t {{_RELEASE_DIR_CLI}}/bb-imager-cli-tempdir/usr/bin/ + install -D -m 644 target/man/* -t {{_RELEASE_DIR_CLI}}/bb-imager-cli-tempdir/usr/share/man/man1/ + install -D -m 644 target/shell-completion/_bb-imager-cli -t {{_RELEASE_DIR_CLI}}/bb-imager-cli-tempdir/usr/share/zsh/site-functions/ + install -D -m 644 target/shell-completion/bb-imager-cli.bash -t {{_RELEASE_DIR_CLI}}/bb-imager-cli-tempdir/usr/share/bash-completion/completions/bb-imager-cli + cd {{_RELEASE_DIR_CLI}}/bb-imager-cli-tempdir && tar cfJ {{_RELEASE_DIR_CLI}}/{{_PACKAGE_NAME_CLI}}-{{TARGET}}.tar.xz * + rm -rf {{_RELEASE_DIR_CLI}}/bb-imager-cli-tempdir + + +# Create compressed CLI package for macOS +[group('packaging')] +package-cli-darwin-zip TARGET=_HOST_TARGET: (build-cli TARGET) generate-cli-manpage (generate-shell-completion 'zsh') + @echo "Create compressed CLI Package for macOS" + mkdir -p {{_RELEASE_DIR_CLI}}/bb-imager-cli-tempdir + cp -r target/man {{_RELEASE_DIR_CLI}}/bb-imager-cli-tempdir/ + cp -r target/shell-completion {{_RELEASE_DIR_CLI}}/bb-imager-cli-tempdir/ + cp target/{{TARGET}}/release/bb-imager-cli {{_RELEASE_DIR_CLI}}/bb-imager-cli-tempdir/ + # Required to get the desired directory structure + cd {{_RELEASE_DIR_CLI}}/bb-imager-cli-tempdir && zip -r {{_RELEASE_DIR_CLI}}/{{_PACKAGE_NAME_CLI}}-{{TARGET}}.zip * + rm -rf {{_RELEASE_DIR_CLI}}/bb-imager-cli-tempdir/ + + +# Create compressed CLI package for Windows +[group('packaging')] +package-cli-windows-zip TARGET=_HOST_TARGET: (build-cli TARGET) (generate-shell-completion 'powershell') + @echo "Create compressed CLI Windows zip {{TARGET}}" + mkdir -p {{_RELEASE_DIR_CLI}}/bb-imager-cli-tempdir + cp target/{{TARGET}}/release/bb-imager-cli.exe {{_RELEASE_DIR_CLI}}/bb-imager-cli-tempdir/ + cp -r target/shell-completion {{_RELEASE_DIR_CLI}}/bb-imager-cli-tempdir/ + # Required to get the desired directory structure + cd {{_RELEASE_DIR_CLI}}/bb-imager-cli-tempdir/ && zip -r {{_RELEASE_DIR_CLI}}/{{_PACKAGE_NAME_CLI}}-{{TARGET}}.zip * + rm -rf {{_RELEASE_DIR_CLI}}/bb-imager-cli-tempdir diff --git a/bb-imager-gui/Makefile b/bb-imager-gui/Makefile deleted file mode 100644 index bee6ad82a70f7dcb1c737147127ee4f7aea73a61..0000000000000000000000000000000000000000 --- a/bb-imager-gui/Makefile +++ /dev/null @@ -1,68 +0,0 @@ -# Map Rust targets with Appimage Arch -APPIMAGE_ARCH_x86_64-unknown-linux-gnu = x86_64 -APPIMAGE_ARCH_aarch64-unknown-linux-gnu = aarch64 -APPIMAGE_ARCH_armv7-unknown-linux-gnueabihf = armhf - -PACKAGE_NAME_GUI = bb-imager-gui -RELEASE_DIR_GUI = ${RELEASE_DIR}/${PACKAGE_NAME_GUI}/${VERSION} - -RUST_GUI_FEATURE_ARGS = $(RUST_FEATURE_ARGS) - -ifdef PB2_MSPM0 - RUST_GUI_FEATURE_ARGS += -F pb2_mspm0 -endif - -build-gui-%: - $(info "Building GUI for $*") - $(RUST_BUILDER) build --release --target $* -p bb-imager-gui $(RUST_GUI_FEATURE_ARGS) - -# Special rule for macos universal binary -build-gui-universal-apple-darwin: build-gui-aarch64-apple-darwin build-gui-x86_64-apple-darwin - $(info "Building GUI for universal-apple-darwin") - mkdir -p target/universal-apple-darwin/release - lipo -create target/x86_64-apple-darwin/release/bb-imager-gui target/aarch64-apple-darwin/release/bb-imager-gui -output target/universal-apple-darwin/release/bb-imager-gui - -package-gui-linux-appimage-%: build-gui-% - $(info "Create GUI Linux Appimage $*") - install -D ${GUI_ASSETS_LINUX}/appimage/AppRun -t ${RELEASE_DIR_GUI}/AppDir/ - install -D target/$*/release/bb-imager-gui -t ${RELEASE_DIR_GUI}/AppDir/usr/bin/ - install -D -m 644 ${GUI_ASSETS_LINUX}/BeagleBoardImager.desktop -t ${RELEASE_DIR_GUI}/AppDir/ - sed -i "s/^X-AppImage-Version=0.0.0/X-AppImage-Version=${VERSION}/" ${RELEASE_DIR_GUI}/AppDir/BeagleBoardImager.desktop - install -D -m 644 ${GUI_ASSETS}/icons/icon.png ${RELEASE_DIR_GUI}/AppDir/bb-imager.png - ARCH=${APPIMAGE_ARCH_$*} $(APPIMAGETOOL) --appimage-extract-and-run ${RELEASE_DIR_GUI}/AppDir ${RELEASE_DIR_GUI}/${PACKAGE_NAME_GUI}-$*.AppImage - rm -rf ${RELEASE_DIR_GUI}/AppDir - -package-gui-linux-deb-%: build-gui-% - $(info "Create GUI Linux deb $*") -ifeq ($(RUST_BUILDER_NAME), cross) - $(CROSS_UTIL) run --target $* -- "cargo deb --target $* -p bb-imager-gui --no-build -o ${RELEASE_DIR_GUI}/${PACKAGE_NAME_GUI}-$*.deb --no-strip" -else - $(RUST_BUILDER) deb --target $* -p bb-imager-gui --no-build -o ${RELEASE_DIR_GUI}/${PACKAGE_NAME_GUI}-$*.deb --no-strip -endif - -package-gui-darwin-dmg-%: build-gui-% - $(info "Create GUI Darwin dmg $*") - sed -i'.bak' -e "s/0\.0\.0/${CI_COMMIT_TAG}/g" -e "s/fffffff/${CI_COMMIT_SHA:0:7}/g" ${GUI_ASSETS_DARWIN}/Info.plist - mkdir -p ${RELEASE_DIR_GUI}/AppDir/BeagleBoardImager.app/Contents/{MacOS,Resources} - cp ${GUI_ASSETS_DARWIN}/Info.plist ${RELEASE_DIR_GUI}/AppDir/BeagleBoardImager.app/Contents/ - cp ${GUI_ASSETS}/icons/icon.icns ${RELEASE_DIR_GUI}/AppDir/BeagleBoardImager.app/Contents/Resources/ - cp target/$*/release/bb-imager-gui ${RELEASE_DIR_GUI}/AppDir/BeagleBoardImager.app/Contents/MacOS/ - create-dmg \ - --volname "BeagleBoardImager Installer" \ - --volicon "${GUI_ASSETS}/icons/icon.icns" \ - --window-pos 200 120 \ - --window-size 800 400 \ - --icon-size 100 \ - --icon "BeagleBoardImager.app" 200 190 \ - --hide-extension "BeagleBoardImager.app" \ - --app-drop-link 600 185 \ - --hdiutil-verbose \ - --skip-jenkins \ - "${RELEASE_DIR_GUI}/${PACKAGE_NAME_GUI}-$*.dmg" \ - "${RELEASE_DIR_GUI}/AppDir/" - rm -rf ${RELEASE_DIR_GUI}/AppDir/ - -package-gui-windows-zip-%: build-gui-% - $(info "Create GUI Windows zip $*") - mkdir -p ${RELEASE_DIR_GUI} - zip -j ${RELEASE_DIR_GUI}/${PACKAGE_NAME_GUI}-$*.zip target/$*/release/bb-imager-gui.exe diff --git a/bb-imager-gui/justfile b/bb-imager-gui/justfile new file mode 100644 index 0000000000000000000000000000000000000000..3d7fd844e5c5ce3a428ca4bbc674bd87f26858cd --- /dev/null +++ b/bb-imager-gui/justfile @@ -0,0 +1,84 @@ +_RUST_GUI_FEATURE_ARGS := if PB2_MSPM0 == '1' { '-F pb2_mspm0' } else { '' } + +_PACKAGE_NAME_GUI := 'bb-imager-gui' + +_GUI_ASSETS := source_directory() / 'assets' +_GUI_ASSETS_LINUX := _GUI_ASSETS / 'packages' / 'linux' +_GUI_ASSETS_DARWIN := _GUI_ASSETS / 'packages' / 'darwin' + +_RELEASE_DIR_GUI := _RELEASE_DIR / _PACKAGE_NAME_GUI / VERSION + + +# Build universal macos GUI binary +_build-gui-universal-apple-darwin: (build-gui 'aarch64-apple-darwin') (build-gui 'x86_64-apple-darwin') + mkdir -p target/universal-apple-darwin/release + lipo -create target/x86_64-apple-darwin/release/bb-imager-gui target/aarch64-apple-darwin/release/bb-imager-gui -output target/universal-apple-darwin/release/bb-imager-gui + +# Release build for Beagle Board Imager GUI. Should be used for final testing +[group('build')] +build-gui TARGET=_HOST_TARGET: + @echo "Build Beagle Board Imager GUI for {{TARGET}}" + {{ if TARGET == 'universal-apple-darwin' { \ + 'just _build-gui-universal-apple-darwin' \ + } else { \ + RUST_BUILDER + ' build --release --target ' + TARGET + ' -p bb-imager-gui ' + _RUST_GUI_FEATURE_ARGS \ + } }} + + +# Run GUI for quick testing on host. Flags can be used to modify the build +[group('run')] +run-gui FLAGS='': + @echo "Run GUI on host for quick testing" + {{RUST_BUILDER}} run -p bb-imager-gui {{_RUST_GUI_FEATURE_ARGS}} {{FLAGS}} + + +# Create Appimage package for GUI +[group('packaging')] +package-gui-linux-appimage TARGET=_HOST_TARGET: (_appimage_prechecks TARGET) (build-gui TARGET) + @echo "Create GUI Linux Appimage for {{TARGET}}" + install -D {{_GUI_ASSETS_LINUX}}/appimage/AppRun -t {{_RELEASE_DIR_GUI}}/AppDir/ + install -D target/{{TARGET}}/release/bb-imager-gui -t {{_RELEASE_DIR_GUI}}/AppDir/usr/bin/ + install -D -m 644 {{_GUI_ASSETS_LINUX}}/BeagleBoardImager.desktop -t {{_RELEASE_DIR_GUI}}/AppDir/ + sed -i "s/^X-AppImage-Version=0.0.0/X-AppImage-Version={{VERSION}}/" {{_RELEASE_DIR_GUI}}/AppDir/BeagleBoardImager.desktop + install -D -m 644 {{_GUI_ASSETS}}/icons/icon.png {{_RELEASE_DIR_GUI}}/AppDir/bb-imager.png + ARCH={{ if TARGET == "x86_64-unknown-linux-gnu" { "x86_64" } else if TARGET == "aarch64-unknown-linux-gnu" { "aarch64" } else if TARGET == "armv7-unknown-linux-gnueabihf" { "armhf" } else { error("Unsupported target for appimages") } }} \ + {{APPIMAGETOOL}} --appimage-extract-and-run {{_RELEASE_DIR_GUI}}/AppDir {{_RELEASE_DIR_GUI}}/{{_PACKAGE_NAME_GUI}}-{{TARGET}}.AppImage + rm -rf {{_RELEASE_DIR_GUI}}/AppDir + + +# Create debian package for GUI +[group('packaging')] +package-gui-linux-deb TARGET=_HOST_TARGET: (build-gui TARGET) (_package-linux-deb 'bb-imager-gui' TARGET _RELEASE_DIR_GUI / _PACKAGE_NAME_GUI + '-' + TARGET + '.deb') + + +# Create macOS dmg package +[group('packaging')] +package-gui-darwin-dmg TARGET=_HOST_TARGET: (build-gui TARGET) + @echo "Create GUI macOS dmg for {{TARGET}}" + sed -i'.bak' -e "s/0\.0\.0/{{VERSION}}/g" -e "s/fffffff/{{_COMMIT_HASH}}/g" {{_GUI_ASSETS_DARWIN}}/Info.plist + mkdir -p {{_RELEASE_DIR_GUI}}/AppDir/BeagleBoardImager.app/Contents/{MacOS,Resources} + cp {{_GUI_ASSETS_DARWIN}}/Info.plist {{_RELEASE_DIR_GUI}}/AppDir/BeagleBoardImager.app/Contents/ + cp {{_GUI_ASSETS}}/icons/icon.icns {{_RELEASE_DIR_GUI}}/AppDir/BeagleBoardImager.app/Contents/Resources/ + cp target/{{TARGET}}/release/bb-imager-gui {{_RELEASE_DIR_GUI}}/AppDir/BeagleBoardImager.app/Contents/MacOS/ + create-dmg \ + --volname "BeagleBoardImager Installer" \ + --volicon "{{_GUI_ASSETS}}/icons/icon.icns" \ + --window-pos 200 120 \ + --window-size 800 400 \ + --icon-size 100 \ + --icon "BeagleBoardImager.app" 200 190 \ + --hide-extension "BeagleBoardImager.app" \ + --app-drop-link 600 185 \ + --hdiutil-verbose \ + --skip-jenkins \ + "{{_RELEASE_DIR_GUI}}/{{_PACKAGE_NAME_GUI}}-{{TARGET}}.dmg" \ + "{{_RELEASE_DIR_GUI}}/AppDir/" + rm -rf {{_RELEASE_DIR_GUI}}/AppDir/ + + +# Create Windows portable zip package +[group('packaging')] +package-gui-windows-zip TARGET=_HOST_TARGET: (build-gui TARGET) + @echo "Create GUI Portable Windows zip for {{TARGET}}" + mkdir -p {{_RELEASE_DIR_GUI}} + zip -j {{_RELEASE_DIR_GUI}}/{{_PACKAGE_NAME_GUI}}-{{TARGET}}.zip target/{{TARGET}}/release/bb-imager-gui.exe diff --git a/bb-imager-service/Makefile b/bb-imager-service/Makefile deleted file mode 100644 index 272abfdcf90c2a01303ec7f51abb2267faae082d..0000000000000000000000000000000000000000 --- a/bb-imager-service/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -PACKAGE_NAME_SERVICE = bb-imager-service -RELEASE_DIR_SERVICE = ${RELEASE_DIR}/${PACKAGE_NAME_SERVICE}/${VERSION} - -build-service-%: - $(info "Building D-Bus Service for $*") - $(RUST_BUILDER) build --release --target $* -p bb-imager-service - -package-service-linux-deb-%: build-service-% - $(info "Create D-Bus Service Linux deb $*") -ifeq ($(RUST_BUILDER_NAME), cross) - $(CROSS_UTIL) run --target $* -- "cargo deb --target $* -p bb-imager-service --no-build -o ${RELEASE_DIR_SERVICE}/${PACKAGE_NAME_SERVICE}-$*.deb --no-strip" -else - $(RUST_BUILDER) deb --target $* -p bb-imager-service --no-build -o ${RELEASE_DIR_SERVICE}/${PACKAGE_NAME_SERVICE}-$*.deb --no-strip -endif - -package-service-linux-xz-%: build-service-% - $(info "Create D-Bus Service Linux xz $*") - install -D target/$*/release/bb-imager-service -t ${RELEASE_DIR_SERVICE}/bb-imager-service-tempdir/usr/bin/ - install -D -m 644 $(SERVICE_ASSETS)/dbus-org.beagleboard.ImagingService.service -t ${RELEASE_DIR_SERVICE}/bb-imager-service-tempdir/usr/lib/systemd/system/ - install -D -m 644 $(SERVICE_ASSETS)/org.beagleboard.ImagingService.conf -t ${RELEASE_DIR_SERVICE}/bb-imager-service-tempdir/usr/share/dbus-1/system.d/ - install -D -m 644 $(SERVICE_ASSETS)/org.beagleboard.ImagingService.policy -t ${RELEASE_DIR_SERVICE}/bb-imager-service-tempdir/usr/share/polkit-1/actions/ - install -D -m 644 $(SERVICE_ASSETS)/org.beagleboard.ImagingService.service -t ${RELEASE_DIR_SERVICE}/bb-imager-service-tempdir/usr/share/dbus-1/system-services/ - cd ${RELEASE_DIR_SERVICE}/bb-imager-service-tempdir/ && tar cfJ ${RELEASE_DIR_SERVICE}/${PACKAGE_NAME_SERVICE}-$*.tar.xz * - rm -rf ${RELEASE_DIR_SERVICE}/bb-imager-service-tempdir diff --git a/bb-imager-service/justfile b/bb-imager-service/justfile new file mode 100644 index 0000000000000000000000000000000000000000..8a2c67849e48f1528890c6554b5ab64db5c22683 --- /dev/null +++ b/bb-imager-service/justfile @@ -0,0 +1,30 @@ +_PACKAGE_NAME_SERVICE := 'bb-imager-service' + +_RELEASE_DIR_SERVICE := _RELEASE_DIR / _PACKAGE_NAME_SERVICE / VERSION + +_SERVICE_ASSETS := source_directory() / 'assets' + + +# Release build for Beagle Board Imager GUI. Should be used for final testing +[group('build')] +build-service TARGET=_HOST_TARGET: + @echo "Build Beagle Board Imager Service for {{TARGET}}" + {{RUST_BUILDER}} build --release --target {{TARGET}} -p bb-imager-service + + +# Create debian package for Beagle Board Imager Service +[group('packaging')] +package-service-linux-deb TARGET=_HOST_TARGET: (build-service TARGET) (_package-linux-deb 'bb-imager-service' TARGET _RELEASE_DIR_SERVICE / _PACKAGE_NAME_SERVICE + '-' + TARGET + '.deb') + + +# Create compressed Beagle Board Imager service package for Linux +[group('packaging')] +package-service-linux-xz TARGET=_HOST_TARGET: (build-service TARGET) + @echo "Create compressed Beagle Board Service Package for Linux" + install -D target/{{TARGET}}/release/bb-imager-service -t {{_RELEASE_DIR_CLI}}/bb-imager-service-tempdir/usr/bin/ + install -D -m 644 {{_SERVICE_ASSETS}}/dbus-org.beagleboard.ImagingService.service -t {{_RELEASE_DIR_SERVICE}}/bb-imager-service-tempdir/usr/lib/systemd/system/ + install -D -m 644 {{_SERVICE_ASSETS}}/org.beagleboard.ImagingService.conf -t {{_RELEASE_DIR_SERVICE}}/bb-imager-service-tempdir/usr/share/dbus-1/system.d/ + install -D -m 644 {{_SERVICE_ASSETS}}/org.beagleboard.ImagingService.policy -t {{_RELEASE_DIR_SERVICE}}/bb-imager-service-tempdir/usr/share/polkit-1/actions/ + install -D -m 644 {{_SERVICE_ASSETS}}/org.beagleboard.ImagingService.service -t {{_RELEASE_DIR_SERVICE}}/bb-imager-service-tempdir/usr/share/dbus-1/system-services/ + cd {{_RELEASE_DIR_SERVICE}}/bb-imager-service-tempdir/ && tar cfJ {{_RELEASE_DIR_SERVICE}}/{{_PACKAGE_NAME_SERVICE}}-{{TARGET}}.tar.xz * + rm -rf {{_RELEASE_DIR_SERVICE}}/bb-imager-service-tempdir diff --git a/justfile b/justfile new file mode 100644 index 0000000000000000000000000000000000000000..0c1487f6c1f3195bc96e659cdc2e9616faf3a037 --- /dev/null +++ b/justfile @@ -0,0 +1,45 @@ +#!/usr/bin/env just --justfile + +set unstable := true + +import 'scripts/checks.just' +import 'scripts/setup.just' +import 'scripts/packaging.just' +import 'scripts/release.just' +import 'bb-imager-gui/justfile' +import 'bb-imager-cli/justfile' +import 'bb-imager-service/justfile' + +[private] +_CARGO_PATH := which("cargo") +[private] +_COMMIT_HASH := shell('git rev-parse HEAD') +[private] +_HOST_TARGET := arch() + if os() == 'linux' { '-unknown-linux-gnu' } else if os() == 'macos' { '-apple-darwin' } else if os() == 'windows' { '-pc-windows-gnu' } else { error("Unsupported Platform") } +[private] +_RELEASE_DIR := source_directory() / 'release' +[private] +_EXE_DIR := if os() == 'linux' { executable_directory() } else { '' } + +# Public arguments + +RUST_BUILDER := env("RUST_BUILDER", _CARGO_PATH) +PB2_MSPM0 := env("PB2_MSPM0", '0') +APPIMAGETOOL := env("APPIMAGETOOL", which('appimagetool')) +VERSION := env('VERSION', shell('grep "version =" Cargo.toml | sed "s/version = \"\(.*\)\"/\1/"')) + +# default recipe to display help information +default: + @just --list + +# Run tests on workspace +[group('housekeeping')] +test: + @echo "Run workspace tests" + {{ RUST_BUILDER }} test --workspace + +# Clean Artifacts +[group('housekeeping')] +clean: + {{ _CARGO_PATH }} clean + rm -rf release diff --git a/scripts/checks.just b/scripts/checks.just new file mode 100644 index 0000000000000000000000000000000000000000..86979aa3be4ace1d023a1d49b2f6f0f71bfb0ea4 --- /dev/null +++ b/scripts/checks.just @@ -0,0 +1,16 @@ +_appimage_prechecks TARGET: + @echo "Checking appimagetool" + {{ if shell('command -v $1', APPIMAGETOOL) == '' { error('Appimagetool is missing. Try running `just setup-appimage`') } else { '' } }} + + +_deb_prechecks: + @echo "Checking if cargo-deb is installed" + {{ if which('cargo-deb') == '' { error('cargo-deb is required to build Debian package. Try running `just setup-deb`') } else { '' } }} + + +# Run code checks +[group('housekeeping')] +check: + @echo "Run clippy checks" + {{ RUST_BUILDER }} clippy --all-targets --all-features --no-deps --workspace + diff --git a/scripts/packaging.just b/scripts/packaging.just new file mode 100644 index 0000000000000000000000000000000000000000..af40e454adc452b260bfd691ed376d32f5430bc4 --- /dev/null +++ b/scripts/packaging.just @@ -0,0 +1,10 @@ +_CARGO_DEB_FLAGS := ' --no-build --no-strip' + +# Create Linux debian package +_package-linux-deb PKG TARGET OUTPUT: _deb_prechecks + @echo "Create {{ PKG }} Linux debian package for {{ TARGET }}" + {{ if file_name(RUST_BUILDER) == 'cross' { \ + RUST_BUILDER + ' run --target ' + TARGET + ' -- "cargo deb --target ' + TARGET + ' -p ' + PKG + ' -o ' + OUTPUT + _CARGO_DEB_FLAGS + '"' \ + } else { \ + RUST_BUILDER + ' deb --target ' + TARGET + ' -p ' + PKG + ' -o ' + OUTPUT + _CARGO_DEB_FLAGS \ + } }} diff --git a/scripts/release.just b/scripts/release.just new file mode 100644 index 0000000000000000000000000000000000000000..81af127da1441c4d47dc6e292ea96ca8937dc9ad --- /dev/null +++ b/scripts/release.just @@ -0,0 +1,21 @@ +# Generate all supported release for the Linux target +_release-linux TARGET=_HOST_TARGET: (package-cli-linux-xz TARGET) (package-gui-linux-appimage TARGET) (package-gui-linux-deb TARGET) + {{ if PB2_MSPM0 == '1' { 'just package-service-linux-xz ' + TARGET + ' package-service-linux-deb ' + TARGET } else { '' } }} + +# Generate all supported release for the Windows target +_release-windows TARGET=_HOST_TARGET: (package-cli-windows-zip TARGET) (package-gui-windows-zip TARGET) + +# Generate all supported release for the macOS target +_release-darwin TARGET=_HOST_TARGET: (package-cli-darwin-zip TARGET) (package-gui-darwin-dmg TARGET) + +# Generate all supported packages for the target +[group('packaging')] +release TARGET=_HOST_TARGET: + @echo "Generating all release for {{ TARGET }}" + {{ if TARGET =~ "windows" { \ + 'just _release-windows ' + TARGET \ + } else if TARGET =~ "darwin" { \ + 'just _release-darwin ' + TARGET \ + } else if TARGET =~ "linux" { \ + 'just _release-linux ' + TARGET \ + } else { error('Unsupported Platform') } }} diff --git a/scripts/setup.just b/scripts/setup.just new file mode 100644 index 0000000000000000000000000000000000000000..8f70ff10fd6294f793aec2c170c1c7b575d6d477 --- /dev/null +++ b/scripts/setup.just @@ -0,0 +1,35 @@ +_check-appimagetool: + {{ if which('appimagetool') == '' { '' } else { error('Appimagetool is already available') } }} + + +# Setup for building appimages +[group('setup')] +setup-appimage INSTALL_DIR=_EXE_DIR: _check-appimagetool + @echo "Install Appimagetool at {{ INSTALL_DIR }}" + wget https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-$(uname -m).AppImage -O {{INSTALL_DIR}}/appimagetool + chmod +x {{INSTALL_DIR}}/appimagetool + + +# Setup for building debian packages +[group('setup')] +setup-deb: + @echo "Install cargo-deb" + {{ if which('cargo-binstall') == '' { 'cargo install --locked -y cargo-deb' } else { 'cargo binstall -y cargo-deb ' } }} + + +# Setup for building dmg +[group('setup')] +setup-dmg: + @echo "Install create-dmg" + brew install create-dmg + + +# Check if Rust is already installed +_check-rust: + {{ if which('cargo') == '' { '' } else { error('Rust is already available') } }} + + +# Setup rust toolcahin +setup-rust: _check-rust + @echo "Setting up rust using rustup" + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y