Skip to content

Add amber build with --target-tier for a known deploy CPU - #80

Merged
crimson-knight merged 1 commit into
mainfrom
c1/target-tier
Nov 27, 2026
Merged

crimson-knight merged 1 commit into
mainfrom
c1/target-tier

Conversation

@crimson-knight

Copy link
Copy Markdown
Member

What this adds

amber build builds the app's release binary with crystal-alpha (first targets: entry in shard.yml into bin/, --release, after compiling app/assets/), with a --target-tier NAME option for owners who know their deploy machine.

  • Default tier portable: crystal-alpha's own default target, so one binary runs on every supported chip and picks per-chip kernels at startup.
  • Named tiers pass --mcpu: x86-64-v2, x86-64-v3, x86-64-v4, neoverse-v1 (Graviton3), neoverse-n2 (Azure Cobalt 100), neoverse-v2 (Graviton4), apple-m1, apple-m4.
  • The table is one constant, AmberCLI::TARGET_TIERS (src/amber_cli/core/target_tier.cr), each entry with a one-line description; amber build --list-target-tiers prints it.
  • An unknown tier exits 1 with the list of valid tiers; a tier for the other architecture exits 1 and says to build on a machine of that architecture.
  • The tier can also come from .amber.yml (build: target_tier: ...); --target-tier overrides it. shard.yml is read only for its targets:.
  • --dry-run prints the compiler command without running it.

Every CPU name was checked against crystal-alpha 1.22.3 / LLVM 21.1.8: Linux tiers by --cross-compile --target x86_64-linux-gnu|aarch64-linux-gnu --mcpu ... producing an ELF object with no "not a recognized processor" warning, Apple tiers by a native build that runs.

Note: neoverse-n2 is Armv9 with SVE2, which Graviton3 (Neoverse V1) lacks, so Graviton3 gets its own neoverse-v1 tier.

Proof

  • crystal spec spec/commands/build_command_spec.cr: option parsing, the tier table, the exact compiler command line per tier, the .amber.yml fallback and override, unknown-tier and wrong-architecture errors.
  • On an M1 Max, a fresh amber new tier_demo -d sqlite app built with amber build and with amber build --target-tier apple-m1 (crystal-alpha build src/tier_demo.cr -o bin/tier_demo --release --mcpu apple-m1); both serve HTTP 200, and otool -L lists only /usr/lib/libsqlite3.dylib and /usr/lib/libSystem.B.dylib.

Ships in the next amber_cli release; this PR makes no release.

amber build compiles the first shard.yml target into bin/ with
crystal-alpha in release mode, after compiling app/assets. The default
tier, portable, keeps the compiler's own target; named tiers (x86-64-v2/v3/v4,
neoverse-v1/n2/v2, apple-m1/m4) pass --mcpu. The tier table is one
constant, AmberCLI::TARGET_TIERS, printed by --list-target-tiers. A tier
may also come from build.target_tier in .amber.yml.
@crimson-knight
crimson-knight merged commit 3171453 into main Nov 27, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant