Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions crates/libafl_nyx/build.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
use std::process::Command;

use std::{env, path::PathBuf, process::Command};
fn main() {
if cfg!(target_os = "linux") && cfg!(target_arch = "x86_64") && !cfg!(doc) {
// Use CARGO_TARGET_DIR if available, otherwise fall back to OUT_DIR's parent directories
let target_dir = if let Ok(target_dir) = env::var("CARGO_TARGET_DIR") {
PathBuf::from(target_dir)
} else {
// OUT_DIR is usually $TARGET/{debug|release}/build/$PKG-$HASH/out
// We want $TARGET/{debug|release}
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
out_dir
.ancestors()
.nth(3) // This is still a fallback, but at least we try CARGO_TARGET_DIR first
.map(std::path::Path::to_path_buf)
.expect("Failed to determine target directory from OUT_DIR")
};
println!("cargo:rerun-if-changed=build.rs");
// let output = Command::new("./build_nyx_support.sh").output().expect("can't run ./build_nyx_support.sh");
let status = Command::new("./build_nyx_support.sh")
.arg(target_dir)
.status()
.expect("can't run ./build_nyx_support.sh");
if status.success() {
Expand Down
13 changes: 11 additions & 2 deletions crates/libafl_nyx/build_nyx_support.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
#!/bin/bash

if [ -z "$1" ]; then
echo "Usage: $0 <target-directory>"
exit 1
fi

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

TARGET_DIR="$1"
mkdir -p "$TARGET_DIR"
cd "$TARGET_DIR" || exit 1

echo "================================================="
echo " Nyx build script"
echo "================================================="
Expand Down Expand Up @@ -44,8 +53,8 @@ echo "[*] Checking QEMU-Nyx ..."
if [ ! -f "QEMU-Nyx/x86_64-softmmu/qemu-system-x86_64" ]; then
cd QEMU-Nyx/ || return
# We need to copy our custom `Makefile.libxdc` after `git submodule update`, otherwise we get a git error.
sed -i "s,git submodule update libxdc$,git submodule update libxdc \&\& cp ../Makefile.libxdc ./libxdc/Makefile || exit 1," compile_qemu_nyx.sh
./compile_qemu_nyx.sh lto || exit 1
sed -i "s,git submodule update libxdc$,git submodule update libxdc \&\& cp \"\$SCRIPT_DIR\"/Makefile.libxdc ./libxdc/Makefile || exit 1," compile_qemu_nyx.sh
./compile_qemu_nyx.sh lto
cd ..
fi

Expand Down
2 changes: 1 addition & 1 deletion fuzzers/full_system/nyx_libxml2_parallel/setup_libxml2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ cd ./libxml2/ || exit
./autogen.sh --enable-shared=no || exit
make -j || exit
cd - || exit
python3 "../../../crates/libafl_nyx/packer/packer/nyx_packer.py" \
python3 "./target/release/packer/packer/nyx_packer.py" \
./libxml2/xmllint \
/tmp/nyx_libxml2 \
afl \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ cd ./libxml2/ || exit
./autogen.sh --enable-shared=no || exit
make -j || exit
cd - || exit
python3 "../../../crates/libafl_nyx/packer/packer/nyx_packer.py" \
python3 "./target/release/packer/packer/nyx_packer.py" \
./libxml2/xmllint \
/tmp/nyx_libxml2 \
afl \
Expand Down
Loading