-
Notifications
You must be signed in to change notification settings - Fork 569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New: Cling interactive C++ REPL #5937
Conversation
C/Cling/build_tarballs.jl
Outdated
mv cling/ src/tools/ | ||
mkdir build | ||
cd build/ | ||
cmake -DCMAKE_INSTALL_PREFIX=$prefix -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN} -DCMAKE_BUILD_TYPE=Release LLVM_BUILD_TOOLS=OFF ../src |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean
cmake -DCMAKE_INSTALL_PREFIX=$prefix -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN} -DCMAKE_BUILD_TYPE=Release LLVM_BUILD_TOOLS=OFF ../src | |
cmake -DCMAKE_INSTALL_PREFIX=$prefix \ | |
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN} \ | |
-DCMAKE_BUILD_TYPE=Release \ | |
-DLLVM_BUILD_TOOLS=OFF \ | |
../src |
(note the -D
before LLVM_BUILD_TOOLS
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
(It builds for me anyway under Docker on intel macOS)
I've already changed things a bit on my local branch because of this:
# The very first thing we need to do is to build llvm-tblgen for x86_64-linux-muslc |
I currently have something like this (still a work in progress)
# The very first thing we need to do is to build llvm-tblgen for x86_64-linux-muslc
# This is because LLVM's cross-compile setup is kind of borked, so we just
# build the tools natively ourselves, directly. :/
# See: https://github.com/JuliaPackaging/Yggdrasil/blob/86a4221f71ee8ca5c0fd1056829a1fe2b28c879b/M/Metal_LLVM_Tools/build_tarballs.jl#L35
# Build llvm-tblgen and llvm-config
mkdir ${WORKSPACE}/bootstrap
pushd ${WORKSPACE}/bootstrap
CMAKE_FLAGS=()
CMAKE_FLAGS+=(-DLLVM_TARGETS_TO_BUILD:STRING=host)
CMAKE_FLAGS+=(-DLLVM_HOST_TRIPLE=${MACHTYPE})
CMAKE_FLAGS+=(-DCMAKE_BUILD_TYPE=Release)
CMAKE_FLAGS+=(-DLLVM_ENABLE_PROJECTS='llvm')
CMAKE_FLAGS+=(-DCMAKE_CROSSCOMPILING=False)
CMAKE_FLAGS+=(-DCMAKE_TOOLCHAIN_FILE=${CMAKE_HOST_TOOLCHAIN})
cmake -GNinja ${LLVM_SRCDIR} ${CMAKE_FLAGS[@]}
ninja -j${nproc} llvm-tblgen llvm-config
popd
# Let's do the actual build within the `build` subdirectory
mkdir ${WORKSPACE}/build && cd ${WORKSPACE}/build
CMAKE_FLAGS=()
# Tell LLVM where our pre-built tblgen tools are
CMAKE_FLAGS+=(-DLLVM_TABLEGEN=${WORKSPACE}/bootstrap/bin/llvm-tblgen)
CMAKE_FLAGS+=(-DLLVM_CONFIG_PATH=${WORKSPACE}/bootstrap/bin/llvm-config)
# Install things into $prefix
CMAKE_FLAGS+=(-DCMAKE_INSTALL_PREFIX=${prefix})
# Explicitly use our cmake toolchain file and tell CMake we're cross-compiling
CMAKE_FLAGS+=(-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN})
CMAKE_FLAGS+=(-DCMAKE_CROSSCOMPILING:BOOL=ON)
# Release build for best performance
CMAKE_FLAGS+=(-DCMAKE_BUILD_TYPE=Release)
CMAKE_FLAGS+=(-DLLVM_TARGETS_TO_BUILD="host;NVPTX")
CMAKE_FLAGS+=(-DLLVM_BUILD_TOOLS=OFF)
cmake -GNinja ${LLVM_SRCDIR} ${CMAKE_FLAGS[@]}
ninja -j${nproc} \
tools/cling/install \
install-clang-resource-headers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CMAKE_FLAGS+=(-DCMAKE_CROSSCOMPILING=False)
looks like a blatant lie.
Edit: oh, that's only for the host tools? But with ${CMAKE_HOST_TOOLCHAIN}
CMAKE_CROSSCOMPILING
should already be true, isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm copying this stuff from ...
here:
Lines 72 to 74 in 73a24b8
# The very first thing we need to do is to build llvm-tblgen for x86_64-linux-muslc | |
# This is because LLVM's cross-compile setup is kind of borked, so we just | |
# build the tools natively ourselves, directly. :/ |
and here:
Yggdrasil/M/Metal_LLVM_Tools/build_tarballs.jl
Lines 35 to 37 in 86a4221
# The very first thing we need to do is to build llvm-tblgen for x86_64-linux-muslc | |
# This is because LLVM's cross-compile setup is kind of borked, so we just | |
# build the tools natively ourselves, directly. :/ |
It seems like cross compilation is broken for llvm, so these work-arounds are needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More than LLVM specifically being broken, the problem is that as far as I know in CMake there is no way to pass both host and target toolchains at the same time, like more sensible build systems allow to do, so you have to manually build host tools separately. I still think manually setting CMAKE_CROSSCOMPILING
is unnecessary though.
C/Cling/build_tarballs.jl
Outdated
cd tools/cling/ | ||
make install | ||
cd ../.. | ||
make install-clang-resource-headers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cd tools/cling/ | |
make install | |
cd ../.. | |
make install-clang-resource-headers | |
make -C tools/cling/ install | |
make install-clang-resource-headers |
Big fan of Cling, but can I ask for the reason why you want to include it in Yggdrasil? |
@vchuravy, I'm using it here to resolve Some more explanation is here: JuliaInterop/Clang.jl#309 (comment) |
CI says "Not exactly 2 tarballs? This isn't right!" @giordano do you understand what this means ?
|
That comes from Line 299 in 8d0c4b6
products/ directory.
|
Or maybe not enough... |
Related to this ? libsdl-org/SDL#6491 Looks like this is caused by The Maybe something like this would help: Lines 220 to 222 in 73a24b8
|
Yggdrasil/S/SDL2/build_tarballs.jl Lines 26 to 28 in 359cb6f
|
built on the top of LLVM and Clang libraries https://root.cern/cling https://root.cern/cling/cling_build_instructions/
Seems to be working now (tested using tarballs downloaded from CI). Examples of using % uname -a
Darwin Sams-2019-Macbook.local 22.1.0 Darwin Kernel Version 22.1.0: Sun Oct 9 20:14:54 PDT 2022; root:xnu-8792.41.9~2/RELEASE_X86_64 x86_64
% tar xzf ../x86_64-apple-darwin.tar.gz
% grep TCP_MAXOLEN `xcrun --show-sdk-path`/usr/include/netinet/tcp.h
#define TCP_MAXOLEN (TCP_MAXHLEN - sizeof(struct tcphdr))
% ./bin/cling -isystem`xcrun --show-sdk-path`/usr/include --nologo
[cling]$ #include <netinet/tcp.h>
[cling]$ TCP_MAXOLEN
(unsigned long) 40 $ uname -a
Linux debian 6.1.0-0-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1~rc6-1~exp1 (2022-11-26) x86_64 GNU/Linux
$ tar xzf ../x86_64-linux-gnu.tar.gz
$ grep ICMP_ADVLENMIN /usr/include/netinet/ip_icmp.h
#define ICMP_ADVLENMIN (8 + sizeof (struct ip) + 8) /* min */
$ ./bin/cling --nologo
[cling]$ #include <netinet/ip_icmp.h>
[cling]$ ICMP_ADVLENMIN
(unsigned long) 36
[cling]$ #include <stdio.h>
[cling]$ printf("Hello World!\n");
Hello World! Here's another one... #define LPSETTIMEOUT_OLD 0x060f /* set parport timeout */
#define LPSETTIMEOUT_NEW \
_IOW(0x6, 0xf, __s64[2]) /* set parport timeout */
#if __BITS_PER_LONG == 64
#define LPSETTIMEOUT LPSETTIMEOUT_OLD
#else
#define LPSETTIMEOUT (sizeof(time_t) > sizeof(__kernel_long_t) ? \
LPSETTIMEOUT_NEW : LPSETTIMEOUT_OLD)
#endif [cling]$ #include <linux/lp.h>
[cling]$ LPSETTIMEOUT
(int) 1551 |
C/Cling/build_tarballs.jl
Outdated
Platform("x86_64", "macOS"), | ||
Platform("aarch64", "linux"; libc = "glibc") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can maybe also try aarch64 darwin?
Platform("x86_64", "macOS"), | |
Platform("aarch64", "linux"; libc = "glibc") | |
Platform("aarch64", "linux"; libc = "glibc"), | |
Platform("x86_64", "macOS"), | |
Platform("aarch64", "macOS"), |
And what about other platforms?
Co-authored-by: Mosè Giordano <giordano@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should have noticed this before
Thanks for your contribution! I'm curious to see how this works out 😄 |
Thanks for your assistance @giordano |
Cling is an interactive C++ interpreter built on the top of LLVM and Clang libraries
Building Cling requires CERN's patched versions of llvm and clang.
https://root.cern/cling
https://root.cern/cling/cling_build_instructions/
https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/cling.rb