一键导入
generate-recipe
Translate extracted repository metadata into a Spack package recipe, then validate and iterate until the package installs successfully.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Translate extracted repository metadata into a Spack package recipe, then validate and iterate until the package installs successfully.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Extract and analyze CMake build metadata from a repository, mapping it to Spack-relevant abstractions for use in recipe generation
Extract Spack package metadata and find similar packages based on build system, dependencies, and variants. Use to discover reference recipes for package generation.
| name | generate-recipe |
| description | Translate extracted repository metadata into a Spack package recipe, then validate and iterate until the package installs successfully. |
Use this skill after the cmake-extract skill has completed and produced a spack_metadata.txt file. This skill translates the extracted metadata into a working Spack package recipe.
AGENTS.md before invoking any spack commands — it defines how spack must be called in this environment.spack_metadata.txt must exist in the repository directoryfind-similar-packages skill first to find 2 reference recipes. These provide implementation patterns for similar packages and improve recipe quality.Read spack_metadata.txt from the repository directory. The file contains:
Given the metadata, generate a Spack package recipe as a plain text Python source file.
Determine required builder classes from the metadata and import them first, in this order:
from spack_repo.builtin.build_systems.cmake import CMakePackage # if cmake from spack_repo.builtin.build_systems.cuda import CudaPackage # if cuda, etc. from spack.package import *
Respect this import order or the package will fail to build.
Name the class using PascalCase derived directly from the Spack spec name: Example: "bricks" → class Bricks(CMakePackage):
Include additional builder classes (e.g. CudaPackage, ROCmPackage) when strongly implied by the build system or FEATURES. List them as multiple inheritance after the primary base class.
If cmake metadata is available, translate every mapping line from the CMAKE MAPPINGS section into its corresponding Spack directive.
If no cmake mappings exist (e.g. the build system is Autotools, Meson, or something else), derive the equivalent mappings yourself by reading the build files directly — look for optional feature flags, find_package-style dependency checks, and conditional compilation blocks. Apply the same translation logic: each meaningful build option becomes a variant or dependency, each version check becomes a constraint. All decisions must be traceable to something in the build files (see Constraint traceability).
If there is other behavior to encode in the recipe that is necessary for installation or feature-completeness (such as build environment setup or other logic), feel free to add as long as they are reflected in Spack best practices.
Version constraints use prefix matching, which differs from most package managers. A bound like 1.2 means "the 1.2 prefix", not the exact version 1.2.0:
@1.2 matches any version with prefix 1.2 — 1.2, 1.2.3, 1.2.3.4.5 — but not 1.1.x or 1.3.x.@:1.2 (upper bound) includes 1.2.3, 1.2.3.4.5, but not 1.3.0.@1.2: (lower bound) matches 1.2.* and anything after.@1.1:1.2 matches the 1.1.* through 1.2.* series but not 1.3.0.Avoid gaps between version ranges. Use minor-version boundaries rather than exact patch versions so ranges are contiguous. For example, write @:5.1 and @5.2: — not @:5.1.0 and @5.2.1:, which leaves a gap.
maintainers, tags
If you used the find-similar-packages skill, incorporate the reference recipes found:
For every non-trivial constraint added to the recipe — version bounds, conflicts, conditional dependencies, variant defaults — retain a clear mental record of why it was added and where the evidence came from. Sources include:
gh)If the user asks why a constraint exists, give a precise answer: what broke, what commit or version introduced the breakage, and what evidence supports the bound. A vague answer is not acceptable. If the justification cannot be reconstructed, say so and offer to re-investigate rather than guessing.
Example of the expected quality:
depends_on("zlib@1.2.11:") — CMakeLists.txt calls find_package(ZLIB 1.2.11 REQUIRED); mapped directly from the version argument.
Run the following to create the package scaffold and capture the output path:
spack create --name <pkg_name> --skip-editor
The URL can be a link to a tarball or a git repository. Ask the user for this information if not already provided. With the URL, Spack will look for versions and checksums automatically.
Parse the output to extract the file path where the package was created. Read the generated file, and merge it with the recipe generated in Step 2.
When using a git URL, you must verify what versions actually exist before adding them to the recipe:
Check for release tags first using gh api repos/<owner>/<repo>/tags to see what tags exist in the repository.
If no release tags exist:
version("main", branch="main") (or the appropriate default branch name)git = "<url>" setRun each command below in order. Use any errors or warnings to revise the recipe and re-run from the failing phase. Continue until installation succeeds or an issue is deemed intractable.
Any information needed to fix the recipe should be available in the error messages, the target repository's build configuration files, any reference packages, or Spack documentation. It should not be necessary to search for external details unless there is a critical issue you cannot resolve with the available information.
Create a temporary directory and a Spack environment rooted there. Use this directory path for all subsequent -e invocations:
export tmp_env=$(mktemp -d) spack env create --dir $tmp_env
spack -e $tmp_env list <pkg_name>
Catches syntax errors or load failures. Fix any issues before proceeding.
spack -e $tmp_env audit packages <pkg_name>
Checks for missing dependencies, malformed directives, and other static issues. Fix any issues before proceeding.
spack -e $tmp_env spec <pkg_name>
Resolves all dependencies and constraints. Fix any issues before proceeding.
Add the package as a root spec in the environment, then install:
spack -e $tmp_env add <pkg_name> spack -e $tmp_env install
Attempts a full build and install. Fix any issues and re-run from the failing phase.
Make small, incremental changes. When iterating on a failing recipe, change one thing at a time and re-run the failing phase. Changing multiple things at once makes it harder to identify what fixed or broke something.
Always concretize before any other env operation (stage, install, location, etc.). After concretizing, use just the package name — no @version — since the version is already pinned. Without prior concretization, Spack resolves the spec ad-hoc and may not pick the version you expect.
If any phase fails due to a broken or missing dependency (rather than an issue in the target package itself), stop and ask the user: "The failure appears to be in dependency . Would you like to fix that first?" Do not attempt to fix dependency packages autonomously — stay focused on the target package.
If online access is available, gh is a powerful debugging tool. Use it freely to gather context that isn't in the local error output:
gh api repos/<owner>/<repo>/tags — find what versions actually exist upstreamgh api repos/<owner>/<repo>/contents/<path> --jq '.content' | base64 -d — read CMakeLists.txt, setup.py, etc. at a specific tag without cloninggh issue list -R <owner>/<repo> --search "<keyword>" — check if a build failure is a known upstream buggh api repos/<owner>/<repo>/compare/<base>...<head> — understand what changed between two releases that may affect the recipe/raw or using gh run viewWhen a user provides a failure URL, try fetching its raw content before asking for more information.
Ask the user before proceeding: "Installation succeeded. Would you like to run smoke tests across variant combinations?"
If yes, select a representative set of specs to test — toggle boolean variants, pin optional dependencies to versions within their declared bounds, and combine constraints that are likely to interact. Do not attempt to cover every combination; be judicious. Good candidates include:
+cuda, ~mpi)For each spec to test, create a fresh environment, add the spec, and install:
export tmp_env_N=$(mktemp -d) spack env create --dir $tmp_env_N spack -e $tmp_env_N add <pkg_name> spack -e $tmp_env_N install
Use a separate tmp_env_N variable for each spec (e.g. tmp_env_1, tmp_env_2, ...) so environments remain independent.
Report a summary of which specs passed and which failed. Failures in smoke tests should be investigated and fixed the same way as Phase 4 failures, unless they trace back to a dependency.