Skip to content

Commit

Permalink
Add rattler-build recipe for Zig-built conda-launchers (#7)
Browse files Browse the repository at this point in the history
Co-authored-by: jaimergp <[email protected]>
  • Loading branch information
chawyehsu and jaimergp authored Nov 18, 2024
1 parent d23e557 commit 4a9f48c
Show file tree
Hide file tree
Showing 9 changed files with 478 additions and 2 deletions.
44 changes: 43 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ concurrency:
cancel-in-progress: true

jobs:
build_recipe:
conda_build_recipe:
name: Build conda recipe (${{ matrix.subdir }})
runs-on: ${{ matrix.os }}
strategy:
Expand Down Expand Up @@ -80,3 +80,45 @@ jobs:
echo "Use this command to try out the build:"
echo " conda install -c ${ANACONDA_ORG_CHANNEL}/label/${ANACONDA_ORG_LABEL} conda-launchers"
rattler_build_recipe:
name: Rattler build recipe
runs-on: windows-latest
steps:
- name: Checkout Source
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Setup Pixi
uses: prefix-dev/[email protected]
with:
cache: true

- name: Run Build
shell: pwsh
run: pixi run build

- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: conda-launchers-zig-builds
path: |
./output/noarch/conda-launchers*.conda
- name: Upload to Anaconda
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
env:
ANACONDA_OWNER: conda-canary
ANACONDA_CHANNEL: conda-launchers-zig_dev
ANACONDA_API_KEY: ${{ secrets.ANACONDA_ORG_CONDA_CANARY_TOKEN }}
shell: pwsh
run: |
if (-not $env:ANACONDA_API_KEY -or $env:ANACONDA_API_KEY -eq '') {
Write-Error "ANACONDA_API_KEY is not set."
exit 1
}
foreach ($file in Get-ChildItem -Path "./output/noarch/conda-launchers*.conda") {
Write-Host "Uploading $($file.Name)"
pixi run upload "$file"
}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,9 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

!launcher.manifest
# pixi environment
.pixi/
# rattler-build output
output/
126 changes: 126 additions & 0 deletions pixi.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions pixi.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[project]
name = "conda-launchers"
version = "0.0.0"
description = "Conda launchers for Windows"
channels = ["conda-forge"]
platforms = ["win-64"]
license = "BSD-3-Clause"

[tasks]
build = "rattler-build build --recipe recipe-zig --log-style plain --skip-existing all -c conda-forge"
upload = "rattler-build upload anaconda --log-style plain"

[dependencies]
rattler-build = ">=0.29.0,<0.30"

[target.win-64.dependencies]
m2-patch = ">=2.7.6.2,<3"
50 changes: 50 additions & 0 deletions recipe-zig/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
setlocal EnableDelayedExpansion

@rem no-op for conda-launchers metapackage
if %PKG_NAME% == conda-launchers (exit 0)

@rem rename patched source file to be used for building
move /Y launcher.c.orig launcher.c

if %PKG_NAME% == conda-launchers_win-32 (
set ZIG_TARGET=x86-windows-gnu
set EXE_TARGET=32
)

if %PKG_NAME% == conda-launchers_win-64 (
set ZIG_TARGET=x86_64-windows-gnu
set EXE_TARGET=64
)

if %PKG_NAME% == conda-launchers_win-arm64 (
set ZIG_TARGET=aarch64-windows-gnu
set EXE_TARGET=arm64
)

@rem build cli launcher
zig build -Doptimize=ReleaseSmall -Dtarget=%ZIG_TARGET% -Dgui=false --prefix-exe-dir "%PREFIX%\Scripts"
if %ERRORLEVEL% neq 0 exit 1

@rem build gui launcher
zig build -Doptimize=ReleaseSmall -Dtarget=%ZIG_TARGET% -Dgui=true --prefix-exe-dir "%PREFIX%\Scripts"
if %ERRORLEVEL% neq 0 exit 1

@rem install launcher scripts
cd "%PREFIX%\Scripts"
(
echo print^("cli-%EXE_TARGET%.exe successfully launched the accompanying Python script"^)
)> "cli-%EXE_TARGET%-script.py"

if %ERRORLEVEL% neq 0 exit 1

(
echo import tkinter as tk
echo root = tk.Tk^(^)
echo text = tk.Label^(root, text ="Hello and Bye!"^)
echo text.pack^(^)
echo root.geometry^("150x100"^)
echo root.after^(1000, lambda: root.destroy^(^)^)
echo root.mainloop^(^)
)> "gui-%EXE_TARGET%-script.pyw"

if %ERRORLEVEL% neq 0 exit 1
Loading

0 comments on commit 4a9f48c

Please sign in to comment.