Skip to content

Conversation

@ysbaddaden
Copy link
Contributor

@ysbaddaden ysbaddaden commented Nov 26, 2025

The LLVM bindings only expose the targets that the Crystal compiler itself supports, and each target copy-pastes the LibLLVM bindings and LLVM init methods which should use a macro.

I introduce a LibLLVM::ALL_TARGETS constant that's only used in macros to check if a known target has been built and generate the bindings and init methods accordingly.

The constant is a Hash because we need the original LLVM target name (e.g. AArch64) and Crystal chose to use lowercased symbols and aliases (e.g. aarch64). Maybe it should be an Array and macros use target.id.downcase instead 🤔 The constant is now an Array.

The @@initialized_ class variables are now an atomic, and the dead @@initialized has been removed.

The list of targets is duplicated with the scripts/generate_llvm_version_info.cr file but the script musn't load src/llvm/lib_llvm.cr. Maybe the target list could be extracted into another file 🤔 The list has been extracted to src/llvm/lib_llvm/config.cr.

@straight-shoota
Copy link
Member

Combining with the list in scripts/generate_llvm_version_info.cr sounds great. But maybe the generator could be the source of truth and populate the list in lib_llvm.cr? (or rather a separate file lib_llvm/targets.cr?).

@ysbaddaden
Copy link
Contributor Author

Note: the script is a windows script to generate a llvm_VERSION file from the DLL when llvm-config isn't available (MSVC), but we could have a single file that both would load.

@straight-shoota straight-shoota added this to the 1.19.0 milestone Nov 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants