diff --git a/.github/workflows/packages.yml b/.github/workflows/packages.yml new file mode 100644 index 00000000..2e10540b --- /dev/null +++ b/.github/workflows/packages.yml @@ -0,0 +1,304 @@ +name: Packages + +# Builds every DraftCraft package: macOS (Apple silicon and Intel DMG and CLI zip), Windows (x64 +# and arm64 installer and zip) and Linux (x86_64 and aarch64 AppImage and .deb). Windows arm64 is +# cross-compiled on an x86_64 runner and macOS Intel on an Apple-silicon one; Linux aarch64 builds +# on an ARM runner. The files carry no version in their +# names, so releases/latest/download/ always gives the newest. +# +# release.yml calls this for a version tag and publishes what it builds. It also runs on pull +# requests that change the packaging, so a change is seen working before a release: the packages +# are then only this run's artifacts. +on: + workflow_call: + inputs: + ref: + description: "Git ref to build" + required: true + type: string + pull_request: + paths: + - "packaging/**" + - ".github/workflows/packages.yml" + - ".github/workflows/release.yml" + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: packages-${{ inputs.ref || github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +env: + CARGO_TERM_COLOR: always + # Open-licensed (SIL OFL 1.1) interface fonts embedded in the build; their licences ship in the packages. + CRAFT_FONTS_REF: b076417b5880bd4154bd22f00695b1d28c6bea83 + +jobs: + linux: + name: linux-${{ matrix.arch }} + # The oldest supported runners, so the binaries run on any newer glibc (the .deb asks for >= 2.35). + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - { arch: x86_64, os: ubuntu-22.04, target: x86_64-unknown-linux-gnu, deb: amd64 } + - { arch: aarch64, os: ubuntu-22.04-arm, target: aarch64-unknown-linux-gnu, deb: arm64 } + env: + TARGET: ${{ matrix.target }} + ARCH: ${{ matrix.arch }} + NFPM_VERSION: 2.48.0 + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ inputs.ref || github.ref }} + - name: Check out craft-fonts + uses: actions/checkout@v4 + with: + repository: storytold/craft-fonts + ref: ${{ env.CRAFT_FONTS_REF }} + path: craft-fonts + - name: Install Rust + run: | + rustup toolchain install stable --profile minimal --target "$TARGET" + rustup default stable + - uses: Swatinem/rust-cache@v2 + with: + key: ${{ matrix.target }} + - name: Install packaging tools + run: | + set -euo pipefail + sudo apt-get update + sudo apt-get install -y desktop-file-utils + # nfpm builds the .deb; its release is checked against the published checksums. + cd "$RUNNER_TEMP" + base="https://github.com/goreleaser/nfpm/releases/download/v$NFPM_VERSION" + pkg="nfpm_${NFPM_VERSION}_${{ matrix.deb }}.deb" + curl --proto '=https' -fsSLO "$base/$pkg" + curl --proto '=https' -fsSLO "$base/checksums.txt" + grep " $pkg\$" checksums.txt | sha256sum --check - + sudo dpkg -i "$pkg" + nfpm --version + - name: Build + run: | + set -euo pipefail + export CRAFT_FONTS_DIR="$GITHUB_WORKSPACE/craft-fonts" + export DRAFTCRAFT_BUILD_SHA="$(git rev-parse HEAD)" + cargo build --release --locked --target "$TARGET" -p draftcraft -p draftcraft-cli + # draftcraft-cli's man pages and shell completions for the .deb, in a separate run so the + # example's dev-dependencies don't change the binaries (packaging/linux/package.sh). + cargo build --release --locked --target "$TARGET" -p draftcraft-cli --example man-and-completions + - name: Package + run: | + set -euo pipefail + export CRAFT_FONTS_DIR="$GITHUB_WORKSPACE/craft-fonts" + export DRAFTCRAFT_BUILD_SHA="$(git rev-parse HEAD)" + mkdir -p dist/upload + # ARCH (from the matrix) picks appimagetool and the AppImage runtime for this processor. + packaging/linux/appimage.sh "target/$TARGET/release" "dist/upload/draftcraft-linux-$ARCH.AppImage" + DIST="$PWD/dist/deb" packaging/linux/package.sh --skip-build --target "$TARGET" --formats deb + cp dist/deb/draftcraft-*-linux-"$ARCH".deb "dist/upload/draftcraft-linux-$ARCH.deb" + ls -l dist/upload + - name: Check the .deb + run: | + set -euo pipefail + deb="dist/upload/draftcraft-linux-$ARCH.deb" + dpkg-deb --info "$deb" + test "$(dpkg-deb --field "$deb" Architecture)" = "${{ matrix.deb }}" + dpkg-deb --contents "$deb" + sudo apt-get install -y "./$deb" + # The menu entry, its icon, and the file manager's DXF/DWG handler list. + test -x /usr/bin/draftcraft + desktop-file-validate /usr/share/applications/dev.skryx.draftcraft.desktop + test -f /usr/share/icons/hicolor/256x256/apps/dev.skryx.draftcraft.png + test -f /usr/share/mime/packages/dev.skryx.draftcraft.xml + grep -E '^image/vnd\.dxf=.*dev\.skryx\.draftcraft\.desktop' /usr/share/applications/mimeinfo.cache + grep -E '^image/vnd\.dwg=.*dev\.skryx\.draftcraft\.desktop' /usr/share/applications/mimeinfo.cache + draftcraft-cli --version + sudo apt-get remove -y draftcraft + test ! -e /usr/bin/draftcraft + if grep -q dev.skryx.draftcraft.desktop /usr/share/applications/mimeinfo.cache; then + echo "removing the package left DraftCraft as a DXF/DWG handler" >&2 + exit 1 + fi + # The AppImage starts its CLI (extracted: CI runners have no FUSE). + APPIMAGE_EXTRACT_AND_RUN=1 "dist/upload/draftcraft-linux-$ARCH.AppImage" cli --version + - uses: actions/upload-artifact@v4 + with: + name: linux-${{ matrix.arch }} + path: dist/upload/* + if-no-files-found: error + + windows: + name: windows-${{ matrix.arch }} + runs-on: windows-2022 + strategy: + fail-fast: false + matrix: + include: + - { arch: x64, target: x86_64-pc-windows-msvc } + - { arch: arm64, target: aarch64-pc-windows-msvc } + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ inputs.ref || github.ref }} + - name: Check out craft-fonts + uses: actions/checkout@v4 + with: + repository: storytold/craft-fonts + ref: ${{ env.CRAFT_FONTS_REF }} + path: craft-fonts + - name: Install Rust + shell: bash + run: | + rustup toolchain install stable --profile minimal --target ${{ matrix.target }} + rustup default stable + - uses: Swatinem/rust-cache@v2 + with: + key: ${{ matrix.target }} + - name: Install WiX + shell: pwsh + run: | + dotnet tool install --global wix --version 5.0.2 + wix extension add -g WixToolset.UI.wixext/5.0.2 + wix --version + - name: Build, sign and package + shell: pwsh + env: + # Optional: without them sign.ps1 warns and leaves the files unsigned. + WINDOWS_CERTIFICATE: ${{ secrets.WINDOWS_CERTIFICATE }} + WINDOWS_CERTIFICATE_PASSWORD: ${{ secrets.WINDOWS_CERTIFICATE_PASSWORD }} + run: | + $env:CRAFT_FONTS_DIR = Join-Path $env:GITHUB_WORKSPACE 'craft-fonts' + $env:DRAFTCRAFT_BUILD_SHA = (git rev-parse HEAD) + ./packaging/windows/package.ps1 -Arch ${{ matrix.arch }} + - name: Name the release files + shell: bash + run: | + set -euo pipefail + version="$(awk '/^\[/{p=($0=="[workspace.package]");next} p&&$1=="version"{gsub(/[" ]/,"",$3);print $3;exit}' Cargo.toml)" + stage="target/windows-package/${{ matrix.arch }}" + mkdir -p dist/upload + cp "dist/release/draftcraft-$version-windows-${{ matrix.arch }}.msi" "dist/upload/draftcraft-windows-${{ matrix.arch }}.msi" + # The zip in-app updates of unzipped copies read: a DraftCraft/ folder with DraftCraft.exe + # (crates/ui-egui/src/self_update.rs). The same signed binaries as the installer. + dir="dist/zip/DraftCraft" + mkdir -p "$dir" + cp README.md LICENSE-MIT LICENSE-APACHE NOTICE ATTRIBUTION.md "$dir/" + for f in craft-fonts/fonts/*/OFL.txt; do cp "$f" "$dir/OFL-$(basename "$(dirname "$f")").txt"; done + cp "$stage/draftcraft.exe" "$dir/DraftCraft.exe" + cp "$stage/draftcraft-cli.exe" "$dir/draftcraft-cli.exe" + (cd dist/zip && 7z a -tzip "../upload/draftcraft-windows-${{ matrix.arch }}.zip" DraftCraft > /dev/null) + ls -l dist/upload + - name: Install, check and uninstall the installer + # A real install on this throwaway runner, for this account (no administrator), as a + # double-click with the default choice does. The arm64 package can't run here. + if: matrix.arch == 'x64' + shell: pwsh + run: | + $ErrorActionPreference = 'Stop' + $msi = (Resolve-Path 'dist/upload/draftcraft-windows-x64.msi').Path + $log = Join-Path $env:RUNNER_TEMP 'install.log' + $p = Start-Process msiexec.exe -ArgumentList @('/i', "`"$msi`"", '/qn', '/l*v', "`"$log`"") -Wait -PassThru + if ($p.ExitCode -ne 0) { Get-Content $log -Tail 80; throw "install failed: $($p.ExitCode)" } + $exe = (Get-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\App Paths\draftcraft.exe').'(default)' + if (-not (Test-Path $exe)) { throw "App Paths names a missing exe: $exe" } + Write-Output "installed: $exe" + $classes = 'HKCU:\Software\Classes' + foreach ($ext in '.dxf', '.dwg') { + if ((Get-ItemProperty "$classes\$ext\OpenWithProgids").PSObject.Properties.Name -notcontains 'DraftCraft.Drawing') { throw "$ext lacks the DraftCraft.Drawing OpenWithProgids entry" } + if ((Get-ItemProperty "$classes\Applications\draftcraft.exe\SupportedTypes").PSObject.Properties.Name -notcontains $ext) { throw "SupportedTypes lacks $ext" } + if ((Get-ItemProperty 'HKCU:\Software\DraftCraft\Capabilities\FileAssociations').$ext -ne 'DraftCraft.Drawing') { throw "Capabilities lack $ext" } + } + $command = (Get-ItemProperty "$classes\DraftCraft.Drawing\shell\open\command").'(default)' + if ($command -ne "`"$exe`" `"%1`"") { throw "unexpected open command: $command" } + if ((Get-ItemProperty 'HKCU:\Software\RegisteredApplications').DraftCraft -ne 'Software\DraftCraft\Capabilities') { throw 'not in RegisteredApplications' } + & (Join-Path (Split-Path $exe) 'draftcraft-cli.exe') --version + if ($LASTEXITCODE -ne 0) { throw 'draftcraft-cli --version failed' } + $p = Start-Process msiexec.exe -ArgumentList @('/x', "`"$msi`"", '/qn') -Wait -PassThru + if ($p.ExitCode -ne 0) { throw "uninstall failed: $($p.ExitCode)" } + if (Test-Path $exe) { throw "uninstall left $exe" } + $left = Get-ItemProperty "$classes\DraftCraft.Drawing\shell\open\command" -ErrorAction SilentlyContinue + if ($left -and $left.'(default)') { throw 'uninstall left the DraftCraft.Drawing open command' } + foreach ($ext in '.dxf', '.dwg') { + $left = Get-ItemProperty "$classes\$ext\OpenWithProgids" -ErrorAction SilentlyContinue + if ($left -and ($left.PSObject.Properties.Name -contains 'DraftCraft.Drawing')) { throw "uninstall left $ext in DraftCraft's Open with list" } + } + Write-Output 'installed, registered for .dxf and .dwg, and uninstalled cleanly' + - uses: actions/upload-artifact@v4 + with: + name: windows-${{ matrix.arch }} + path: dist/upload/* + if-no-files-found: error + + macos: + name: macos-${{ matrix.arch }} + # Xcode 26 compiles the macOS 26+ Icon Composer icon (DraftCraft.icon → Assets.car), so the + # Intel build is cross-compiled on this Apple-silicon runner too. + runs-on: macos-26 + strategy: + fail-fast: false + matrix: + include: + - { arch: arm64, target: aarch64-apple-darwin, package: aarch64 } + - { arch: x86_64, target: x86_64-apple-darwin, package: x86_64 } + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ inputs.ref || github.ref }} + - name: Check out craft-fonts + uses: actions/checkout@v4 + with: + repository: storytold/craft-fonts + ref: ${{ env.CRAFT_FONTS_REF }} + path: craft-fonts + - name: Install Rust + run: | + rustup toolchain install stable --profile minimal --target ${{ matrix.target }} + rustup default stable + - uses: Swatinem/rust-cache@v2 + with: + key: ${{ matrix.target }} + - name: Import the signing certificate + # Optional: without APPLE_CERTIFICATE the script warns, and package.sh signs ad hoc. + env: + APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }} + APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }} + run: packaging/macos/import-cert.sh + - name: Build and package + env: + # Notarization runs when all three are set and a Developer ID was imported above. + APPLE_ID: ${{ secrets.APPLE_ID }} + APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }} + APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }} + run: | + set -euo pipefail + xcodebuild -version + export CRAFT_FONTS_DIR="$GITHUB_WORKSPACE/craft-fonts" + export DRAFTCRAFT_BUILD_SHA="$(git rev-parse HEAD)" + packaging/macos/package.sh --arch ${{ matrix.package }} + version="$(awk '/^\[/{p=($0=="[workspace.package]");next} p&&$1=="version"{gsub(/[" ]/,"",$3);print $3;exit}' Cargo.toml)" + mkdir -p dist/upload + cp "dist/release/draftcraft-$version-macos-${{ matrix.package }}.dmg" dist/upload/draftcraft-macos-${{ matrix.arch }}.dmg + cp "dist/release/draftcraft-cli-$version-macos-${{ matrix.package }}.zip" dist/upload/draftcraft-cli-macos-${{ matrix.arch }}.zip + ls -l dist/upload + - name: Check the app + run: | + set -euo pipefail + app=target/macos-package/DraftCraft.app + # Built for this matrix entry's processor only. + test "$(lipo -archs "$app/Contents/MacOS/DraftCraft")" = ${{ matrix.arch }} + test "$(lipo -archs "$app/Contents/MacOS/draftcraft-cli")" = ${{ matrix.arch }} + # The .dxf and .dwg document types Finder's Open With reads. + plist="$app/Contents/Info.plist" + for i in 0 1; do + plutil -extract "CFBundleDocumentTypes.$i.LSItemContentTypes.0" raw -o - "$plist" + plutil -extract "UTImportedTypeDeclarations.$i.UTTypeIdentifier" raw -o - "$plist" + done + - uses: actions/upload-artifact@v4 + with: + name: macos-${{ matrix.arch }} + path: dist/upload/* + if-no-files-found: error diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6c9b429c..4c168614 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,9 +1,9 @@ name: Release -# Builds every DraftCraft package when a version tag is pushed and attaches them to that tag's -# GitHub release: macOS (Apple silicon DMG and CLI zip), Linux (x86_64 AppImage) and Windows -# (x64, arm64 zips). Windows arm64 is cross-compiled on an x86_64 runner. The files carry no -# version in their names, so releases/latest/download/ always gives the newest. +# Builds every DraftCraft package when a version tag is pushed (packages.yml) and attaches them to +# that tag's GitHub release: macOS (Apple silicon and Intel DMG and CLI zip), Windows (x64 and arm64 +# installer and zip) and Linux (x86_64 and aarch64 AppImage and .deb). The files carry no version in their names, so +# releases/latest/download/ always gives the newest. on: push: tags: ["v*"] @@ -21,114 +21,16 @@ concurrency: group: release-${{ github.ref }} cancel-in-progress: false -env: - CARGO_TERM_COLOR: always - # Open-licensed (SIL OFL 1.1) interface fonts embedded in the build; their licences ship in the archives. - CRAFT_FONTS_REF: b076417b5880bd4154bd22f00695b1d28c6bea83 - jobs: - build: - name: ${{ matrix.name }} - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - include: - - { name: linux-x86_64, os: ubuntu-22.04, target: x86_64-unknown-linux-gnu } - - { name: windows-x64, os: windows-2022, target: x86_64-pc-windows-msvc } - - { name: windows-arm64, os: windows-2022, target: aarch64-pc-windows-msvc } - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ inputs.tag || github.ref }} - - name: Check out craft-fonts - uses: actions/checkout@v4 - with: - repository: storytold/craft-fonts - ref: ${{ env.CRAFT_FONTS_REF }} - path: craft-fonts - - name: Install Rust - shell: bash - run: | - rustup toolchain install stable --profile minimal --target ${{ matrix.target }} - rustup default stable - - uses: Swatinem/rust-cache@v2 - with: - key: ${{ matrix.target }} - - name: Build - shell: bash - run: | - export CRAFT_FONTS_DIR="$GITHUB_WORKSPACE/craft-fonts" - export DRAFTCRAFT_BUILD_SHA="$(git rev-parse HEAD)" - cargo build --release --locked --target ${{ matrix.target }} -p draftcraft -p draftcraft-cli - - name: Package - shell: bash - run: | - set -euo pipefail - # Names without the version, so releases/latest/download/ always works. - bin="target/${{ matrix.target }}/release" - mkdir -p dist - if [[ "${{ runner.os }}" == "Windows" ]]; then - dir="dist/DraftCraft" - mkdir -p "$dir" - cp README.md LICENSE-MIT LICENSE-APACHE NOTICE ATTRIBUTION.md "$dir/" - for f in craft-fonts/fonts/*/OFL.txt; do cp "$f" "$dir/OFL-$(basename "$(dirname "$f")").txt"; done - cp "$bin/draftcraft.exe" "$dir/DraftCraft.exe" - cp "$bin/draftcraft-cli.exe" "$dir/draftcraft-cli.exe" - (cd dist && 7z a -tzip "draftcraft-${{ matrix.name }}.zip" DraftCraft > /dev/null) - echo "ASSET=dist/draftcraft-${{ matrix.name }}.zip" >> "$GITHUB_ENV" - else - CRAFT_FONTS_DIR="$GITHUB_WORKSPACE/craft-fonts" packaging/linux/appimage.sh "$bin" "dist/draftcraft-${{ matrix.name }}.AppImage" - echo "ASSET=dist/draftcraft-${{ matrix.name }}.AppImage" >> "$GITHUB_ENV" - fi - - uses: actions/upload-artifact@v4 - with: - name: ${{ matrix.name }} - path: ${{ env.ASSET }} - if-no-files-found: error - - macos: - name: macos-arm64 - # Xcode 26 compiles the macOS 26+ Icon Composer icon (DraftCraft.icon → Assets.car). - runs-on: macos-26 - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ inputs.tag || github.ref }} - - name: Check out craft-fonts - uses: actions/checkout@v4 - with: - repository: storytold/craft-fonts - ref: ${{ env.CRAFT_FONTS_REF }} - path: craft-fonts - - name: Install Rust - run: | - rustup toolchain install stable --profile minimal --target aarch64-apple-darwin - rustup default stable - - uses: Swatinem/rust-cache@v2 - with: - key: aarch64-apple-darwin - - name: Build and package - run: | - set -euo pipefail - xcodebuild -version - export CRAFT_FONTS_DIR="$GITHUB_WORKSPACE/craft-fonts" - export DRAFTCRAFT_BUILD_SHA="$(git rev-parse HEAD)" - packaging/macos/package.sh --arch aarch64 - # Names without the version, so releases/latest/download/ always works. - version="$(awk '/^\[/{p=($0=="[workspace.package]");next} p&&$1=="version"{gsub(/[" ]/,"",$3);print $3;exit}' Cargo.toml)" - mkdir -p dist/upload - cp "dist/release/draftcraft-$version-macos-aarch64.dmg" dist/upload/draftcraft-macos-arm64.dmg - cp "dist/release/draftcraft-cli-$version-macos-aarch64.zip" dist/upload/draftcraft-cli-macos-arm64.zip - ls -l dist/upload - - uses: actions/upload-artifact@v4 - with: - name: macos-arm64 - path: dist/upload/* - if-no-files-found: error + packages: + uses: ./.github/workflows/packages.yml + with: + ref: ${{ inputs.tag || github.ref }} + # Signing and notarization use the repository's secrets when they are set (packages.yml). + secrets: inherit release: - needs: [build, macos] + needs: packages runs-on: ubuntu-latest permissions: contents: write diff --git a/ATTRIBUTION.md b/ATTRIBUTION.md index 72248a64..1c879bd0 100644 --- a/ATTRIBUTION.md +++ b/ATTRIBUTION.md @@ -43,6 +43,9 @@ contributors, and where a line says so by Skryx Dev: | `docs/screenshots/draftcraft-layout.png` | Skryx Dev | screenshot of DraftCraft 2.0.0 (2026-11-07) showing its own sample drawing; no third-party software or artwork | MIT OR Apache-2.0 | README illustration: a layout with a viewport | | `docs/screenshots/draftcraft-conic.png` | Skryx Dev | screenshot of DraftCraft 2.0.0 (2026-11-07) showing a drawing made in it with CONIC; no third-party software or artwork | MIT OR Apache-2.0 | README illustration: a layout with a viewport | | `assets/app-icon/src/DraftCraft.icon/Assets/draftcraft-art.png` | WithShalom Studios (DraftCraft) | original work for DraftCraft, drawn by `packaging/compass-icon.py` in [withshalom/draftcraft](https://github.com/withshalom/draftcraft) (2026) | MIT OR Apache-2.0 (the DraftCraft name and marks: [docs/brand/LICENSE-brand.txt](docs/brand/LICENSE-brand.txt)) | Layer of the Icon Composer icon (macOS 26+, compiled by actool) | +| `packaging/macos/dmg/background.png` | Skryx Dev (DraftCraft) | original work for DraftCraft, drawn by `packaging/macos/dmg/background.swift` (2026) with the DraftCraft logo (`docs/brand/draftcraft-logo.svg`); text rendered with [Inter](https://github.com/rsms/inter) (SIL OFL 1.1, the font itself is not included) | MIT OR Apache-2.0 (the DraftCraft name and marks: [docs/brand/LICENSE-brand.txt](docs/brand/LICENSE-brand.txt)) | Background of the macOS DMG window | +| `packaging/macos/dmg/background@2x.png` | Skryx Dev (DraftCraft) | original work for DraftCraft, drawn by `packaging/macos/dmg/background.swift` (2026) with the DraftCraft logo (`docs/brand/draftcraft-logo.svg`); text rendered with [Inter](https://github.com/rsms/inter) (SIL OFL 1.1, the font itself is not included) | MIT OR Apache-2.0 (the DraftCraft name and marks: [docs/brand/LICENSE-brand.txt](docs/brand/LICENSE-brand.txt)) | Retina background of the macOS DMG window | +| `packaging/macos/dmg/DS_Store` | Skryx Dev (DraftCraft) | generated by `packaging/macos/dmg/make-layout.sh` (2026) | MIT OR Apache-2.0 | Finder view settings of the macOS DMG volume (window size, icon places, background) | | `assets/app-icon/src/DraftCraft.icon/icon.json` | Skryx Dev | original work for DraftCraft (2026-11-06): the Icon Composer description of the macOS 26+ icon | MIT OR Apache-2.0 | Compiled by actool into Assets.car; fill colour set to DraftCraft blueprint blue (#0e3463) for the DraftCraft art layer | | `assets/app-icon/draftcraft.icns` | WithShalom Studios (DraftCraft) | original work for DraftCraft, drawn by `packaging/compass-icon.py` in [withshalom/draftcraft](https://github.com/withshalom/draftcraft) (2026) | MIT OR Apache-2.0 (the DraftCraft name and marks: [docs/brand/LICENSE-brand.txt](docs/brand/LICENSE-brand.txt)) | macOS icon | | `assets/app-icon/draftcraft.ico` | WithShalom Studios (DraftCraft) | original work for DraftCraft, drawn by `packaging/compass-icon.py` in [withshalom/draftcraft](https://github.com/withshalom/draftcraft) (2026) | MIT OR Apache-2.0 (the DraftCraft name and marks: [docs/brand/LICENSE-brand.txt](docs/brand/LICENSE-brand.txt)) | Windows icon | diff --git a/Cargo.lock b/Cargo.lock index 1dae744f..e5f4efb6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1425,6 +1425,7 @@ dependencies = [ "serde", "serde_json", "web-time", + "winreg", "zip", ] diff --git a/README.md b/README.md index 1515192d..e3a0170c 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@

- Download for Windows + Download for Windows Download for macOS Download for Linux (AppImage)

@@ -242,20 +242,29 @@ One click downloads the newest version from the [latest release](https://github. | System | Download | |---|---| -| Windows 10 and 11 | [64-bit (x64)](https://github.com/SkryxDev/DraftCraft/releases/latest/download/draftcraft-windows-x64.zip) · [ARM64](https://github.com/SkryxDev/DraftCraft/releases/latest/download/draftcraft-windows-arm64.zip) | -| macOS 11 or later (Apple silicon) | [Disk image](https://github.com/SkryxDev/DraftCraft/releases/latest/download/draftcraft-macos-arm64.dmg) | -| Linux, any distribution | [AppImage x86_64](https://github.com/SkryxDev/DraftCraft/releases/latest/download/draftcraft-linux-x86_64.AppImage) | +| Windows 10 and 11 | Installer: [64-bit (x64)](https://github.com/SkryxDev/DraftCraft/releases/latest/download/draftcraft-windows-x64.msi) · [ARM64](https://github.com/SkryxDev/DraftCraft/releases/latest/download/draftcraft-windows-arm64.msi) — zip: [x64](https://github.com/SkryxDev/DraftCraft/releases/latest/download/draftcraft-windows-x64.zip) · [ARM64](https://github.com/SkryxDev/DraftCraft/releases/latest/download/draftcraft-windows-arm64.zip) | +| macOS 11 or later | Disk image: [Apple silicon](https://github.com/SkryxDev/DraftCraft/releases/latest/download/draftcraft-macos-arm64.dmg) · [Intel](https://github.com/SkryxDev/DraftCraft/releases/latest/download/draftcraft-macos-x86_64.dmg) | +| Linux (any distribution) | AppImage: [x86_64](https://github.com/SkryxDev/DraftCraft/releases/latest/download/draftcraft-linux-x86_64.AppImage) · [ARM64 (aarch64)](https://github.com/SkryxDev/DraftCraft/releases/latest/download/draftcraft-linux-aarch64.AppImage) | +| Debian, Ubuntu 22.04 or later | .deb: [x86_64](https://github.com/SkryxDev/DraftCraft/releases/latest/download/draftcraft-linux-x86_64.deb) · [ARM64 (aarch64)](https://github.com/SkryxDev/DraftCraft/releases/latest/download/draftcraft-linux-aarch64.deb) | -The release page also has the macOS command-line tool on its own (`draftcraft-cli-macos-arm64.zip`) and +The release page also has the macOS command-line tool on its own (`draftcraft-cli-macos-arm64.zip`, +`draftcraft-cli-macos-x86_64.zip`) and `SHA256SUMS.txt`. Every download includes `draftcraft-cli`, the command-line and MCP tool. -- **Windows** — unzip the folder anywhere and run `DraftCraft.exe`. The build isn't signed, so SmartScreen - may stop it the first time: choose **More info**, then **Run anyway**. DraftCraft draws its own title bar +- **Windows** — run the installer: it installs for your account (or, if you choose, for everyone), adds + DraftCraft to the Start menu and offers it in **Open with** for `.dxf` and `.dwg` files; to open them + with DraftCraft by default, pick it in **Settings › Apps › Default apps**. The zip runs from any folder + instead (`DraftCraft.exe`) and changes nothing on the system. Neither is signed yet, so SmartScreen may + stop it the first time: choose **More info**, then **Run anyway**. DraftCraft draws its own title bar there, with the menu bar in it; set `DRAFTCRAFT_TITLEBAR=system` to keep Windows' own. - **macOS** — open the disk image and drag **DraftCraft** into **Applications**. It isn't notarized yet, so the first time open it once, then **System Settings › Privacy & Security › Open Anyway** — or run - `xattr -dr com.apple.quarantine /Applications/DraftCraft.app`. -- **Linux** — make the AppImage executable (`chmod +x draftcraft-linux-x86_64.AppImage`) and run it. + `xattr -dr com.apple.quarantine /Applications/DraftCraft.app`. Finder then lists DraftCraft under + **Open With** for `.dxf` and `.dwg` files. +- **Linux** — install the `.deb` for your processor (`sudo apt install ./draftcraft-linux-x86_64.deb`, or + `…-aarch64.deb` on ARM): DraftCraft appears in the applications menu and in the file manager's **Open With** + for `.dxf` and `.dwg`. Or make the AppImage executable (`chmod +x draftcraft-linux-x86_64.AppImage`) and + run it. DraftCraft tells you when a newer version is out: it asks GitHub when it starts, and **Help › Check for Updates…** checks at any time. That one request to `api.github.com` is all it sends; set diff --git a/crates/ui-egui/Cargo.toml b/crates/ui-egui/Cargo.toml index 89aef46c..bd87d3ca 100644 --- a/crates/ui-egui/Cargo.toml +++ b/crates/ui-egui/Cargo.toml @@ -34,6 +34,11 @@ craft-update = { workspace = true } # Unpacks the Windows update zip (self_update.rs); the same version and features craft-update uses. zip = { version = "9", default-features = false, features = ["deflate"] } +[target.'cfg(windows)'.dependencies] +# Tells a copy the installer (MSI) put in place from an unzipped folder (self_update.rs); the same +# version craft-update reads the registry with. +winreg = "0.55" + [dev-dependencies] # Tests build the dock area as the desktop app does (headless contexts keep floats in-window). craft-ui = { workspace = true, features = ["native-windows"] } diff --git a/crates/ui-egui/src/self_update.rs b/crates/ui-egui/src/self_update.rs index 331510cb..d4a6d125 100644 --- a/crates/ui-egui/src/self_update.rs +++ b/crates/ui-egui/src/self_update.rs @@ -4,12 +4,14 @@ //! //! | Installed as | Download | Put in place | //! |---|---|---| -//! | macOS `DraftCraft.app` (bundle id `dev.skryx.draftcraft`) | `draftcraft-macos-arm64.dmg` | the new app copied out of the disk image beside the old one, then swapped in by renaming (fine while it runs) | +//! | macOS `DraftCraft.app` (bundle id `dev.skryx.draftcraft`) | `draftcraft-macos-{arm64,x86_64}.dmg` | the new app copied out of the disk image beside the old one, then swapped in by renaming (fine while it runs) | //! | Windows folder with `DraftCraft.exe` | `draftcraft-windows-{x64,arm64}.zip` | unzipped beside it; each running file renamed to `*.old` (Windows allows that) and the new one moved in | -//! | Linux AppImage (`$APPIMAGE`) | `draftcraft-linux-x86_64.AppImage` | renamed over the old one (fine while it runs) | +//! | Linux AppImage (`$APPIMAGE`) | `draftcraft-linux-{x86_64,aarch64}.AppImage` | renamed over the old one (fine while it runs) | //! -//! Anything else (a build from source, a folder this account can't write, another system) gets the -//! release page instead, as before. The leftovers of a swap (the old app, `*.old` files) are deleted +//! Anything else (a build from source, a folder this account can't write, a copy installed by the +//! Windows installer or a Linux `.deb`, another system) gets the release page instead, as before: +//! the installer and the package manager keep their own record of the installed version, which +//! replacing the files would leave behind. The leftovers of a swap (the old app, `*.old` files) are deleted //! at the next start ([`clean_leftovers`]). //! //! Downloading, resuming and the checksum are `craft_update::Http::download`; only files under @@ -55,10 +57,20 @@ pub enum Install { impl Install { /// The release file this install updates from, on this processor. pub fn asset_name(&self) -> Option<&'static str> { - match self { - Self::MacApp(_) => cfg!(target_arch = "aarch64").then_some("draftcraft-macos-arm64.dmg"), - Self::WindowsFolder(_) => Some(if cfg!(target_arch = "aarch64") { "draftcraft-windows-arm64.zip" } else { "draftcraft-windows-x64.zip" }), - Self::AppImage(_) => cfg!(target_arch = "x86_64").then_some("draftcraft-linux-x86_64.AppImage"), + self.asset_name_for(std::env::consts::ARCH) + } + + /// The release file for a build on `arch` (`std::env::consts::ARCH`): every processor a + /// release has a package for, and `None` for the others. + fn asset_name_for(&self, arch: &str) -> Option<&'static str> { + match (self, arch) { + (Self::MacApp(_), "aarch64") => Some("draftcraft-macos-arm64.dmg"), + (Self::MacApp(_), "x86_64") => Some("draftcraft-macos-x86_64.dmg"), + (Self::WindowsFolder(_), "aarch64") => Some("draftcraft-windows-arm64.zip"), + (Self::WindowsFolder(_), "x86_64") => Some("draftcraft-windows-x64.zip"), + (Self::AppImage(_), "x86_64") => Some("draftcraft-linux-x86_64.AppImage"), + (Self::AppImage(_), "aarch64") => Some("draftcraft-linux-aarch64.AppImage"), + _ => None, } } @@ -80,6 +92,9 @@ pub fn detect() -> Option { return None; } let install = detect_at(&exe, std::env::var_os("APPIMAGE").map(PathBuf::from))?; + if matches!(install, Install::WindowsFolder(_)) && installed_by_msi(&exe) { + return None; + } install.asset_name()?; writable(container(&install)?).then_some(install) } @@ -100,6 +115,37 @@ fn detect_at(exe: &Path, appimage: Option) -> Option { None } +/// The `App Paths` key the Windows installer registers the app under (`packaging/windows/draftcraft.wxs`). +#[cfg(windows)] +const APP_PATHS_KEY: &str = r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\draftcraft.exe"; + +/// Windows: whether `exe` (canonical) is the copy the installer (MSI) put in place. The installer +/// names its exe in `App Paths`, under HKCU when installed for one account and HKLM for everyone; +/// an unzipped folder has no such entry. Such a copy updates by running the new installer. +#[cfg(windows)] +fn installed_by_msi(exe: &Path) -> bool { + use winreg::RegKey; + use winreg::enums::{HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, KEY_READ, KEY_WOW64_32KEY, KEY_WOW64_64KEY}; + [(HKEY_CURRENT_USER, 0), (HKEY_LOCAL_MACHINE, KEY_WOW64_64KEY), (HKEY_LOCAL_MACHINE, KEY_WOW64_32KEY)].into_iter().any(|(hive, view)| { + let Ok(key) = RegKey::predef(hive).open_subkey_with_flags(APP_PATHS_KEY, KEY_READ | view) else { return false }; + key.get_value::("").is_ok_and(|value| registered_exe_is(&value, exe)) + }) +} + +#[cfg(not(windows))] +fn installed_by_msi(_exe: &Path) -> bool { + false +} + +/// Whether an `App Paths` value (an exe's path, perhaps in quotes) names `exe` (canonical). Both +/// are compared canonical, so case and `\\?\` prefixes don't matter; a value naming a missing +/// file never matches. +#[cfg_attr(not(windows), allow(dead_code))] +fn registered_exe_is(value: &str, exe: &Path) -> bool { + let value = value.trim().trim_matches('"'); + !value.is_empty() && Path::new(value).canonicalize().is_ok_and(|p| p == exe) +} + /// The folder the swap writes in. fn container(install: &Install) -> Option<&Path> { match install { @@ -496,13 +542,46 @@ mod tests { #[test] fn each_install_updates_from_its_own_file() { - let win = Install::WindowsFolder(PathBuf::from("C:/DraftCraft")).asset_name().unwrap(); - assert!(win == "draftcraft-windows-x64.zip" || win == "draftcraft-windows-arm64.zip"); + let win = Install::WindowsFolder(PathBuf::from("C:/DraftCraft")); let mac = Install::MacApp(PathBuf::from("/Applications/DraftCraft.app")); - assert_eq!(mac.asset_name().is_some(), cfg!(target_arch = "aarch64")); - assert_eq!(mac.program(), PathBuf::from("/Applications/DraftCraft.app")); let linux = Install::AppImage(PathBuf::from("/home/me/DraftCraft.AppImage")); - assert_eq!(linux.asset_name().is_some(), cfg!(target_arch = "x86_64")); + assert_eq!(mac.program(), PathBuf::from("/Applications/DraftCraft.app")); + // The names the release workflow (.github/workflows/packages.yml) publishes. + for (install, arch, name) in [ + (&mac, "aarch64", Some("draftcraft-macos-arm64.dmg")), + (&mac, "x86_64", Some("draftcraft-macos-x86_64.dmg")), + (&win, "aarch64", Some("draftcraft-windows-arm64.zip")), + (&win, "x86_64", Some("draftcraft-windows-x64.zip")), + (&win, "x86", None), + (&linux, "x86_64", Some("draftcraft-linux-x86_64.AppImage")), + (&linux, "aarch64", Some("draftcraft-linux-aarch64.AppImage")), + (&linux, "riscv64", None), + ] { + assert_eq!(install.asset_name_for(arch), name, "{install:?} on {arch}"); + } + assert_eq!(mac.asset_name(), mac.asset_name_for(std::env::consts::ARCH)); + } + + #[test] + fn an_installer_copy_is_known_by_the_exe_its_registration_names() { + let dir = tempdir(); + let folder = dir.join("Programs/DraftCraft/DraftCraft"); + std::fs::create_dir_all(&folder).unwrap(); + let exe = folder.join("draftcraft.exe"); + std::fs::write(&exe, "").unwrap(); + let canonical = exe.canonicalize().unwrap(); + let path = exe.to_str().unwrap(); + // The installer writes the bare path; App Paths values are sometimes quoted. + for value in [path.to_string(), format!("\"{path}\""), format!(" {path} ")] { + assert!(registered_exe_is(&value, &canonical), "{value}"); + } + // Another copy, a missing file, an empty value. + let other = dir.join("DraftCraft/DraftCraft.exe"); + std::fs::create_dir_all(other.parent().unwrap()).unwrap(); + std::fs::write(&other, "").unwrap(); + for value in [other.to_str().unwrap(), dir.join("missing.exe").to_str().unwrap(), "", "\"\""] { + assert!(!registered_exe_is(value, &canonical), "{value}"); + } } #[test] diff --git a/docs/releasing.md b/docs/releasing.md index 50625888..034b6233 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -19,18 +19,27 @@ git tag -a v1.1.0 -m "DraftCraft 1.1.0" git push origin v1.1.0 ``` -Pushing a `v*` tag runs [`.github/workflows/release.yml`](../.github/workflows/release.yml). It builds +Pushing a `v*` tag runs [`.github/workflows/release.yml`](../.github/workflows/release.yml), which +builds every package with [`packages.yml`](../.github/workflows/packages.yml): | Package | Contents | | --- | --- | | `draftcraft-macos-arm64.dmg` | `DraftCraft.app` (Apple silicon, with `draftcraft-cli` inside) | -| `draftcraft-cli-macos-arm64.zip` | `draftcraft-cli` for macOS on its own | -| `draftcraft-windows-x64.zip` | `DraftCraft.exe`, `draftcraft-cli.exe`, licences | -| `draftcraft-windows-arm64.zip` | the same for Windows on ARM (cross-compiled) | +| `draftcraft-macos-x86_64.dmg` | the same for Intel Macs (cross-compiled on the Apple-silicon runner) | +| `draftcraft-cli-macos-arm64.zip`, `draftcraft-cli-macos-x86_64.zip` | `draftcraft-cli` for macOS on its own | +| `draftcraft-windows-x64.msi` | the installer (`packaging/windows/package.ps1`, WiX 5): for this account or everyone, Start menu, optional desktop shortcut, `.dxf`/`.dwg` registration | +| `draftcraft-windows-arm64.msi` | the same for Windows on ARM (cross-compiled) | +| `draftcraft-windows-x64.zip` | `DraftCraft.exe`, `draftcraft-cli.exe`, licences, to unzip anywhere | +| `draftcraft-windows-arm64.zip` | the same for Windows on ARM | | `draftcraft-linux-x86_64.AppImage` | the app; `… cli ` runs `draftcraft-cli` (built by `packaging/linux/appimage.sh`) | +| `draftcraft-linux-aarch64.AppImage` | the same for 64-bit ARM (built on an ARM runner) | +| `draftcraft-linux-x86_64.deb`, `draftcraft-linux-aarch64.deb` | Debian/Ubuntu package (`packaging/linux/package.sh`, nfpm): `/usr/bin`, menu entry, icons, MIME types, man pages | The names carry no version, so the README's `releases/latest/download/` links always give the -newest. The workflow creates the GitHub Release `DraftCraft v` with them and `SHA256SUMS.txt`. The DMG is +newest. The same workflow runs on every pull request that changes `packaging/` or the workflows; its +packages are then that run's artifacts, so a packaging change can be tried before a release. On the +way it installs the x64 MSI and both `.deb`s on the runners, checks the `.dxf`/`.dwg` registration, and +uninstalls them. The workflow creates the GitHub Release `DraftCraft v` with them and `SHA256SUMS.txt`. The DMG is made on a macOS 26 runner, whose Xcode compiles the app icon. The workflow can also be started by hand (**Actions › Release › Run workflow**) for an existing tag. @@ -38,12 +47,29 @@ made on a macOS 26 runner, whose Xcode compiles the app icon. The workflow can a From 2.0.2, **Update Now** in the app's update window downloads the new release and installs it ([`crates/ui-egui/src/self_update.rs`](../crates/ui-egui/src/self_update.rs)): `DraftCraft.app` from -`draftcraft-macos-arm64.dmg`, a Windows folder from `draftcraft-windows-{x64,arm64}.zip` (whose top -folder is `DraftCraft/`), the AppImage from `draftcraft-linux-x86_64.AppImage`. Each file is checked +`draftcraft-macos-{arm64,x86_64}.dmg`, a Windows folder from `draftcraft-windows-{x64,arm64}.zip` (whose +top folder is `DraftCraft/`), the AppImage from `draftcraft-linux-{x86_64,aarch64}.AppImage`, each for +the processor it runs on. Each file is checked against `SHA256SUMS.txt`, and the DMG's app must have the bundle id `dev.skryx.draftcraft` and the release's version. Keep those names, that folder and `SHA256SUMS.txt`, or installed copies can no longer update themselves (they then offer the release page instead). +A copy installed by the MSI (its `draftcraft.exe` is the one named under `App Paths`) or by the +`.deb` offers the release page too: the new installer or package replaces it, keeping Windows' +and the package manager's record of the installed version right. + +### Opening `.dxf` and `.dwg` files + +| System | How DraftCraft is registered | +| --- | --- | +| Windows (MSI) | `DraftCraft.Drawing` ProgId, `OpenWithProgids` of `.dxf`/`.dwg`, `Applications\draftcraft.exe\SupportedTypes`, and `Capabilities` in `RegisteredApplications` (`packaging/windows/draftcraft.wxs`), in the install's own context. It appears in **Open with** and in **Settings › Apps › Default apps**; Windows lets only the user make it the default. The zip registers nothing. | +| macOS | `CFBundleDocumentTypes` and `UTImportedTypeDeclarations` in `packaging/macos/Info.plist.in`, with `LSHandlerRank` `Alternate`: Finder lists it in **Open With**, and **Get Info › Open with › Change All…** makes it the default. | +| Linux (`.deb`) | `MimeType=` in `dev.skryx.draftcraft.desktop` and the `image/vnd.dxf`/`image/vnd.dwg` types in `dev.skryx.draftcraft.mime.xml`; the package's scripts refresh the desktop, MIME and icon caches. The AppImage registers nothing. | + +The app opens the files it is given on its command line (`draftcraft [files…]`), which is how Windows +and Linux hand them over. macOS hands them over as an Apple event instead, which the app does not +handle yet, so on macOS a file opened from Finder starts DraftCraft without loading it. + ## 3. A macOS build on your own Mac The release doesn't need it, but the same script makes the DMG locally (Apple-silicon Mac with Xcode): @@ -54,15 +80,38 @@ CRAFT_FONTS_DIR="$PWD/../craft-fonts" packaging/macos/package.sh --arch aarch64 ``` It writes `dist/release/draftcraft--macos-aarch64.dmg` and -`draftcraft-cli--macos-aarch64.zip`. `--arch universal` also builds for Intel Macs (it needs -`rustup target add x86_64-apple-darwin`). +`draftcraft-cli--macos-aarch64.zip`. `--arch x86_64` builds the Intel package the release +ships, and `--arch universal` one app for both; both need `rustup target add x86_64-apple-darwin`. + +### The DMG window + +The DMG opens as a window with its own background (logo, blueprint grid, a card behind the app and +one behind Applications, a compass arc between them). `package.sh` only copies three committed files +from `packaging/macos/dmg/`: `background.png` and `background@2x.png` (joined into the volume's +`/.background/background.tiff`) and `DS_Store` (window size, icon places, the background). After +changing the art (`background.swift`) or the layout, remake them on a Mac and commit them: + +```bash +pip install ds_store==1.3.1 mac_alias==2.2.2 # or PYTHON= +packaging/macos/dmg/make-layout.sh +``` + +The background is found by its path on a volume named `DraftCraft`, so keep that volume name. ## Signing The builds are not signed with a paid certificate: macOS builds are signed ad hoc and Windows builds -are not signed, so users see the warnings the README explains. `packaging/macos/package.sh` signs and -notarizes with a Developer ID when `MACOS_SIGN_IDENTITY`, `APPLE_ID`, `APPLE_PASSWORD` and -`APPLE_TEAM_ID` are set (see the top of the script). +are not signed, so users see the warnings the README explains. Both are ready for certificates; adding +these repository secrets is enough, no workflow change: + +| Secret | Effect | +| --- | --- | +| `APPLE_CERTIFICATE` (base64 Developer ID Application `.p12`), `APPLE_CERTIFICATE_PASSWORD` | `packaging/macos/import-cert.sh` imports it, and `package.sh` signs the app, CLI and DMG with it (hardened runtime, `entitlements.plist`) | +| `APPLE_ID`, `APPLE_PASSWORD` (app-specific password), `APPLE_TEAM_ID` | with the certificate, `package.sh` notarizes and staples the app and the DMG | +| `WINDOWS_CERTIFICATE` (base64 `.pfx`), `WINDOWS_CERTIFICATE_PASSWORD` | `packaging/windows/sign.ps1` signs the exes and the MSI | + +Locally, `package.sh` reads `MACOS_SIGN_IDENTITY`, `APPLE_ID`, `APPLE_PASSWORD` and `APPLE_TEAM_ID` +(see the top of the script). ## Release notes diff --git a/packaging/linux/package.sh b/packaging/linux/package.sh index d38cd555..db4c8bad 100755 --- a/packaging/linux/package.sh +++ b/packaging/linux/package.sh @@ -7,7 +7,11 @@ # $DIST/draftcraft--linux-.rpm Fedora, openSUSE, RHEL, ... # $DIST/draftcraft--linux-.tar.gz plain FHS-style tree (bin/, share/) # -# Usage: packaging/linux/package.sh [--skip-build] [--formats "appimage deb rpm tar"] +# Usage: packaging/linux/package.sh [--skip-build] [--target TRIPLE] [--formats "appimage deb rpm tar"] +# +# --target packages a native build made with `cargo build --target TRIPLE` (the release workflow +# builds that way); with --skip-build the binaries and the man-and-completions example must already +# be in $CARGO_TARGET_DIR/TRIPLE/release. # # Needs: cargo; nfpm for deb/rpm (https://nfpm.goreleaser.com); appimagetool for the AppImage # (downloaded into $CARGO_TARGET_DIR if missing). Build on an old distro (CI: Ubuntu 22.04, @@ -21,17 +25,23 @@ APP_ID=dev.skryx.draftcraft SKIP_BUILD=0 FORMATS="appimage deb rpm tar" +NATIVE_TARGET="" while [[ $# -gt 0 ]]; do case "$1" in --skip-build) SKIP_BUILD=1; shift ;; + --target) NATIVE_TARGET="$2"; shift 2 ;; --formats) FORMATS="$2"; shift 2 ;; - -h | --help) sed -n '2,17p' "$0"; exit 0 ;; + -h | --help) sed -n '2,21p' "$0"; exit 0 ;; *) echo "unknown argument: $1" >&2; exit 2 ;; esac done # Cross builds (CI's riscv64 job) set CROSS_ARCH, CROSS_TARGET (the Rust target), CROSS_COMPILE # (the binutils prefix, for strip) and optionally EMULATOR (e.g. qemu-riscv64, for the smoke test). +if [[ -n "$NATIVE_TARGET" ]] && [[ -n "${CROSS_TARGET:-}" ]]; then + echo "error: --target is for native builds; cross builds set CROSS_TARGET" >&2 + exit 2 +fi ARCH="${CROSS_ARCH:-$(uname -m)}" case "$ARCH" in riscv64) DEB_ARCH=riscv64 ;; @@ -52,11 +62,14 @@ if [[ "$SKIP_BUILD" = 0 ]]; then (cd "$ROOT" && cargo build --release --locked -p draftcraft -p draftcraft-cli --target "$CROSS_TARGET") (cd "$ROOT" && cargo build --release --locked -p draftcraft-cli --example man-and-completions --target "$CROSS_TARGET") else - (cd "$ROOT" && cargo build --release --locked -p draftcraft -p draftcraft-cli) - (cd "$ROOT" && cargo build --release --locked -p draftcraft-cli --example man-and-completions) + target=() + [[ -n "$NATIVE_TARGET" ]] && target=(--target "$NATIVE_TARGET") + (cd "$ROOT" && cargo build --release --locked -p draftcraft -p draftcraft-cli ${target[@]+"${target[@]}"}) + (cd "$ROOT" && cargo build --release --locked -p draftcraft-cli --example man-and-completions ${target[@]+"${target[@]}"}) fi fi -BIN="$CARGO_TARGET_DIR/${CROSS_TARGET:+$CROSS_TARGET/}release" +TRIPLE="${CROSS_TARGET:-$NATIVE_TARGET}" +BIN="$CARGO_TARGET_DIR/${TRIPLE:+$TRIPLE/}release" WORK="$CARGO_TARGET_DIR/linux-package" STAGE="$WORK/root" rm -rf "$WORK" diff --git a/packaging/macos/dmg/DS_Store b/packaging/macos/dmg/DS_Store new file mode 100644 index 00000000..98ba995b Binary files /dev/null and b/packaging/macos/dmg/DS_Store differ diff --git a/packaging/macos/dmg/background.png b/packaging/macos/dmg/background.png new file mode 100644 index 00000000..cb19d097 Binary files /dev/null and b/packaging/macos/dmg/background.png differ diff --git a/packaging/macos/dmg/background.swift b/packaging/macos/dmg/background.swift new file mode 100644 index 00000000..b9a6b517 --- /dev/null +++ b/packaging/macos/dmg/background.swift @@ -0,0 +1,163 @@ +// Draws the DMG window's background: packaging/macos/dmg/background.png (660 × 420 pt) and +// background@2x.png, which package.sh joins into the volume's background.tiff. Our own art: the DraftCraft +// logo (docs/brand/draftcraft-logo.svg), a light blueprint grid, two cards behind the app and the +// Applications link that Finder draws on top, and a compass arc from one to the other. +// +// swift packaging/macos/dmg/background.swift +// +// holds Inter-Medium.ttf and Inter-Regular.ttf (Inter, SIL OFL 1.1, +// https://github.com/rsms/inter): only the rendered text ends up in the image. Keep the geometry in +// step with make-layout.sh (window size, icon centres). + +import AppKit +import CoreText + +let args = CommandLine.arguments +guard args.count == 3 else { + FileHandle.standardError.write("usage: swift background.swift \n".data(using: .utf8)!) + exit(2) +} +let root = URL(fileURLWithPath: #filePath).deletingLastPathComponent().appendingPathComponent("../../..").standardized +let fontDir = URL(fileURLWithPath: args[1]) +let outDir = URL(fileURLWithPath: args[2]) + +for name in ["Inter-Medium.ttf", "Inter-Regular.ttf"] { + var error: Unmanaged? + if !CTFontManagerRegisterFontsForURL(fontDir.appendingPathComponent(name) as CFURL, .process, &error) { + FileHandle.standardError.write("can't load \(name)\n".data(using: .utf8)!) + exit(1) + } +} + +// Geometry in points; make-layout.sh puts the icons at these centres. +let size = NSSize(width: 660, height: 420) +let appCentre = NSPoint(x: 170, y: 236) +let appsCentre = NSPoint(x: 490, y: 236) +let card = NSSize(width: 184, height: 184) +let cardCentreY: CGFloat = 250 + +// The brand's blueprint palette. +func rgb(_ hex: UInt32, _ alpha: CGFloat = 1) -> NSColor { + NSColor(srgbRed: CGFloat((hex >> 16) & 0xff) / 255, green: CGFloat((hex >> 8) & 0xff) / 255, blue: CGFloat(hex & 0xff) / 255, alpha: alpha) +} +let navy = rgb(0x0e3463) +let accent = rgb(0x3ea6e8) + +func draw(scale: CGFloat) -> NSBitmapImageRep { + let rep = NSBitmapImageRep(bitmapDataPlanes: nil, pixelsWide: Int(size.width * scale), pixelsHigh: Int(size.height * scale), + bitsPerSample: 8, samplesPerPixel: 4, hasAlpha: true, isPlanar: false, + colorSpaceName: .deviceRGB, bytesPerRow: 0, bitsPerPixel: 0)! + rep.size = size + NSGraphicsContext.saveGraphicsState() + let context = NSGraphicsContext(bitmapImageRep: rep)! + NSGraphicsContext.current = context + // Top-left origin, like Finder's icon positions. + let flip = NSAffineTransform() + flip.translateX(by: 0, yBy: size.height) + flip.scaleX(by: 1, yBy: -1) + flip.concat() + + // Paper: a soft blue-white wash with a glow behind the title. + NSGradient(colors: [rgb(0xf7fbff), rgb(0xe3eefa)])!.draw(in: NSRect(origin: .zero, size: size), angle: 90) + NSGradient(colors: [rgb(0xffffff, 0.85), rgb(0xffffff, 0)])! + .draw(fromCenter: NSPoint(x: 330, y: 70), radius: 0, toCenter: NSPoint(x: 330, y: 70), radius: 300, options: []) + + // Drafting grid: minor lines every 20 pt, major every 100 pt. + for (step, alpha) in [(CGFloat(20), CGFloat(0.07)), (100, 0.10)] { + let path = NSBezierPath() + var x: CGFloat = 30 + while x < size.width { path.move(to: NSPoint(x: x, y: 0)); path.line(to: NSPoint(x: x, y: size.height)); x += step } + var y: CGFloat = 10 + while y < size.height { path.move(to: NSPoint(x: 0, y: y)); path.line(to: NSPoint(x: size.width, y: y)); y += step } + path.lineWidth = 1 / scale + accent.withAlphaComponent(alpha).setStroke() + path.stroke() + } + + // Images and text draw upright: undo the flip about the horizontal line at `y`. + func upright(at y: CGFloat, _ body: () -> Void) { + NSGraphicsContext.saveGraphicsState() + let unflip = NSAffineTransform() + unflip.translateX(by: 0, yBy: y * 2) + unflip.scaleX(by: 1, yBy: -1) + unflip.concat() + body() + NSGraphicsContext.restoreGraphicsState() + } + + // Logo, centred at the top. + let logo = NSImage(contentsOf: root.appendingPathComponent("docs/brand/draftcraft-logo.svg"))! + let logoHeight: CGFloat = 50 + let logoWidth = logoHeight * logo.size.width / logo.size.height + let logoRect = NSRect(x: (size.width - logoWidth) / 2, y: 34, width: logoWidth, height: logoHeight) + upright(at: logoRect.midY) { logo.draw(in: logoRect) } + + func text(_ string: String, font: String, size pt: CGFloat, color: NSColor, centreY: CGFloat) { + let attributes: [NSAttributedString.Key: Any] = [.font: NSFont(name: font, size: pt)!, .foregroundColor: color] + let s = NSAttributedString(string: string, attributes: attributes) + let bounds = s.size() + upright(at: centreY) { s.draw(at: NSPoint(x: (size.width - bounds.width) / 2, y: centreY - bounds.height / 2)) } + } + text("Drag DraftCraft into Applications to install", font: "Inter-Medium", size: 15, color: rgb(0x3d5a7d), centreY: 116) + + // Cards behind the two icons (Finder draws the icons and their labels on top). + for centre in [appCentre, appsCentre] { + let rect = NSRect(x: centre.x - card.width / 2, y: cardCentreY - card.height / 2, width: card.width, height: card.height) + let path = NSBezierPath(roundedRect: rect, xRadius: 40, yRadius: 40) + NSGraphicsContext.saveGraphicsState() + let shadow = NSShadow() + shadow.shadowColor = navy.withAlphaComponent(0.12) + shadow.shadowBlurRadius = 22 + shadow.shadowOffset = NSSize(width: 0, height: -8) + shadow.set() + rgb(0xffffff, 0.72).setFill() + path.fill() + NSGraphicsContext.restoreGraphicsState() + path.lineWidth = 1.5 + rgb(0xffffff, 0.95).setStroke() + path.stroke() + } + + // A compass arc from the app to Applications, drawn in dots, ending in an arrowhead. + let from = NSPoint(x: appCentre.x + card.width / 2 + 18, y: 252) + let to = NSPoint(x: appsCentre.x - card.width / 2 - 18, y: 252) + let control1 = NSPoint(x: from.x + 16, y: from.y - 46) + let control2 = NSPoint(x: to.x - 16, y: to.y - 46) + let arc = NSBezierPath() + arc.move(to: from) + arc.curve(to: to, controlPoint1: control1, controlPoint2: control2) + arc.lineWidth = 3.2 + arc.lineCapStyle = .round + arc.setLineDash([0.01, 9], count: 2, phase: 0) + accent.setStroke() + arc.stroke() + // Arrowhead along the curve's end tangent (from the last control point to the end). + let (dx, dy) = (to.x - control2.x, to.y - control2.y) + let length = (dx * dx + dy * dy).squareRoot() + let (ux, uy) = (dx / length, dy / length) + let (back, spread): (CGFloat, CGFloat) = (12, 8) + let head = NSBezierPath() + head.move(to: NSPoint(x: to.x - ux * back - uy * spread, y: to.y - uy * back + ux * spread)) + head.line(to: to) + head.line(to: NSPoint(x: to.x - ux * back + uy * spread, y: to.y - uy * back - ux * spread)) + head.lineWidth = 3.2 + head.lineCapStyle = .round + head.lineJoinStyle = .round + head.stroke() + // The compass point the arc starts from. + let pivot = NSBezierPath(ovalIn: NSRect(x: from.x - 4, y: from.y - 4, width: 8, height: 8)) + navy.withAlphaComponent(0.85).setFill() + pivot.fill() + + text("Free software · MIT or Apache 2.0 · github.com/SkryxDev/DraftCraft", font: "Inter-Regular", size: 12, color: rgb(0x7389a3), centreY: 374) + + NSGraphicsContext.restoreGraphicsState() + return rep +} + +try FileManager.default.createDirectory(at: outDir, withIntermediateDirectories: true) +for (scale, name) in [(CGFloat(1), "background.png"), (2, "background@2x.png")] { + let data = draw(scale: scale).representation(using: .png, properties: [:])! + try data.write(to: outDir.appendingPathComponent(name)) +} +print("wrote \(outDir.path)/background.png and background@2x.png") diff --git a/packaging/macos/dmg/background@2x.png b/packaging/macos/dmg/background@2x.png new file mode 100644 index 00000000..05a2693f Binary files /dev/null and b/packaging/macos/dmg/background@2x.png differ diff --git a/packaging/macos/dmg/make-layout.sh b/packaging/macos/dmg/make-layout.sh new file mode 100755 index 00000000..6e048ccc --- /dev/null +++ b/packaging/macos/dmg/make-layout.sh @@ -0,0 +1,108 @@ +#!/usr/bin/env bash +# Remakes the DMG window's look, which packaging/macos/package.sh copies into every disk image: +# +# packaging/macos/dmg/background.png the window background (from background.swift), and +# packaging/macos/dmg/background@2x.png its Retina version; package.sh joins them into +# /.background/background.tiff on the volume +# packaging/macos/dmg/DS_Store Finder's view settings for the volume: window size, no +# toolbar or sidebar, 128 pt icons at the cards' centres, and +# the background (an alias to /.background/background.tiff +# on a volume named DraftCraft) +# +# Run it on a Mac after changing the art or the layout, then commit both files. Releases don't run +# it: they only copy the files, so building a DMG needs no Python and mounts nothing. +# +# packaging/macos/dmg/make-layout.sh +# +# Needs Xcode's swift and Python 3 with ds_store 1.3.1 and mac_alias 2.2.2 (dmgbuild's libraries; +# `pip install ds_store==1.3.1 mac_alias==2.2.2`, or PYTHON=). +set -euo pipefail +HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +FONTS="${1:?usage: make-layout.sh }" +PYTHON="${PYTHON:-python3}" + +# Keep in step with background.swift: window size and icon centres, in points. +WIDTH=660 +HEIGHT=420 +# Finder counts the title bar in the window height. +TITLE_BAR=28 +APP_X=170 +APPS_X=490 +ICON_Y=236 + +WORK="$(mktemp -d)" +cleanup() { + if [[ -n "${DEVICE:-}" ]]; then hdiutil detach -quiet "$DEVICE" || hdiutil detach -quiet -force "$DEVICE" || true; fi + rm -rf "$WORK" +} +trap cleanup EXIT + +swift "$HERE/background.swift" "$FONTS" "$HERE" + +# A scratch volume with the same name and layout as the release DMG, so the alias inside the view +# settings points where the background will be. +hdiutil create -quiet -size 8m -fs HFS+ -volname DraftCraft -type UDIF -layout NONE "$WORK/layout.dmg" +MOUNT="$WORK/mnt" +mkdir -p "$MOUNT" +DEVICE="$(hdiutil attach "$WORK/layout.dmg" -nobrowse -noautoopen -noverify -mountpoint "$MOUNT" | awk 'NR==1{print $1}')" +mkdir -p "$MOUNT/.background" "$MOUNT/DraftCraft.app" +# One TIFF with both resolutions, as package.sh makes it: Finder picks the 2x image on Retina displays. +tiffutil -cathidpicheck "$HERE/background.png" "$HERE/background@2x.png" -out "$MOUNT/.background/background.tiff" +ln -s /Applications "$MOUNT/Applications" + +"$PYTHON" - "$MOUNT" "$WIDTH" "$((HEIGHT + TITLE_BAR))" "$APP_X" "$APPS_X" "$ICON_Y" <<'PY' +import sys +from ds_store import DSStore +from mac_alias import Alias + +mount, width, height, app_x, apps_x, icon_y = sys.argv[1], *map(int, sys.argv[2:]) +alias = Alias.for_file(f"{mount}/.background/background.tiff") +# for_file records where the scratch volume is mounted here (a temporary folder). Point the alias at +# the release volume instead: Finder finds the background by these paths, since the release image is a +# new volume with its own creation date. The file ids are the ones `hdiutil makehybrid` gives +# /.background and its TIFF on the release volume (package.sh stages the same top-level entries). +alias.volume.posix_path = "/Volumes/DraftCraft" +alias.target.posix_path = "/.background/background.tiff" +alias.target.carbon_path = b"DraftCraft:.background:\x00background.tiff" +alias.target.folder_cnid = 20 +alias.target.cnid = 22 +alias.target.cnid_path = (20,) +with DSStore.open(f"{mount}/.DS_Store", "w+") as store: + store["."]["bwsp"] = { + "WindowBounds": f"{{{{200, 160}}, {{{width}, {height}}}}}", + "ShowStatusBar": False, + "ShowToolbar": False, + "ShowTabView": False, + "ShowPathbar": False, + "ShowSidebar": False, + "ContainerShowSidebar": False, + "PreviewPaneVisibility": False, + "SidebarWidth": 0, + } + store["."]["icvp"] = { + "viewOptionsVersion": 1, + "backgroundType": 2, + "backgroundImageAlias": alias.to_bytes(), + "backgroundColorRed": 1.0, + "backgroundColorGreen": 1.0, + "backgroundColorBlue": 1.0, + "arrangeBy": "none", + "gridOffsetX": 0.0, + "gridOffsetY": 0.0, + "gridSpacing": 100.0, + "iconSize": 128.0, + "textSize": 13.0, + "labelOnBottom": True, + "showIconPreview": False, + "showItemInfo": False, + "scrollPositionX": 0.0, + "scrollPositionY": 0.0, + } + store["."]["vSrn"] = ("long", 1) + store["."]["icvl"] = ("type", b"icnv") + store["DraftCraft.app"]["Iloc"] = (app_x, icon_y) + store["Applications"]["Iloc"] = (apps_x, icon_y) +PY + +cp "$MOUNT/.DS_Store" "$HERE/DS_Store" +echo "wrote $HERE/background.png, background@2x.png and DS_Store" diff --git a/packaging/macos/package.sh b/packaging/macos/package.sh index 126c858c..8d7ea406 100755 --- a/packaging/macos/package.sh +++ b/packaging/macos/package.sh @@ -159,6 +159,14 @@ STAGE="$WORK/dmg" mkdir -p "$STAGE" ditto "$APP" "$STAGE/DraftCraft.app" ln -s /Applications "$STAGE/Applications" +# The window's look (packaging/macos/dmg/make-layout.sh makes these): background, size and icon +# places. Finder reads them from the volume; the background folder is hidden. +mkdir -p "$STAGE/.background" +tiffutil -cathidpicheck "$HERE/dmg/background.png" "$HERE/dmg/background@2x.png" -out "$STAGE/.background/background.tiff" +cp "$HERE/dmg/DS_Store" "$STAGE/.DS_Store" +# The volume's own icon, shown by the window title and on the desktop. +cp "$ROOT/assets/app-icon/draftcraft.icns" "$STAGE/.VolumeIcon.icns" +SetFile -a C "$STAGE" rm -f "$DMG" "$WORK/raw.dmg" # makehybrid + convert builds the image without attaching a device, unlike `create -srcfolder`, # which is flaky on CI runners ("Resource busy") and hangs in sandboxed sessions. @@ -187,6 +195,18 @@ ditto -c -k --keepParent "$CLI_DIR" "$CLI_ZIP" # A bare Mach-O can't carry a stapled ticket; Gatekeeper looks the notarization up online. if [[ "$NOTARIZE" = 1 ]]; then notarize "$CLI_ZIP"; fi -"$WORK/bin/draftcraft-cli" --version +# Smoke test, when this Mac can run the build: its own processor, or an Intel build through Rosetta. +runs_here() { + local archs host + archs=" $(lipo -archs "$1") " + host="$(uname -m)" + [[ "$archs" == *" $host "* ]] && return 0 + [[ "$host" == arm64 ]] && [[ "$archs" == *" x86_64 "* ]] && /usr/bin/arch -x86_64 /usr/bin/true 2>/dev/null +} +if runs_here "$WORK/bin/draftcraft-cli"; then + "$WORK/bin/draftcraft-cli" --version +else + warn "skipping draftcraft-cli --version: this $(uname -m) Mac can't run the $ARCH build (Rosetta missing?)" +fi echo "==> done" ls -lh "$DMG" "$CLI_ZIP" diff --git a/packaging/windows/check-install-policy.ps1 b/packaging/windows/check-install-policy.ps1 index dd3bb82d..bb506246 100644 --- a/packaging/windows/check-install-policy.ps1 +++ b/packaging/windows/check-install-policy.ps1 @@ -32,6 +32,11 @@ function Set-SessionProperty($Session, [string] $Name, [string] $Value) { function Get-SessionProperty($Session, [string] $Name) { $Session.GetType().InvokeMember('Property', 'GetProperty', $null, $Session, @($Name)) } +# The long name in a Directory table's DefaultDir: "target[:source]", each "short|long" when WiX +# generated an 8.3 name (as it does for "DraftCraft"). +function Get-LongName([string] $DefaultDir) { + (($DefaultDir -split ':')[0] -split '\|')[-1] +} function Get-PackageTemplate($Database) { # Summary information property 7 is the platform: "Intel;1033", "x64;1033" or "Arm64;1033". $summary = $Database.GetType().InvokeMember('SummaryInformation', 'GetProperty', $null, $Database, @(0)) @@ -55,7 +60,7 @@ try { if ($properties['UpgradeCode'].Trim('{}') -ne $policy.upgradeCode) { throw 'Launcher upgrade identity changed.' } $dirs = @{} foreach ($row in (Read-Rows $database 'SELECT `Directory`, `Directory_Parent`, `DefaultDir` FROM `Directory`' 3)) { $dirs[$row[0]] = @($row[1],$row[2]) } - if ($dirs['INSTALLFOLDER'][0] -ne 'CraftSuiteFolder' -or $dirs['CraftSuiteFolder'][1] -ne 'DraftCraft' -or + if ($dirs['INSTALLFOLDER'][0] -ne 'CraftSuiteFolder' -or (Get-LongName $dirs['CraftSuiteFolder'][1]) -ne 'DraftCraft' -or $dirs['CraftSuiteFolder'][0] -ne 'LocalProgramsFolder' -or $dirs['LocalProgramsFolder'][0] -ne 'LocalAppDataFolder') { throw 'Launcher new-install folder must be under the per-user DraftCraft suite root.' } @@ -88,7 +93,9 @@ try { $directories[$row[0]] = @($row[1], $row[2]) } if ($directories['INSTALLFOLDER'][0] -ne 'CraftSuiteFolder' -or - $directories['CraftSuiteFolder'][1] -ne 'DraftCraft') { throw 'Expected the app under the DraftCraft suite folder.' } + (Get-LongName $directories['CraftSuiteFolder'][1]) -ne 'DraftCraft') { + throw "Expected the app under the DraftCraft suite folder (INSTALLFOLDER: $($directories['INSTALLFOLDER'] -join ', '); CraftSuiteFolder: $($directories['CraftSuiteFolder'] -join ', '))." + } $programs = $directories['CraftSuiteFolder'][0] if ($programs -eq 'ProgramFiles6432Folder') { $programs = $directories[$programs][0] } if ($programs -notin 'ProgramFilesFolder', 'ProgramFiles64Folder') { diff --git a/packaging/windows/draftcraft.wxs b/packaging/windows/draftcraft.wxs index b517d89c..b79869da 100644 --- a/packaging/windows/draftcraft.wxs +++ b/packaging/windows/draftcraft.wxs @@ -62,10 +62,25 @@ + + + + + + + + + + + + + diff --git a/packaging/windows/install-policy.json b/packaging/windows/install-policy.json index cf957cb4..89723cdc 100644 --- a/packaging/windows/install-policy.json +++ b/packaging/windows/install-policy.json @@ -45,6 +45,66 @@ "", "\"[#DraftcraftExe]\" \"%1\"" ], + [ + "-1", + "Software\\Classes\\Applications\\draftcraft.exe", + "FriendlyAppName", + "DraftCraft" + ], + [ + "-1", + "Software\\Classes\\Applications\\draftcraft.exe\\SupportedTypes", + ".dxf", + "" + ], + [ + "-1", + "Software\\Classes\\Applications\\draftcraft.exe\\SupportedTypes", + ".dwg", + "" + ], + [ + "-1", + "Software\\Classes\\DraftCraft.Drawing", + "", + "DraftCraft drawing" + ], + [ + "-1", + "Software\\Classes\\DraftCraft.Drawing\\DefaultIcon", + "", + "[#DraftcraftExe],0" + ], + [ + "-1", + "Software\\DraftCraft\\Capabilities", + "ApplicationName", + "DraftCraft" + ], + [ + "-1", + "Software\\DraftCraft\\Capabilities", + "ApplicationDescription", + "Computer-aided design and drafting" + ], + [ + "-1", + "Software\\DraftCraft\\Capabilities\\FileAssociations", + ".dxf", + "DraftCraft.Drawing" + ], + [ + "-1", + "Software\\DraftCraft\\Capabilities\\FileAssociations", + ".dwg", + "DraftCraft.Drawing" + ], + [ + "-1", + "Software\\RegisteredApplications", + "DraftCraft", + "Software\\DraftCraft\\Capabilities" + ], [ "-1", "Software\\Skryx Dev\\DraftCraft",