Skip to content
Fangrui Song edited this page Nov 24, 2024 · 77 revisions
cd
git clone https://github.com/MaskRay/Config
cd Config
./deploy.bash

Emacs

sudo apt install libjansson-dev => --with-json (default) => native json-parse-string

sudo apt install libgif-dev libgtk-3-dev libgnutls28-dev libjpeg-dev libncurses-dev libxaw3dxft8-dev libxpm-dev texinfo

sudo apt install libgccjit-14-dev libtree-sitter-dev

mkdir -p ~/Dev/Emacs
cd ~/Dev/Emacs
git clone https://github.com/emacs-mirror/emacs
cd emacs
./autogen.sh

# Delete files like lisp/*.elc
# mkdir -p out/release; cd out/release
# apt install libgnutls28-dev
# apt install libjansson-dev libtree-sitter-dev
mkdir -p out/native; cd out/native
../../configure --with-native-compilation --with-json --with-tree-sitter --with-xwidgets CFLAGS='-O3 -march=native' LDFLAGS=-fuse-ld=lld

make -j
git clone --depth 1 https://github.com/doomemacs/doomemacs ~/.config/emacs
~/.config/emacs/bin/doom install

Neovim

apt install libtool-bin pkg-config

git clone --depth=1 https://github.com/neovim/neovim ~/projects/neovim
cd ~/projects/neovim
make CMAKE_EXTRA_FLAGS=-DCMAKE_INSTALL_PREFIX=$HOME/.local
make install

ccls

If you compile with local clang+llvm, ninja clangFormat clangIndex clangTooling should be sufficient.

# link against local clang to leverage latest features
LLVM=$(realpath ~/llvm)
cmake -H. -Bout/release -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=$HOME/Stable/bin/clang++ -DCMAKE_EXE_LINKER_FLAGS='-fuse-ld=lld' -DCMAKE_PREFIX_PATH="$LLVM/out/stable;$LLVM/out/stable/tools/clang;$LLVM/llvm;$LLVM/clang"

# Build with the prebuilt 9.0.0 package
cmake -H. -Bout/prebuilt-9 -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=$HOME/Stable/bin/clang++ -DCMAKE_PREFIX_PATH=$(realpath ~/llvm-prebuilt/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-16.04)

# Build with the prebuilt 15.0.6 package
cmake -H. -Bout/prebuilt-15 -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=$HOME/Stable/bin/clang++ -DCMAKE_PREFIX_PATH=$HOME/llvm-prebuilt/clang+llvm-15.0.6-x86_64-linux-gnu-ubuntu-18.04

# Debug build with local clang
LLVM=$(realpath ~/llvm)
cmake -H. -Bout/debug -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=$HOME/Stable/bin/clang++ -DCMAKE_CXX_FLAGS=-gsplit-dwarf=single -DCMAKE_EXE_LINKER_FLAGS='-fuse-ld=lld -Wl,--gdb-index' -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DCMAKE_PREFIX_PATH="$LLVM/Release;$LLVM/Release/tools/clang;$LLVM/llvm;$LLVM/clang"

# Debug build with local Debug clang
cmake -H. -Bout/debug-clang -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=$HOME/Stable/bin/clang++ -DCMAKE_CXX_FLAGS=-gsplit-dwarf=single -DCMAKE_EXE_LINKER_FLAGS='-fuse-ld=lld -Wl,--gdb-index' -DCMAKE_PREFIX_PATH="$out/Debug;$out/Debug/tools/clang;$LLVM/llvm;$LLVM/clang"

# Debug+ASAN build with local clang
cmake -H. -Bout/asan -G Ninja -DASAN=on -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=$LLVM/Release/bin/clang++ -DCMAKE_CXX_LINK_FLAGS=-fuse-ld=lld -DCMAKE_PREFIX_PATH="$LLVM/out/release;$LLVM/out/release/tools/clang;$LLVM/llvm;$LLVM/clang"

# Debug build with bundled clang+llvm downloaded from releases.llvm.org
cmake -H. -Bout/debug -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_LINK_FLAGS='-fuse-ld=lld -Wl,-export-dynamic'
  • Faster linking: -gsplit-dwarf=single, -fuse-ld=lld
  • Function name in symbolizer: -DCMAKE_CXX_LINK_FLAGS=-Wl,-export-dynamic

glibc

mkdir Debug; cd Debug
../configure --prefix=/tmp/opt/glibc CFLAGS='-g3 -O2'

Linux

wget 'https://git.archlinux.org/svntogit/packages.git/plain/trunk/config?h=packages/linux' -O .config
yes '' | make config
bear make -j bzImage modules

Pre-built clang

curl -s https://raw.githubusercontent.com/chromium/chromium/main/tools/clang/scripts/update.py | python - --output-dir=~/Stable

cd /usr/local/bin
sudo ln -s ~/Stable/bin/{clang,clang++,lld} .
sudo ln -s lld ld

See also Slim LLVM toolchains for building the Linux kernel.

llvm-project

git clone [email protected]:llvm/llvm-project.git ~/llvm
cd ~/llvm
cat > ~/llvm/.git/hooks/pre-commit <<'e'
#!/bin/zsh
git diff -U0 'HEAD^' | ~/llvm/clang/tools/clang-format/clang-format-diff.py -p1 -i
e
chmod +x ~/llvm/.git/hooks/pre-commit

touch .ccls-root
mkdir /tmp/ccls-cache
ln -s /tmp/ccls-cache .ccls-cache
echo /out >> .git/info/exclude
echo /.ccls-cache >> .git/info/exclude

~/bin/configure-llvm preset  # See LLVM.md
ln -s /tmp/Debug/compile_commands.json .

binutils-gdb

cd ~/Dev
git clone ssh://sourceware.org/git/binutils-gdb.git

apt install bison dejagnu flex texinfo

binutils + ld + gas + gdb + gold

mkdir Debug; cd Debug
../configure --enable-binutils --enable-gas --enable-gdb --enable-gold --disable-gprof --enable-ld --enable-plugins --without-guile --prefix=~/.local/stow/gdb CFLAGS='-O0 -g' CXXFLAGS='-O0 -g'
bear make -j

mkdir DebugAll; cd DebugAll
../configure --enable-targets=all CFLAGS='-g3 -O0' --disable-gdb

# i686
mkdir -p out/i686; cd out/i686
CC='gcc -m32' CXX='g++ -m32' ../../configure --prefix=~/.local/stow/gdb --disable-gdb --disable-readline i686-linux

## riscv
mkdir -p out/riscv; cd out/riscv
../../configure --target riscv --enable-binutils --enable-gas --enable-gdb --enable-gold --disable-gprof --enable-ld --enable-plugins --without-guile CFLAGS='-O0 -g' CXXFLAGS='-O0 -g'

GCC

cd ~/Dev
git clone git+ssh://[email protected]/git/gcc.git
mkdir Debug; cd Debug
../configure --enable-languages=c CFLAGS='-O0 -g' --disable-multilib --disable-libsanitizer
# apt install binutils-riscv64-linux-gnu
# (cd /usr/riscv64-linux-gnu/usr; sudo ln -s ../include; sudo ln -s .. riscv64-linux-gnu)
mkdir out/riscv64; cd out/riscv64
../../configure --prefix=/tmp/opt/gcc-riscv64 --with-sysroot=/usr/riscv64-linux-gnu --target=riscv64-linux-gnu --enable-languages=c,c++ --disable-multilib --disable-libsanitizer --disable-bootstrap CFLAGS='-O0 -g'
# make install
# /tmp/opt/gcc-riscv64/bin/riscv64-linux-gnu-g++ -B /usr/riscv64-linux-gnu/bin a.cc

Julia

https://github.com/JuliaLang/julia

make -j O=out configure  # edit out/Make.user
bear make -j O=out debug
make -j O=out release

ldc

git clone --recursive https://github.com/ldc-developers/ldc.git

cmake -H. -BDebug9 -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=$HOME/Stable/bin/clang -DCMAKE_CXX_COMPILER=$HOME/Stable/bin/clang++ -DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld -DD_COMPILER=$HOME/dlang/ldc-1.18.0/bin/ldmd2 -DCMAKE_CXX_STANDARD=14 -DLLVM_ROOT_DIR=$HOME/ccls/build/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-16.04

musl

mkdir debug; cd debug
../configure --enable-optimize=no --enable-debug --prefix=~/.local/stow/musl CFLAGS=-fuse-ld=lld
# CFLAGS=-mlong-double-64 on powerpc64le
% cat ~/Util/musl/obj/musl-gcc
#!/bin/sh
exec "${REALGCC:-gcc}" "$@" -specs ~/musl/out/debug/lib/musl-gcc.specs
% cat ~/Util/musl/lib/musl-gcc.specs
*my_dir:
/home/maskray/musl

*libdir:
/home/maskray/musl/out/debug/..

*prefix:
$(prefix)/..

%rename cpp_options old_cpp_options

*cpp_options:
-nostdinc -isystem %(my_dir)/arch/x86_64 -isystem %(my_dir)/arch/generic -isystem %(my_dir)/include -isystem %(prefix)/obj/include -isystem include%s %(old_cpp_options)

*cc1:
%(cc1_cpu) -isystem %(my_dir)/arch/x86_64 -isystem %(my_dir)/arch/generic -isystem %(my_dir)/include -isystem %(prefix)/obj/include -nostdinc -isystem include%s

*link_libgcc:
-L%(libdir) -L .%s

*libgcc:
libgcc.a%s %:if-exists(libgcc_eh.a%s)

*startfile:
%{static-pie: %(libdir)/rcrt1.o; !shared: %(libdir)/Scrt1.o} %(libdir)/crti.o crtbeginS.o%s

*endfile:
crtendS.o%s %(libdir)/crtn.o

*link:
%{static|static-pie:; :-dynamic-linker %(libdir)/libc.so} %{shared:-shared} %{static:-static} %{static-pie:-static -pie --no-dynamic-linker -z text} %{rdynamic:-export-dynamic}

*esp_link:


*esp_options:


*esp_cpp_options:

# arm-linux-musleabihf
../configure AR=~/llvm/Release/bin/llvm-ar RANLIB=: CC="$HOME/llvm/Release/bin/clang -target arm-linux-musleabihf" LDFLAGS=-fuse-ld=lld
# powerpc gcc
../configure CROSS_COMPILE=powerpc-linux-gnu- LDFLAGS=-fuse-ld=gold CFLAGS=-mlong-double-64
# riscv64
../configure --target riscv64 CROSS_COMPILE=/home/maskray/.local/opt/riscv-none-gcc/8.2.0-2.2-20190521-0004/bin/riscv-none-embed- CFLAGS='-march=rv64imafdc -mabi=lp64d'

libc-test

git clone git://repo.or.cz/libc-test.git
cd libc-test
# config.mak
CFLAGS += -specs ~/Dev/Bin/musl-gcc.specs
LDFLAGS += -specs ~/Dev/Bin/musl-gcc.specs

# config.mak.def minus glibc

rizin

(cd test; ln -s ~/Dev/Bin/rizin-testbins bins)

## ASAN
CFLAGS='-fsanitize=address,undefined -gsplit-dwarf' meson . out/asan --buildtype=debug --prefix ~/.local/opt/rizin/asan -Db_lundef=false
## Debug
CFLAGS=-gsplit-dwarf meson setup out/debug --buildtype=debug --prefix ~/.local/opt/rizin/debug
## Release
meson setup out/release --buildtype=release --prefix ~/.local/opt/rizin/release
mkdir -p ~/.local/share/rizin
cd ~/.local/share/rizin
ln -s ~/Dev/rizin/libr/cons/d cons
ln -s ~/Dev/rizin/Release/libr/anal/d anal
ln -s ~/Dev/rizin/Release/libr/asm/d asm
ln -s ~/Dev/rizin/Release/libr/bin/d bin
ln -s ~/Dev/rizin/Release/libr/flag/d flag
ln -s ~/Dev/rizin/Release/libr/syscall/d syscall

rizin-regressions:

export PKG_CONFIG_PATH=~/.config/rizin/Release/lib/x86_64-linux-gnu/pkgconfig

rizin-extras:

cd ~/Dev && git clone https://github.com/radareorg/rizin-extras
# R2_CFLAGS for r_asm.h
# R2PM_PREFIX for correct -Wl,-R
PKG_CONFIG_PATH=~/Dev/Bin/keystone/Release R2_CFLAGS=-I$HOME/.config/rizin/Release/include/libr R2PM_PREFIX=~/Dev/Bin/keystone/Release/llvm make -C keystone

mkdir -p ~/.local/share/rizin/plugins && cd ~/.local/share/rizin/plugins
for i in ~/Dev/rizin-extras/keystone/*.so; do ln -s $i; done

keystone:

cd ~/Dev/Bin
git clone https://github.com/keystone-engine/keystone
cd keystone
mkdir Release; cd Release
../make-lib.sh
# Modify Release/keystone.pc
# Release/llvm/lib/libkeystone.so
sed -i 's,^includedir=.*,includedir=/home/maskray/Dev/Bin/keystone/include,' keystone.pc
sed -i 's,^libdir=.*,includedir=/home/maskray/Dev/Bin/keystone/Release/llvm/lib,' keystone.pc

wabt

git clone https://github.com/WebAssembly/wabt

cmake -G Ninja -H. -Bout/clang/Release -DCMAKE_C_COMPILER=~/llvm/bin/clang -DCMAKE_CXX_COMPILER=~/llvm/bin/clang++ -DCMAKE_BUILD_TYPE=Release
cmake --build out/clang/Release

bpftrace

apt install clang-8 libclang-8-dev

bcc

git clone https://github.com/iovisor/bcc; cd bcc
cmake -GNinja -H. -BRelease -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=$HOME/llvm/bin/clang++ -DCMAKE_C_COMPILER=$HOME/llvm/bin/clang -DCMAKE_INSTALL_PREFIX=~/.local/stow/bcc -DLLVM_DIR=/usr/loca/llvm-7/cmake
ninja -C Release install

bpftrace

git clone https://github.com/iovisor/bpftrace; cd bpftrace
cmake -H. -BDebug -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=~/llvm/bin/clang -DCMAKE_CXX_COMPILER=~/llvm/bin/clang++ -DCMAKE_EXPORT_COMPILE_COMMANDS=on -DLIBBCC_INCLUDE_DIRS=$HOME/.local/stow/bcc/include/bcc -DLIBBCC_LIBRARIES=~/.local/stow/bcc/lib/libbcc.so -DLLVM_DIR=/usr/lib/llvm-8/cmake
cmake -H. -BRelease -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=~/llvm/bin/clang -DCMAKE_CXX_COMPILER=~/llvm/bin/clang++ -DLIBBCC_INCLUDE_DIRS=$HOME/.local/stow/bcc/include/bcc -DLIBBCC_LIBRARIES=~/.local/stow/bcc/lib/libbcc.so -DLLVM_DIR=/usr/lib/llvm-8/cmake

qemu-system-aarch64 -M virt -cpu cortex-a57 -nographic -smp 1 -m 2048 -kernel vmlinuz-vanilla -initrd initramfs-vanilla -append "console=ttyAMA0 ip=dhcp alpine_repo=http://dl-cdn.alpinelinux.org/alpine/edge/main/"

xmonad

sudo apt-get install -y xmonad xmonad-contrib xmobar trayer

# change ~/.config/xmonad/xmonad.hs
xmonad --recompile

Haskell

Install Stack:

curl -sSL https://get.haskellstack.org/ -o install.sh
sh install.sh -d ~/.local/bin/

Nim

Install choosenim:

curl -sSf -O https://nim-lang.org/choosenim/init.sh
git clone https://github.com/nim-lang/Nim.git; cd Nim

ruby

git clone https://github.com/ruby/ruby; cd ruby
autoreconf
mkdir Debug; cd Debug
../configure --prefix=/tmp/opt CFLAGS='-gsplit-dwarf=single' CC=~/Stable/bin/clang
bear make -j install-doc
cd ..; ln -s Debug/compile_commands.json
Clone this wiki locally