tinygo-org/go-llvm

Cannot build/install with llvm-14 from apt.llvm.org

sayotte opened this issue · 4 comments

System info:

sayotte@x270:~/go/pkg/mod/tinygo.org/x$ cat /etc/issue
Ubuntu 20.04.3 LTS \n \l

sayotte@x270:~/go/pkg/mod/tinygo.org/x$ dpkg-query -l | grep llvm
ii  libllvm12:amd64                                             1:12.0.0-3ubuntu1~20.04.5                                        amd64        Modular compiler and toolchain technologies, runtime library
ii  libllvm12:i386                                              1:12.0.0-3ubuntu1~20.04.5                                        i386         Modular compiler and toolchain technologies, runtime library
ii  libllvm14:amd64                                             1:14.0.6~++20221117072312+f28c006a5895-1~exp1~20221117192323.163 amd64        Modular compiler and toolchain technologies, runtime library
ii  llvm-14                                                     1:14.0.6~++20221117072312+f28c006a5895-1~exp1~20221117192323.163 amd64        Modular compiler and toolchain technologies
ii  llvm-14-dev                                                 1:14.0.6~++20221117072312+f28c006a5895-1~exp1~20221117192323.163 amd64        Modular compiler and toolchain technologies, libraries and headers
ii  llvm-14-linker-tools                                        1:14.0.6~++20221117072312+f28c006a5895-1~exp1~20221117192323.163 amd64        Modular compiler and toolchain technologies - Plugins
ii  llvm-14-runtime                                             1:14.0.6~++20221117072312+f28c006a5895-1~exp1~20221117192323.163 amd64        Modular compiler and toolchain technologies, IR interpreter
ii  llvm-14-tools                                               1:14.0.6~++20221117072312+f28c006a5895-1~exp1~20221117192323.163 amd64        Modular compiler and toolchain technologies, tools

sayotte@x270:~/go/pkg/mod/tinygo.org/x$ llvm-as-14 --version
Ubuntu LLVM version 14.0.6
  Optimized build.
  Default target: x86_64-pc-linux-gnu
  Host CPU: skylake

go get fails to find header files:

sayotte@x270:~/go/pkg/mod/tinygo.org/x$ go get tinygo.org/x/go-llvm
# tinygo.org/x/go-llvm
go-llvm@v0.0.0-20221028183034-8341240c0b32/analysis.go:16:10: fatal error: llvm-c/Analysis.h: No such file or directory
   16 | #include "llvm-c/Analysis.h" // If you are getting an error here you need to build or install LLVM, see https://tinygo.org/docs/guides/build/
      |          ^~~~~~~~~~~~~~~~~~~
compilation terminated.

Modify Makefile to use the installed version:

sayotte@x270:~/go/pkg/mod/tinygo.org/x/go-llvm@v0.0.0-20221028183034-8341240c0b32$ sudo sed -i 's|VERSION=9.0.0|VERSION=14.0.6|' Makefile 
sayotte@x270:~/go/pkg/mod/tinygo.org/x/go-llvm@v0.0.0-20221028183034-8341240c0b32$ sudo PATH=$PATH make config

go install still fails on the same import:

sayotte@x270:~/go/pkg/mod/tinygo.org/x/go-llvm@v0.0.0-20221028183034-8341240c0b32$ go install
# tinygo.org/x/go-llvm
./analysis.go:16:10: fatal error: llvm-c/Analysis.h: No such file or directory
   16 | #include "llvm-c/Analysis.h" // If you are getting an error here you need to build or install LLVM, see https://tinygo.org/docs/guides/build/
      |          ^~~~~~~~~~~~~~~~~~~
compilation terminated.

An attempt with setting CGO_ flags using llvm-config-14 overcomes` that problem, but dies in linking because it's looking for LLVM-15 for some reason???:

sayotte@x270:~/go/pkg/mod/tinygo.org/x/go-llvm@v0.0.0-20221028183034-8341240c0b32$ cat ~/build.sh 
#!/bin/bash

export CGO_CPPFLAGS=$(llvm-config-14 --cppflags)
export CGO_CFLAGS=$(llvm-config-14 --cflags)
export CGO_LDFLAGS=$(llvm-config-14 --ldflags)
go install

sayotte@x270:~/go/pkg/mod/tinygo.org/x/go-llvm@v0.0.0-20221028183034-8341240c0b32$ ~/build.sh >~/log 2>&1
sayotte@x270:~/go/pkg/mod/tinygo.org/x/go-llvm@v0.0.0-20221028183034-8341240c0b32$ cat ~/log
# tinygo.org/x/go-llvm
/usr/bin/ld: cannot find -lLLVM-15
collect2: error: ld returned 1 exit statu

I then tried deleting llvm_config_linux_llvm15.go, hoping it was unnecessary and the culprit, but the linker barfed on boatloads of unresolved symbols.

You need to use -tags=llvm14 to use LLVM 14. The default is LLVM 15.
This package is tested in CI with LLVM 14 (as well as LLVM 15), so there is no need to modify the source code.

Ahh I see. I thought 14 would be default and most desirable, because of this in the README.md:

Currently supported:

LLVM 14 from [apt.llvm.org](http://apt.llvm.org/) on Debian/Ubuntu.
LLVM 14 from Homebrew on macOS.

Ah, I see. I have updated the README with the current state of LLVM support.

I'm guessing this is now resolved, so closing. Please comment if it still doesn't work for you.