create-package.md

We need to create a new AUR package (or multiple) from scratch.

Code style:

  • Language(s): PKGBUILD is bash; .install (if necessary) is POSIX-sh–compatible functions
  • Indent 2 spaces; UTF-8; LF endings; no trailing whitespace
  • Strings: single quotes for literals; double quotes when expanding vars
  • Functions: prepare(), build(), check(), package(); only define needed ones
  • No sudo, networking, or user config in build/package functions
  • Use install -Dm755 for binaries; set exact modes explicitly
  • Checksums: keep hashes in sync with sources
  • Keep .SRCINFO in lockstep with PKGBUILD; don't commit build artifacts

During creation, follow this strict workflow. If a planning or todo tool is available, fill it out in detail with these steps; you might get interrupted and have to pick up where you left off based on that todo/planning tool's output.

  1. List the contents of your current working directory to see what I've already done.
    • If you see text files, read them.
    • If you see directories, list their contents.
      • If by its contents, it seems like the repository of the project we're packaging, ignore it for now.
    • If there are sub-directories of your current working directory with suffixes like -bin or -git, we're actually going to be creating multiple AUR packages for the same piece of software.
      • -git packages clone the primary branch (main, master, trunk, etc.) and build and install the software from that source. We do not specify versions for these packages; updpkgsums determines the version and edits the PKGBUILD.
      • -bin packages download the project-built and project-distributed binary and install that.
      • Packages without a suffix download the nearest thing to a release archive we can find and build/install that source.
    • There are no sub-directories of your current working directory, we're only creating one package. Look to your current working directory to determine whether we're creating a suffix-less package, or one with -git or -bin.
  2. Ask me for the package name (provides=), description (description=), and license (license=()), and the license path inside the project repo (for installing). Then for each of the non-git package types, ask me for its current version and the source URL.
    • For -git packages, you must prefix the source URL with git+https://.... Ask me which branch to check out. Include the following function to support versioning.
      pkgver() {
        cd "$pkgname" || exit
        ( set -o pipefail
          git describe --long 2>/dev/null | sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
          printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
        )
      }
      
    • For -bin packages, use bin-name-$pkgver:https://... in the source, then install bin-name-$pkgver as bin-name. Additionally, we'll need to obtain the license from the original repository. If the source is GitHub, the raw URL is https://raw.githubusercontent.com/bmf-san/ggc/refs/tags/{TAG}/LICENSE. If the source is not GitHub, ask me for the raw URL to the tagged LICENSE file.
  3. For each package we're creating, write a new PKGBUILD to that directory with the details above. The Maintainer comment at the top should be Amolith <amolith@secluded.site>. If multiple packages, make sure to include conflicts=() so one can't get installed alongside the other. Make sure packages with -git or -bin use the suffix-less package name in the provides field. Use b2sums.
  4. Ask me to find and relay the build system/installation methods recommended by the project. This might be cargo for Rust projects, go for Go, etc.
  5. Once I've relayed the project's instructions, adapt those for each of the packages depending on project language and update the PKGBUILDs' build(), check(), package(), etc. functions.
    • Rust
      • -git and -bin are pretty self-explanatory for Rust. For suffix-less packages, download the version crate from cargo's API as a .crate file and build it using cargo.
    • Go
      • To keep all Go modules in the package build environment, use
        prepare() {
          cd "${pkgname}-${pkgver}"
          export GOPATH="${srcdir}"
          go mod download -modcacherw
        }
        
      • If the build process bakes in version information, use the following in the build() function.
        go build \
            -trimpath \
            -buildmode=pie \
            -mod=readonly \
            -modcacherw \
            -ldflags "-linkmode external -extldflags \"${LDFLAGS}\"" \
            "$pkgname" main.go # or ./cmd or ...
        
        If the build process does not bake version info in, use this.
        export CGO_CPPFLAGS="${CPPFLAGS}"
        export CGO_CFLAGS="${CFLAGS}"
        export CGO_CXXFLAGS="${CXXFLAGS}"
        export CGO_LDFLAGS="${LDFLAGS}"
        export GOFLAGS="-buildmode=pie -trimpath -ldflags=-linkmode=external -mod=readonly -modcacherw"
        
  6. Consider the diagnostics and present all issues to me, whether you think they're relevant or not. Include reasoning why those issues are relevant, or why they're not. We'll work on any genuine issues until they're resolved before proceeding.
  7. Update checksums in each package directory with updpkgsums
  8. Install dependencies and build/install the package(s) by giving me a code block of makepkg -Ccsi commands I can copy/paste. If there are multiple packages, include cd prior to makepkg. We'll work on any issues that arise during this step until they're resolved.
    • I must run makepkg commands because you're prohibited from interacting with it.
  9. After I build the packages, run namcap on ./package-name-*.pkg.tar.zst to lint them. Again, report all the issues to me and we'll work on them before continuing.
  10. Generate each package's .SRCINFO by, again, giving me a series makepkg --printsrcinfo > .SRCINFO. If just one package, no cd is necessary. Just makepkg.
  11. If the PKGBUILDs and .SRCINFOs are the only files you've created during this session, enter each package directory, then git add and git commit them. If there are other files you've modified that are tracked by git in those package directory, please show me the diff and ask which you should commit. Create a .gitignore in each package repo that lists everything in the dir we have not committed. Use appropriate globbing.
  12. Clean all artefacts with git clean -fdx