forked from ethereum/ethash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·94 lines (79 loc) · 3.06 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·94 lines (79 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
# Build the ethash project.
#
# Usage:
# ./build.sh # incremental build (C + Go)
# ./build.sh --clean # wipe build dir first, then full rebuild
set -e
REPO_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
BUILD_DIR="$REPO_ROOT/build"
# Parse flags — use a loop so order doesn't matter
DO_CLEAN=0
DO_BENCH=0
for arg in "$@"; do
case "$arg" in
--clean) DO_CLEAN=1 ;;
--bench) DO_BENCH=1 ;;
*) echo "[build] Unknown argument: $arg"; exit 1 ;;
esac
done
if [[ "$DO_CLEAN" -eq 1 ]]; then
echo "[build] Removing $BUILD_DIR"
rm -rf "$BUILD_DIR"
fi
# ---------------------------------------------------------------------------
# C/C++ build (cmake → libethash.a + Test binary + Python extension)
# ---------------------------------------------------------------------------
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
cmake "$REPO_ROOT" -DCMAKE_BUILD_TYPE=Release > /dev/null 2>&1 || {
# On failure re-run without redirection so the error is visible
cmake "$REPO_ROOT" -DCMAKE_BUILD_TYPE=Release
exit 1
}
# Touch C source files modified via WSL on an NTFS mount to work around clock
# skew that prevents make from detecting changes.
if grep -q "microsoft\|WSL" /proc/version 2>/dev/null; then
touch "$REPO_ROOT/src/libethash/internal.c"
touch "$REPO_ROOT/src/python/core.c"
fi
make
echo "[build/c] Done — binaries in $BUILD_DIR"
# Build benchmark binaries if --bench flag is passed
if [[ "$DO_BENCH" -eq 1 ]]; then
echo "[build/bench] Building benchmark binaries..."
make Benchmark_LIGHT Benchmark_FULL
echo "[build/bench] Done — binaries in $BUILD_DIR/src/benchmark/"
fi
# ---------------------------------------------------------------------------
# Go build (CGo; compiles its own copy of the C sources via ethashc.go)
# ---------------------------------------------------------------------------
cd "$REPO_ROOT"
if [ ! -f go.mod ]; then
echo "[build/go] go.mod not found, skipping Go build"
else
echo "[build/go] Building Go package..."
go build ./...
echo "[build/go] Done"
# Verify the package compiles cleanly with vet as well
echo "[build/go] Running go vet..."
go vet ./...
echo "[build/go] vet passed"
fi
touch "$BUILD_DIR/.built"
# ---------------------------------------------------------------------------
# Python extension build (compiles src/python/core.c via pip editable install)
# ---------------------------------------------------------------------------
PYTHON_TEST_DIR="$REPO_ROOT/test/python"
VENV_DIR="$PYTHON_TEST_DIR/python-virtual-env"
echo "[build/python] Setting up venv and building pyethash extension..."
[ -d "$VENV_DIR" ] || python3 -m venv "$VENV_DIR"
source "$VENV_DIR/bin/activate"
pip install -r "$PYTHON_TEST_DIR/requirements.txt" -q
# --no-build-isolation: reuse the already-activated venv's build tools rather
# than spawning an isolated env; this also ensures the compiled extension ends
# up inside the venv so pytest can import it.
pip install -e "$REPO_ROOT" -q --no-build-isolation
deactivate
echo "[build/python] Done"
echo "[build] All done"