Skip to content

Commit cd92730

Browse files
committed
update build.sh, CI and package
1 parent b4246cf commit cd92730

File tree

14 files changed

+196
-318
lines changed

14 files changed

+196
-318
lines changed

.github/workflows/check.yml

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,37 @@ jobs:
1919
- name: Set up OCaml
2020
uses: ocaml/setup-ocaml@v2
2121
with:
22-
ocaml-compiler: 5.0.0
23-
24-
- name: Install ocamlformat
25-
run: opam install ocamlformat.0.26.1
26-
27-
- name: Check format
28-
run: |
29-
eval $(opam env)
30-
scripts/check-format
22+
ocaml-compiler: 5.3.0
3123

3224
- name: Use cached dependencies
3325
id: cache-opam
3426
uses: actions/cache@v3
3527
env:
36-
cache-name: cache-opam
28+
opam-cache-name: cache-opam
29+
with:
30+
path: ~/.opam
31+
key: ${{ env.opam-cache-name }}-build-${{ hashFiles('build.sh') }}
32+
33+
- name: Cache LLVM
34+
id: cache-llvm
35+
uses: actions/cache@v3
36+
env:
37+
llvm-cache-name: cache-llvm
3738
with:
38-
path: |
39-
~/.opam
40-
./_opam
41-
key: ${{ env.cache-name }}-build-${{ hashFiles('build.sh') }}
42-
43-
- name: Install LLVM 16
44-
run: |
45-
sudo apt-get update
46-
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
47-
sudo add-apt-repository -y 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main'
48-
sudo apt-get install -y llvm-16 llvm-16-dev
49-
50-
- name: Build LLFuzz
51-
run: |
52-
./build.sh || eval $(opam env) && make
53-
54-
- name: Run test
55-
run: |
56-
eval $(opam env) && make test
39+
path: /opt/llvm-project
40+
key: ${{ env.llvm-cache-name }}-${{ hashFiles('build.sh') }}
41+
42+
43+
- name: Install dependencies
44+
run:
45+
sudo apt-get update && sudo apt-get install -y re2c z3
46+
47+
- name: Build Optimuzz
48+
run: ./build.sh
49+
env:
50+
LLVM_PATH: /opt/llvm-project/
51+
52+
- name: Check Instrumentation Build
53+
run: make -C instrumentation
54+
env:
55+
LLVM_PATH: /opt/llvm-project/

.gitignore

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,6 @@ setup.log
2929
# Mac
3030
.DS_Store
3131

32-
# executables
33-
llfuzz
34-
check_corpus
35-
cov
36-
pattern-check
37-
clean
38-
alive-tv
39-
llmutate
40-
distance
41-
fuzzer
42-
4332
# llvm files
4433
*.bc
4534
*.ll
@@ -74,4 +63,5 @@ memo/
7463

7564
llfuzz-out
7665
*.tar
77-
compile_flags.txt
66+
compile_flags.txt
67+
commit.json

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "alive2"]
22
path = alive2
3-
url = git@github.com:AliveToolkit/alive2.git
3+
url = https://github.com/AliveToolkit/alive2.git

Dockerfile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM ubuntu:24.04
2+
3+
########## Dependencies ##########
4+
5+
RUN apt-get update
6+
7+
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y cmake ninja-build re2c opam libz3-dev z3
8+
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y sudo git python3.12 python3-pip pkg-config libcairo2-dev libssl-dev libreadline-dev
9+
10+
########## Dependencies Ends ##########
11+
12+
# Setup Working Environment
13+
14+
RUN groupadd user
15+
RUN useradd -g user -m -d /home/user user
16+
RUN usermod -aG sudo user
17+
RUN echo "user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
18+
19+
ENV TERM xterm-256color
20+
21+
WORKDIR /home/user
22+
RUN chown -R user:user /home/user && chmod -R 755 /home/user
23+
24+
USER user
25+
26+
COPY --chown=user:user . optimuzz
27+
28+
WORKDIR /home/user/optimuzz
29+
ENV LLVM_PATH /home/user/llvm-project
30+
ENV LLVM_BUILDS /home/user/llvm-builds

Makefile

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,13 @@ EXE=fuzzer
66

77
.PHONY: clean
88

9-
all: fmt
10-
$(DUNE) build
11-
$(LN) _build/default/src/main.exe $(EXE)
12-
$(LN) _build/default/src/check_corpus.exe check_corpus
13-
$(LN) _build/default/src/llmutate.exe llmutate
9+
all:
10+
$(DUNE) build -p optimuzz
11+
dune install
1412

1513
test: all
1614
$(DUNE) test
1715

18-
fmt:
19-
- $(DUNE) fmt
20-
2116
clean:
2217
$(DUNE) clean
2318
$(RM) -rf $(EXE) *.txt

README.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,41 @@ Our recent development is avaiable at [our website](https://prosys.kaist.ac.kr/o
66

77
## Installation
88

9-
The script below installs the followings:
9+
### Quick Start
10+
11+
We provide [Dockerfile](Dockerfile) which installs the system dependencies and configures the environment variables.
12+
13+
```bash
14+
docker build -t . optimuzz
15+
docker run -it optimuzz
16+
17+
# Inside the docker
18+
echo $PWD # /home/user/optimuzz
19+
./build.sh
20+
```
21+
22+
### Environment Variables
23+
24+
* `LLVM_PATH`: The LLVM project directory. We use clang/llvm toolchains and libraries to build Optimuzz, Alive2, and other LLVM versions under test.
25+
* `LLVM_BUILDS`: LLVM versions under test will be installed under this directory.
26+
27+
Note that we use LLVM 20.1.1.
28+
29+
### Build Script
30+
31+
The script `build.sh` installs the followings:
1032
* the required OPAM packages
1133
* LLVM 20 with the OCaml bindings
1234
* Alive2
35+
* Optimuzz toolchain (`fuzzer` and `llmutate`)
1336

14-
```bash
15-
export LLVM_PATH=$HOME/llvm-project # or your favorite
16-
build.sh
17-
```
1837

19-
## Usage
38+
## Optimuzz Toolchain
2039

2140
We provide following tools to employ Optimuzz.
2241

2342
```sh
2443
# Build LLVM with our instrumentation pass
25-
export LLVM_BUILDS=$HOME/llvm-builds # or your favorite to store the LLVM project builds
2644
$ tools/build.py commit <commit-sha> <target-file> [--fresh]
2745
$LLVM_BUILDS/llvm-builds/<commit-sha>/build/bin/opt
2846

build.sh

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,71 @@ else
2323
fi
2424

2525
eval $(SHELL=bash opam env --switch=$OPTIMUZZ_OPAM_SWITCH)
26+
export OPAMSWITCH=$OPTIMUZZ_OPAM_SWITCH
2627
opam pin https://github.com/prosyslab/logger.git
27-
opam install -j $NCPU dune ctypes domainslib progress ocamlgraph ocamlformat merlin ocp-index ocp-indent ocaml-lsp-server
28-
scripts/llvm20.sh
29-
scripts/alive.sh
28+
opam install -j $NCPU dune ctypes ocamlgraph ocamlformat merlin ocp-index ocp-indent ocaml-lsp-server
29+
30+
if [ -z "$LLVM_PATH" ]; then
31+
echo "LLVM_PATH is not set. Please set it to the path of your LLVM installation."
32+
exit 1
33+
fi
34+
35+
install_llvm() {
36+
git clone https://github.com/llvm/llvm-project.git $LLVM_PATH
37+
pushd $LLVM_PATH
38+
git checkout llvmorg-20.1.1
39+
mkdir -p build
40+
pushd build
41+
# Alive2 requires ASSERTIONS to be enabled
42+
cmake -G Ninja ../llvm \
43+
-DLLVM_ENABLE_PROJECTS="llvm;lld;clang" \
44+
-DLLVM_ENABLE_BINDINGS=ON \
45+
-DCMAKE_BUILD_TYPE=Release \
46+
-DLLVM_ENABLE_RTTI=ON \
47+
-DLLVM_ENABLE_ASSERTIONS=ON \
48+
-DLLVM_ENABLE_SPHINX=OFF \
49+
-DLLVM_ENABLE_DOXYGEN=OFF \
50+
-DLLVM_ENABLE_OCAMLDOC=OFF \
51+
-DLLVM_TARGETS_TO_BUILD="X86" \
52+
-DLLVM_OCAML_INSTALL_PATH="$(opam var lib)"
53+
ninja
54+
55+
# This installs LLVM-20 bindings to the current opam switch
56+
sudo ninja install
57+
popd
58+
popd
59+
}
60+
61+
62+
install_alive2() {
63+
git submodule update --init --remote alive2
64+
pushd alive2
65+
git checkout v20.0
66+
67+
rm -rf build
68+
mkdir -p build
69+
70+
pushd build
71+
cmake -GNinja -DCMAKE_PREFIX_PATH="$LLVM_PATH" -DBUILD_TV=1 -DCMAKE_BUILD_TYPE=Release ..
72+
ninja
73+
sudo ninja install
74+
popd
75+
popd
76+
}
77+
78+
79+
echo "LLVM_PATH: $LLVM_PATH"
80+
81+
if [ ! -x "$LLVM_PATH/build/bin/opt" ]; then
82+
echo "No LLVM is found built. Installing LLVM..."
83+
install_llvm
84+
else
85+
echo "Built LLVM found. Skipping LLVM build."
86+
pushd $LLVM_PATH/build
87+
sudo ninja install
88+
popd
89+
fi
90+
91+
install_alive2
3092

3193
make
32-
# opam install -j $NCPU llvm.16.0.6+nnp
33-
# make

optimuzz.install

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
lib: [
2+
"_build/install/default/lib/optimuzz/META"
3+
"_build/install/default/lib/optimuzz/dune-package"
4+
"_build/install/default/lib/optimuzz/opam"
5+
]
6+
bin: [
7+
"_build/install/default/bin/fuzzer"
8+
"_build/install/default/bin/llmutate"
9+
]
10+
doc: [
11+
"_build/install/default/doc/optimuzz/README.md"
12+
]

optimuzz.opam

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
opam-version: "2.0"
2+
name: "optimuzz"
3+
version: "0.1"
4+
maintainer: "[email protected]"
5+
authors: ["Jaeseong Kwon" "Bongjun Jang" "Kihong Heo"]
6+
homepage: "https://github.com/prosyslab/optimuzz"
7+
bug-reports: "https://github.com/prosyslab/optimuzz/issues"
8+
dev-repo: "git+https://github.com/prosyslab/optimuzz.git"
9+
10+
depends: [
11+
"ocaml" {>= "5.3.0"}
12+
"dune" {>= "3.12"}
13+
"ctypes" {>= "0.23.0"}
14+
"ocamlgraph" {>= "2.1.0"}
15+
]
16+
17+
build: [
18+
["dune" "build" "-p" name "-j" jobs]
19+
]
20+
21+
install: [
22+
["dune" "install" "-p" name]
23+
]

0 commit comments

Comments
 (0)