Skip to content

Commit 12d8f65

Browse files
authored
Merge pull request #7 from CVanF5/linux-fixes
Linux fixes
2 parents 53eacdb + a3c8438 commit 12d8f65

File tree

7 files changed

+210
-28
lines changed

7 files changed

+210
-28
lines changed

Makefile

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,17 @@ deploy:
9494

9595
start-local: build-check
9696
@echo "Starting mock external processor..."
97-
@pkill -f "extproc_mock" || true
98-
@EPP_UPSTREAM=localhost:8080 MOCK_ROLE=EPP ./target/debug/extproc_mock 0.0.0.0:9001 &
97+
@-kill $$(cat /tmp/extproc_mock.pid 2>/dev/null) 2>/dev/null || true
98+
@rm -f /tmp/extproc_mock.pid
99+
@(EPP_UPSTREAM=localhost:8080 MOCK_ROLE=EPP ./target/debug/extproc_mock 0.0.0.0:9001 >/dev/null 2>&1 & echo $$! > /tmp/extproc_mock.pid) || true
100+
@sleep 1
99101
@echo "Starting echo server..."
100-
@pkill -f "custom-echo-server.js" || true
102+
@-kill $$(cat /tmp/echo-server.pid 2>/dev/null) 2>/dev/null || true
103+
@rm -f /tmp/echo-server.pid
101104
@cd docker/echo-server && [ ! -f package.json ] && npm init -y >/dev/null 2>&1 || true
102105
@cd docker/echo-server && [ ! -d node_modules ] && npm install express >/dev/null 2>&1 || true
103-
@cd docker/echo-server && PORT=8080 node custom-echo-server.js &
106+
@(cd docker/echo-server && PORT=8080 node custom-echo-server.js >/dev/null 2>&1 & echo $$! > /tmp/echo-server.pid) || true
107+
@sleep 1
104108

105109
setup-local:
106110
./tests/setup-local-dev.sh --local
@@ -109,11 +113,11 @@ setup-docker:
109113
./tests/setup-local-dev.sh --docker
110114

111115
stop:
112-
docker compose -f $(DOCKER_COMPOSE_MAIN) down --remove-orphans
113-
# Stop local processes
116+
@docker compose -f $(DOCKER_COMPOSE_MAIN) down --remove-orphans 2>/dev/null || true
114117
ifndef GITHUB_ACTIONS
115-
pkill -f "custom-echo-server.js" 2>/dev/null || true
116-
pkill -f "extproc_mock" 2>/dev/null || true
118+
@-kill $$(cat /tmp/echo-server.pid 2>/dev/null) 2>/dev/null || true
119+
@-kill $$(cat /tmp/extproc_mock.pid 2>/dev/null) 2>/dev/null || true
120+
@rm -f /tmp/extproc_mock.pid /tmp/echo-server.pid 2>/dev/null || true
117121
endif
118122

119123

@@ -126,7 +130,6 @@ else
126130
endif
127131

128132
test-docker:
129-
@echo "Starting main docker services with build..."
130133
docker compose -f $(DOCKER_COMPOSE_MAIN) up --build -d
131134
DOCKER_ENVIRONMENT=main ./tests/test-config.sh
132135

@@ -173,4 +176,4 @@ help:
173176
@echo "EXAMPLES:"
174177
@echo " make start # Start full stack"
175178
@echo " make test TEST_ENV=local # Run local tests"
176-
@echo " make generate-config OUTPUT=/tmp/nginx.conf ENV=local TEST=bbr_on_epp_off"
179+
@echo " make generate-config OUTPUT=/tmp/nginx.conf ENV=local TEST=bbr_on_epp_off"

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn cstr_ptr(s: *const u8) -> *const c_char {
3434
#[cfg(not(target_os = "macos"))]
3535
#[inline]
3636
fn cstr_ptr(s: *const u8) -> *const c_char {
37-
s as *const u8 as *const c_char
37+
s as *const c_char
3838
}
3939

4040
// NGINX module for Gateway API inference extensions.

src/modules/bbr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn cstr_ptr(s: *const u8) -> *const c_char {
1616
#[cfg(not(target_os = "macos"))]
1717
#[inline]
1818
fn cstr_ptr(s: *const u8) -> *const c_char {
19-
s as *const u8 as *const c_char
19+
s as *const c_char
2020
}
2121

2222
/// Get an incoming request header value by name (case-insensitive).

tests/configs/nginx-base.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ events {
2020
}
2121

2222
http {
23-
include /opt/homebrew/etc/nginx/mime.types;
23+
include MIMETYPES_PATH_PLACEHOLDER;
2424
default_type application/octet-stream;
2525

2626
log_format main '$remote_addr - $remote_user [$time_local] "$request" '

tests/generate-config.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,14 @@ fi
8888
if [[ "$ENVIRONMENT" == "local" ]]; then
8989
if [[ "$(uname)" == "Darwin" ]]; then
9090
MODULE_PATH="$PROJECT_ROOT/target/debug/libngx_inference.dylib"
91+
MIMETYPES_PATH="/opt/homebrew/etc/nginx/mime.types"
9192
else
9293
MODULE_PATH="$PROJECT_ROOT/target/debug/libngx_inference.so"
94+
MIMETYPES_PATH="/etc/nginx/mime.types"
9395
fi
9496
else
9597
MODULE_PATH="/usr/lib/nginx/modules/libngx_inference.so"
98+
MIMETYPES_PATH="/etc/nginx/mime.types"
9699
fi
97100

98101
# Validate template file exists
@@ -105,6 +108,7 @@ echo "Generating nginx configuration..."
105108
echo " Environment: $ENVIRONMENT"
106109
echo " Template: $TEMPLATE"
107110
echo " Module path: $MODULE_PATH"
111+
echo " Mime types path: $MIMETYPES_PATH"
108112
echo " Output: $OUTPUT_FILE"
109113

110114
# Create output directory if it doesn't exist
@@ -125,6 +129,7 @@ if [[ -n "$SERVER_CONFIG" ]]; then
125129
# Replace all placeholders
126130
sed -e "s|TEST_SERVER_CONFIG_PLACEHOLDER|${SERVER_CONFIG_FILE}|g" \
127131
-e "s|MODULE_PATH_PLACEHOLDER|${MODULE_PATH}|g" \
132+
-e "s|MIMETYPES_PATH_PLACEHOLDER|${MIMETYPES_PATH}|g" \
128133
-e "s|RESOLVER_PLACEHOLDER|${RESOLVER}|g" \
129134
"$TEMPLATE" > "$OUTPUT_FILE"
130135
else
@@ -133,6 +138,7 @@ else
133138

134139
# Just replace module and resolver placeholders
135140
sed -e "s|MODULE_PATH_PLACEHOLDER|${MODULE_PATH}|g" \
141+
-e "s|MIMETYPES_PATH_PLACEHOLDER|${MIMETYPES_PATH}|g" \
136142
-e "s|RESOLVER_PLACEHOLDER|${RESOLVER}|g" \
137143
"$TEMPLATE" > "$OUTPUT_FILE"
138144
fi

tests/setup-local-dev.sh

Lines changed: 180 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ fi
6363
echo -e "${YELLOW}Setting up for ${ENVIRONMENT} development...${NC}"
6464
echo ""
6565

66+
# Detect OS and package manager
67+
detect_os() {
68+
if [[ -f /etc/os-release ]]; then
69+
. /etc/os-release
70+
OS=$ID
71+
OS_VERSION=$VERSION_ID
72+
elif [[ "$(uname)" == "Darwin" ]]; then
73+
OS="macos"
74+
else
75+
OS="unknown"
76+
fi
77+
}
78+
79+
detect_os
80+
6681
# Common tools check
6782
echo -e "${YELLOW}Checking common tools...${NC}"
6883
tools_missing=0
@@ -72,9 +87,9 @@ if command -v curl >/dev/null 2>&1; then
7287
echo -e "${GREEN}✓ curl found: $(curl --version | head -n1)${NC}"
7388
else
7489
echo -e "${RED}✗ curl not found - please install curl${NC}"
75-
if [[ "$(uname)" == "Darwin" ]]; then
90+
if [[ "$OS" == "macos" ]]; then
7691
echo " brew install curl"
77-
elif [[ "$(uname)" == "Linux" ]]; then
92+
elif [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
7893
echo " sudo apt-get install curl"
7994
fi
8095
tools_missing=1
@@ -85,9 +100,9 @@ if command -v jq >/dev/null 2>&1; then
85100
echo -e "${GREEN}✓ jq found: $(jq --version)${NC}"
86101
else
87102
echo -e "${RED}✗ jq not found - please install jq for JSON parsing${NC}"
88-
if [[ "$(uname)" == "Darwin" ]]; then
103+
if [[ "$OS" == "macos" ]]; then
89104
echo " brew install jq"
90-
elif [[ "$(uname)" == "Linux" ]]; then
105+
elif [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
91106
echo " sudo apt-get install jq"
92107
fi
93108
tools_missing=1
@@ -104,12 +119,11 @@ if [[ "$ENVIRONMENT" == "local" ]]; then
104119
echo -e "${GREEN}✓ nginx found: $CURRENT_VERSION${NC}"
105120
else
106121
echo -e "${RED}✗ nginx not found - please install nginx${NC}"
107-
if [[ "$(uname)" == "Darwin" ]]; then
122+
if [[ "$OS" == "macos" ]]; then
108123
echo " brew install nginx"
109-
elif [[ "$(uname)" == "Linux" ]]; then
110-
echo " # Ubuntu/Debian:"
124+
elif [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
111125
echo " sudo apt-get install nginx"
112-
echo " # CentOS/RHEL:"
126+
elif [[ "$OS" == "centos" || "$OS" == "rhel" || "$OS" == "fedora" ]]; then
113127
echo " sudo yum install nginx"
114128
fi
115129
tools_missing=1
@@ -120,14 +134,10 @@ if [[ "$ENVIRONMENT" == "local" ]]; then
120134
echo -e "${GREEN}✓ node found: $(node --version)${NC}"
121135
else
122136
echo -e "${RED}✗ node not found - please install Node.js for echo server${NC}"
123-
if [[ "$(uname)" == "Darwin" ]]; then
137+
if [[ "$OS" == "macos" ]]; then
124138
echo " brew install node"
125-
elif [[ "$(uname)" == "Linux" ]]; then
126-
echo " # Ubuntu/Debian:"
139+
elif [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
127140
echo " sudo apt-get install nodejs npm"
128-
echo " # Or use NodeSource:"
129-
echo " curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -"
130-
echo " sudo apt-get install -y nodejs"
131141
fi
132142
tools_missing=1
133143
fi
@@ -150,6 +160,152 @@ if [[ "$ENVIRONMENT" == "local" ]]; then
150160
tools_missing=1
151161
fi
152162

163+
echo ""
164+
echo -e "${YELLOW}Checking Rust build dependencies...${NC}"
165+
166+
# Check clang/LLVM (required for bindgen)
167+
if command -v clang >/dev/null 2>&1; then
168+
echo -e "${GREEN}✓ clang found: $(clang --version | head -n1)${NC}"
169+
else
170+
echo -e "${RED}✗ clang not found - required for Rust bindgen${NC}"
171+
if [[ "$OS" == "macos" ]]; then
172+
echo " xcode-select --install"
173+
elif [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
174+
echo " sudo apt-get install clang"
175+
elif [[ "$OS" == "alpine" ]]; then
176+
echo " apk add clang-dev"
177+
elif [[ "$OS" == "centos" || "$OS" == "rhel" || "$OS" == "fedora" ]]; then
178+
echo " sudo dnf install clang"
179+
fi
180+
tools_missing=1
181+
fi
182+
183+
# Check PCRE2 development files
184+
pcre2_found=false
185+
if [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
186+
if dpkg -l | grep -q libpcre2-dev; then
187+
echo -e "${GREEN}✓ libpcre2-dev found${NC}"
188+
pcre2_found=true
189+
fi
190+
elif [[ "$OS" == "macos" ]]; then
191+
if brew list pcre2 &>/dev/null; then
192+
echo -e "${GREEN}✓ pcre2 found${NC}"
193+
pcre2_found=true
194+
fi
195+
elif [[ "$OS" == "centos" || "$OS" == "rhel" || "$OS" == "fedora" ]]; then
196+
if rpm -q pcre2-devel &>/dev/null; then
197+
echo -e "${GREEN}✓ pcre2-devel found${NC}"
198+
pcre2_found=true
199+
fi
200+
fi
201+
202+
if [[ "$pcre2_found" == "false" ]]; then
203+
echo -e "${RED}✗ PCRE2 development files not found - required for nginx module build${NC}"
204+
if [[ "$OS" == "macos" ]]; then
205+
echo " brew install pcre2"
206+
elif [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
207+
echo " sudo apt-get install libpcre2-dev"
208+
elif [[ "$OS" == "alpine" ]]; then
209+
echo " apk add pcre2-dev"
210+
elif [[ "$OS" == "centos" || "$OS" == "rhel" || "$OS" == "fedora" ]]; then
211+
echo " sudo dnf install pcre2-devel"
212+
fi
213+
tools_missing=1
214+
fi
215+
216+
# Check OpenSSL development files
217+
openssl_found=false
218+
if [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
219+
if dpkg -l | grep -q libssl-dev; then
220+
echo -e "${GREEN}✓ libssl-dev found${NC}"
221+
openssl_found=true
222+
fi
223+
elif [[ "$OS" == "macos" ]]; then
224+
if brew list openssl &>/dev/null; then
225+
echo -e "${GREEN}✓ openssl found${NC}"
226+
openssl_found=true
227+
fi
228+
elif [[ "$OS" == "centos" || "$OS" == "rhel" || "$OS" == "fedora" ]]; then
229+
if rpm -q openssl-devel &>/dev/null; then
230+
echo -e "${GREEN}✓ openssl-devel found${NC}"
231+
openssl_found=true
232+
fi
233+
fi
234+
235+
if [[ "$openssl_found" == "false" ]]; then
236+
echo -e "${RED}✗ OpenSSL development files not found - required for nginx module build${NC}"
237+
if [[ "$OS" == "macos" ]]; then
238+
echo " brew install openssl"
239+
elif [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
240+
echo " sudo apt-get install libssl-dev"
241+
elif [[ "$OS" == "alpine" ]]; then
242+
echo " apk add openssl-dev"
243+
elif [[ "$OS" == "centos" || "$OS" == "rhel" || "$OS" == "fedora" ]]; then
244+
echo " sudo dnf install openssl-devel"
245+
fi
246+
tools_missing=1
247+
fi
248+
249+
# Check zlib development files
250+
zlib_found=false
251+
if [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
252+
if dpkg -l | grep -q zlib1g-dev; then
253+
echo -e "${GREEN}✓ zlib1g-dev found${NC}"
254+
zlib_found=true
255+
fi
256+
elif [[ "$OS" == "macos" ]]; then
257+
if brew list zlib &>/dev/null; then
258+
echo -e "${GREEN}✓ zlib found${NC}"
259+
zlib_found=true
260+
fi
261+
elif [[ "$OS" == "centos" || "$OS" == "rhel" || "$OS" == "fedora" ]]; then
262+
if rpm -q zlib-devel &>/dev/null; then
263+
echo -e "${GREEN}✓ zlib-devel found${NC}"
264+
zlib_found=true
265+
fi
266+
fi
267+
268+
if [[ "$zlib_found" == "false" ]]; then
269+
echo -e "${RED}✗ zlib development files not found - required for nginx gzip module${NC}"
270+
if [[ "$OS" == "macos" ]]; then
271+
echo " brew install zlib"
272+
elif [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
273+
echo " sudo apt-get install zlib1g-dev"
274+
elif [[ "$OS" == "alpine" ]]; then
275+
echo " apk add zlib-dev"
276+
elif [[ "$OS" == "centos" || "$OS" == "rhel" || "$OS" == "fedora" ]]; then
277+
echo " sudo dnf install zlib-devel"
278+
fi
279+
tools_missing=1
280+
fi
281+
282+
# Check make
283+
if command -v make >/dev/null 2>&1; then
284+
echo -e "${GREEN}✓ make found: $(make --version | head -n1)${NC}"
285+
else
286+
echo -e "${RED}✗ make not found - required for nginx module build${NC}"
287+
if [[ "$OS" == "macos" ]]; then
288+
echo " xcode-select --install"
289+
elif [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
290+
echo " sudo apt-get install build-essential"
291+
elif [[ "$OS" == "alpine" ]]; then
292+
echo " apk add make"
293+
elif [[ "$OS" == "centos" || "$OS" == "rhel" || "$OS" == "fedora" ]]; then
294+
echo " sudo dnf install make"
295+
fi
296+
tools_missing=1
297+
fi
298+
299+
# Optional: Check pkg-config (helpful for finding libraries)
300+
if command -v pkg-config >/dev/null 2>&1; then
301+
echo -e "${GREEN}✓ pkg-config found: $(pkg-config --version)${NC}"
302+
else
303+
echo -e "${YELLOW}⚠ pkg-config not found - optional but recommended${NC}"
304+
if [[ "$OS" == "debian" || "$OS" == "ubuntu" ]]; then
305+
echo " sudo apt-get install pkg-config"
306+
fi
307+
fi
308+
153309
elif [[ "$ENVIRONMENT" == "docker" ]]; then
154310
echo -e "${YELLOW}Checking Docker development requirements...${NC}"
155311

@@ -235,6 +391,15 @@ else
235391
echo -e "${RED}✗ Some required tools are missing for ${ENVIRONMENT} development${NC}"
236392
echo " Please install the missing tools and run this script again."
237393
echo ""
394+
395+
# Provide a quick install command for Debian/Ubuntu
396+
if [[ "$ENVIRONMENT" == "local" && ("$OS" == "debian" || "$OS" == "ubuntu") ]]; then
397+
echo -e "${YELLOW}Quick install for Debian/Ubuntu:${NC}"
398+
echo " sudo apt-get update"
399+
echo " sudo apt-get install -y clang libpcre2-dev libssl-dev zlib1g-dev build-essential pkg-config"
400+
echo ""
401+
fi
402+
238403
echo " You can also try the other environment:"
239404
if [[ "$ENVIRONMENT" == "local" ]]; then
240405
echo " $0 --docker # Setup for Docker-based testing"
@@ -243,4 +408,4 @@ else
243408
fi
244409
fi
245410

246-
exit $tools_missing
411+
exit $tools_missing

tests/test-config.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,23 @@ create_config_from_template() {
143143
local module_path="$LOCAL_MODULE_PATH"
144144
local resolver="$CACHED_RESOLVER"
145145

146+
# Determine mime.types path based on OS
147+
local mimetypes_path="/etc/nginx/mime.types"
148+
if [[ "$(uname)" == "Darwin" ]]; then
149+
mimetypes_path="/opt/homebrew/etc/nginx/mime.types"
150+
fi
151+
146152
if [[ -n "$server_config" ]]; then
147153
# Replace all placeholders
148154
sed -e "s|TEST_SERVER_CONFIG_PLACEHOLDER|${server_config}|g" \
149155
-e "s|MODULE_PATH_PLACEHOLDER|${module_path}|g" \
156+
-e "s|MIMETYPES_PATH_PLACEHOLDER|${mimetypes_path}|g" \
150157
-e "s|RESOLVER_PLACEHOLDER|${resolver}|g" \
151158
"$template_file" > "$output_file"
152159
else
153160
# Replace module and resolver placeholders
154161
sed -e "s|MODULE_PATH_PLACEHOLDER|${module_path}|g" \
162+
-e "s|MIMETYPES_PATH_PLACEHOLDER|${mimetypes_path}|g" \
155163
-e "s|RESOLVER_PLACEHOLDER|${resolver}|g" \
156164
"$template_file" > "$output_file"
157165
fi

0 commit comments

Comments
 (0)