Skip to content

Commit 655e7e4

Browse files
authored
Support LLVM 21.0 (development branch) (#15771)
Currently, Crystal waits until a new stable major version of LLVM is released before that version is declared in `src/llvm/ext/llvm-versions.txt`, the list of supported LLVM versions. This has proved to be a hassle when maintaining Crystal on software repositories that only distribute the latest versions of each package; LLVM x.1 is often scheduled half to a whole month before a corresponding Crystal 1.y release, during which either Crystal does not run at all (LLVM could use versioned library names), or someone has to explicitly backport LLVM support on our master branch to a preceding Crystal package. With this change, Crystal now supports the latest LLVM development branch explicitly, in the hopes that unattended transitions from LLVM x.0 to x.1 are smooth. This also means Crystal is now responsible for tracking any upstream LLVM changes as soon as possible.
1 parent fc444b6 commit 655e7e4

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

.github/workflows/llvm.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,22 @@ jobs:
4141
- {llvm_version: 18, runs-on: ubuntu-24.04, codename: noble}
4242
- {llvm_version: 19, runs-on: ubuntu-24.04, codename: noble}
4343
- {llvm_version: 20, runs-on: ubuntu-24.04, codename: noble}
44-
name: "LLVM ${{ matrix.llvm_version }}"
44+
- {runs-on: ubuntu-24.04, codename: noble}
45+
name: "LLVM ${{ matrix.llvm_version || 'Nightly' }}"
4546
steps:
4647
- name: Checkout Crystal source
4748
uses: actions/checkout@v4
4849

49-
- name: Install LLVM ${{ matrix.llvm_version }}
50+
- name: Install LLVM ${{ matrix.llvm_version || 'Nightly' }}
5051
run: |
5152
sudo apt remove 'llvm-*' 'libllvm*'
5253
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
53-
sudo apt-add-repository -y deb http://apt.llvm.org/${{ matrix.codename }}/ llvm-toolchain-${{ matrix.codename }}-${{ matrix.llvm_version }} main
54-
sudo apt install -y llvm-${{ matrix.llvm_version }}-dev lld
54+
sudo apt-add-repository -y \
55+
deb \
56+
http://apt.llvm.org/${{ matrix.codename }}/ \
57+
llvm-toolchain-${{ matrix.codename }}${{ matrix.llvm_version && format('-{0}', matrix.llvm_version) || '' }} \
58+
main
59+
sudo apt install -y llvm${{ matrix.llvm_version && format('-{0}', matrix.llvm_version) || '' }}-dev lld
5560
5661
- name: Install Crystal
5762
uses: crystal-lang/install-crystal@v1

src/compiler/crystal/codegen/codegen.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2544,7 +2544,7 @@ module Crystal
25442544
name = "'#{name}'"
25452545
key = StringKey.new(@llvm_mod, str)
25462546
@strings[key] ||= begin
2547-
global = @llvm_mod.globals.add(@llvm_typer.llvm_string_type(str.bytesize), name)
2547+
global = @llvm_mod.globals.add(@llvm_typer.llvm_string_type(str.bytesize), name.gsub('\\', "\\\\"))
25482548
global.linkage = LLVM::Linkage::Private
25492549
global.global_constant = true
25502550
global.initializer = llvm_context.const_struct [

src/llvm/enums.cr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ module LLVM
5757
WillReturn
5858
WriteOnly
5959
ZExt
60+
Captures
6061

6162
# NOTE: enum body does not allow `class_getter` or `TypeDeclaration`, hence
6263
# the nil cast
@@ -91,6 +92,7 @@ module LLVM
9192
kinds[ArgMemOnly] = kind_for_name("argmemonly")
9293
kinds[Builtin] = kind_for_name("builtin")
9394
kinds[ByVal] = kind_for_name("byval")
95+
kinds[Captures] = kind_for_name("captures")
9496
kinds[Cold] = kind_for_name("cold")
9597
kinds[Convergent] = kind_for_name("convergent")
9698
kinds[Dereferenceable] = kind_for_name("dereferenceable")

src/llvm/ext/llvm-versions.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20.1 19.1 18.1 17.0 16.0 15.0 14.0 13.0 12.0 11.1 11.0 10.0 9.0 8.0
1+
21.0 20.1 19.1 18.1 17.0 16.0 15.0 14.0 13.0 12.0 11.1 11.0 10.0 9.0 8.0

0 commit comments

Comments
 (0)