-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbuild-native.sh
More file actions
executable file
·185 lines (157 loc) · 4.77 KB
/
build-native.sh
File metadata and controls
executable file
·185 lines (157 loc) · 4.77 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/bash
set -euo pipefail
#
# Build script for GraalVM native image of nf-language-server
# Supports: linux/amd64, linux/arm64, macos/amd64, macos/arm64 (Apple Silicon)
#
# Usage:
# ./build-native.sh [options]
#
# Options:
# --skip-test Skip testing the native binary
# --help, -h Show this help message
#
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Colors for output (disabled in CI)
if [[ -t 1 ]] && [[ -z "${CI:-}" ]]; then
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
else
RED=''
GREEN=''
YELLOW=''
NC=''
fi
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check for required tools
check_requirements() {
log_info "Checking requirements..."
# Check for Java
if ! command -v java &> /dev/null; then
log_error "Java is not installed or not in PATH"
exit 1
fi
JAVA_VERSION=$(java -version 2>&1 | head -1 | cut -d'"' -f2 | cut -d'.' -f1)
if [[ "$JAVA_VERSION" -lt 17 ]]; then
log_error "Java 17+ is required, found version $JAVA_VERSION"
exit 1
fi
# Check for native-image
if ! command -v native-image &> /dev/null; then
# Try to find it in JAVA_HOME
if [[ -n "${JAVA_HOME:-}" ]] && [[ -x "$JAVA_HOME/bin/native-image" ]]; then
export PATH="$JAVA_HOME/bin:$PATH"
elif [[ -n "${GRAALVM_HOME:-}" ]] && [[ -x "$GRAALVM_HOME/bin/native-image" ]]; then
export PATH="$GRAALVM_HOME/bin:$PATH"
export JAVA_HOME="$GRAALVM_HOME"
else
log_error "native-image not found. Please install GraalVM with native-image support."
log_error "You can use SDKMAN: sdk install java 21.0.1-graal && sdk use java 21.0.1-graal"
exit 1
fi
fi
# Verify native-image works
if ! native-image --version &> /dev/null; then
log_error "native-image is not working correctly"
exit 1
fi
log_info "Using Java: $(java -version 2>&1 | head -1)"
log_info "Using native-image: $(native-image --version 2>&1 | head -1)"
}
# Detect platform
detect_platform() {
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
case "$OS" in
linux|darwin)
BINARY_EXT=""
;;
mingw*|msys*|cygwin*)
BINARY_EXT=".exe"
;;
*)
log_error "Unsupported OS: $OS"
exit 1
;;
esac
}
# Build native image (includes shadow jar, tracing agent, and native compilation)
build_native_image() {
log_info "Building native image (this includes JAR build and tracing agent)..."
./gradlew nativeCompile --no-configuration-cache --no-daemon
local BINARY_PATH="build/native/nativeCompile/nlsp${BINARY_EXT}"
if [[ -f "$BINARY_PATH" ]]; then
log_info "Native image built successfully: $BINARY_PATH"
ls -lh "$BINARY_PATH"
else
log_error "Native image build failed - binary not found"
exit 1
fi
}
# Test the native binary
test_native_binary() {
log_info "Testing native binary..."
local BINARY_PATH="build/native/nativeCompile/nlsp${BINARY_EXT}"
local OUTPUT
OUTPUT=$(./lsp-simulator.sh | "$BINARY_PATH" 2>&1 | head -20)
if echo "$OUTPUT" | grep -q '"id":1,"result"'; then
log_info "Native binary test passed - LSP initialize succeeded"
else
log_error "Native binary test failed"
echo "$OUTPUT"
exit 1
fi
}
# Main build process
main() {
local SKIP_TEST=false
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
--skip-test)
SKIP_TEST=true
shift
;;
--help|-h)
echo "Usage: $0 [options]"
echo ""
echo "Build GraalVM native image for nf-language-server"
echo ""
echo "Options:"
echo " --skip-test Skip testing the native binary"
echo " --help, -h Show this help message"
echo ""
echo "Requirements:"
echo " - GraalVM 21+ with native-image"
echo " - Use SDKMAN: sdk install java 21.0.1-graal"
exit 0
;;
*)
log_error "Unknown option: $1"
exit 1
;;
esac
done
log_info "Starting native image build..."
echo ""
check_requirements
detect_platform
build_native_image
if [[ "$SKIP_TEST" != "true" ]]; then
test_native_binary
fi
echo ""
log_info "Build completed successfully!"
log_info "Binary: build/native/nativeCompile/nlsp${BINARY_EXT}"
}
main "$@"