Skip to content

Run one compiler order everywhere, and find llvm-config only in the compiler's Homebrew prefix - #78

Merged
crimson-knight merged 3 commits into
mainfrom
compiler-named-by-crystal-and-linuxbrew-llvm
Nov 26, 2026
Merged

crimson-knight merged 3 commits into
mainfrom
compiler-named-by-crystal-and-linuxbrew-llvm

Conversation

@crimson-knight

@crimson-knight crimson-knight commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Two changes for the agent-crystal Homebrew line (Amber V2).

One compiler order everywhere. Every Amber tool runs the command in CRYSTAL when it is set (surrounding whitespace stripped), otherwise crystal-alpha, otherwise stock crystal.

  • amber generate (route and plug insertion), amber exec, amber db seed, amber watch's default build and the default watch config run Amber::CLI.crystal_compiler_command, quoted with Process.quote. ResolveCrystalCompilerCommand takes the variable and a PATH lookup, so its spec covers each branch without touching the environment.
  • The agent loop (ResolveCompilerForAgentLoop and the generated .amber/amber-agent-hook) reads CRYSTAL instead of CRYSTAL_ALPHA and drops the acrystal alias. The hook version moves to 7, so amber doctor asks existing projects to rerun amber setup:agent.
  • amber-lsp's Lookup.default_compiler_command uses the same resolver.

llvm-config only from the compiler's Homebrew prefix. The stdlib API layer of amber-lsp lookup needs llvm-config to build src/docs_main.cr. FindLLVMConfigForCompiler (its own file) searches, in order:

  1. opt/llvm@N/bin/llvm-config, then opt/llvm/bin/llvm-config, in the Homebrew prefix that holds the compiler (ListHomebrewPrefixesAroundCompiler). Each layout proposes a candidate: the parent of Cellar for <prefix>/Cellar/<formula>/<version>/bin/<compiler>, the parent of opt for opt/<formula>/bin, and the parent of bin. The first candidate that holds a Cellar folder is the prefix. This covers /opt/homebrew, Linuxbrew (/home/linuxbrew/.linuxbrew) and custom prefixes.
  2. /opt/homebrew and /usr/local.
  3. llvm-config-N.M, llvm-config-N and llvm-config on PATH.

A compiler outside a Homebrew prefix contributes no search path, so nothing above an arbitrary compiler (a project folder, a home folder) is ever run; a spec plants an llvm-config in a project's opt/ folder and proves it never runs. The version must match LLVM major.minor as whole components, so 21.10.x does not match 21.1.

Known separate issue, not fixed here: with agent-crystal 1.22.3-incremental-2 and -3, crystal-alpha docs src/docs_main.cr fails because require "./compress/**" loads both compress/deflate/lib_z/reader.cr and compress/deflate/mica/reader.cr. That makes the stdlib layer unavailable with an empty cache, so build_layered_api_index_spec.cr and two lookup_command_spec.cr examples fail locally on that toolchain (they fail identically at this PR's first commit); CI on stock Crystal runs them.

Local: crystal-alpha spec gives 812 examples, 3 failures (the three above), 0 errors.

…compiler's Homebrew prefix

Every Amber tool now runs the compiler named by CRYSTAL (stripped of
surrounding whitespace) when it is set, otherwise crystal-alpha, otherwise
stock crystal:

- amber db seed, amber watch's default build and the default watch config
  run the compiler from Amber::CLI.crystal_compiler_command, quoted.
- The agent loop resolver and the generated agent hook read CRYSTAL instead
  of CRYSTAL_ALPHA and drop the acrystal alias; the hook version moves to 7
  so `amber doctor` asks existing projects to rerun setup.
- amber-lsp's default compiler uses the same resolver.

amber-lsp's llvm-config search no longer walks every directory above the
compiler. FindLLVMConfigForCompiler tries opt/llvm@N in the Homebrew prefix
that holds the compiler (the parent of Cellar, or of bin / opt/<formula>/bin,
when that prefix has a Cellar folder), then the standard Homebrew prefixes,
then PATH, and matches LLVM major.minor as whole version components, so
21.10.x no longer matches 21.1. A spec plants an llvm-config in a project's
opt/ folder and proves it is never run.
@crimson-knight crimson-knight changed the title Run the compiler named by CRYSTAL, and find Homebrew's keg-only llvm beside the compiler Run one compiler order everywhere, and find llvm-config only in the compiler's Homebrew prefix Nov 25, 2026
…rch the unversioned llvm keg

The opt/<formula>/bin rule fired for /opt/homebrew/bin/crystal-alpha (the folder two levels above bin is /opt) and returned no prefix. Each layout now proposes a candidate, and the first candidate that holds a Cellar folder is the prefix. FindLLVMConfigForCompiler also tries opt/llvm beside opt/llvm@N; the version check rejects either when its LLVM does not match.
@crimson-knight
crimson-knight merged commit 3c212a9 into main Nov 26, 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