Skip to content

Commit 0d902d3

Browse files
geraldcombspoiana
authored andcommitted
feat(userspace/libsinsp/example): Allow running under Windows
Change command line option parsing from getopt_long to cxxopts, which lets us run on Windows. Initial conversion was done using Claude Sonnet 4.5, then cleaned up manually. cxxopts.cmake was copied from the Falco repository and updated to version 3.1.1. Signed-off-by: Gerald Combs <gerald@wireshark.org>
1 parent 7250ae9 commit 0d902d3

File tree

6 files changed

+232
-146
lines changed

6 files changed

+232
-146
lines changed

.github/install-deps.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,11 @@ wget -P "/usr/include" "https://raw.githubusercontent.com/troydhanson/uthash/v1.
6060
echo "=== Downloading BS_thread_pool.h (4.1.0) ==="
6161

6262
wget -P "/usr/include" "https://github.com/bshoshany/thread-pool/raw/v4.1.0/include/BS_thread_pool.hpp"
63+
64+
# === cxxopts ===
65+
if [ ! -f "/usr/include/cxxopts.hpp" ]; then
66+
echo "=== Downloading cxxopts.hpp (3.3.1) ==="
67+
wget -P "/usr/include" "https://raw.githubusercontent.com/jarro2783/cxxopts/refs/tags/v3.3.1/include/cxxopts.hpp"
68+
else
69+
echo "=== cxxopts.hpp already exists, skipping download ==="
70+
fi

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ jobs:
204204

205205
- name: Install deps ⛓️
206206
run: |
207-
HOMEBREW_NO_AUTO_UPDATE=1 brew install c-ares re2 tbb jq jsoncpp openssl uthash
207+
HOMEBREW_NO_AUTO_UPDATE=1 brew install c-ares re2 tbb jq jsoncpp openssl uthash cxxopts
208208
209209
- name: Build 🏗️
210210
run: |
@@ -248,7 +248,7 @@ jobs:
248248
- name: Install deps ⛓️
249249
run: |
250250
sudo apt update
251-
sudo apt install -y --no-install-recommends ca-certificates build-essential clang-14 llvm-14 git pkg-config autoconf automake libtool libelf-dev libcap-dev linux-headers-$(uname -r)
251+
sudo apt install -y --no-install-recommends ca-certificates build-essential clang-14 llvm-14 git pkg-config autoconf automake libtool libelf-dev libcap-dev libcxxopts-dev linux-headers-$(uname -r)
252252
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-14 90
253253
sudo update-alternatives --install /usr/bin/llvm-strip llvm-strip /usr/bin/llvm-strip-14 90
254254
sudo update-alternatives --install /usr/bin/llc llc /usr/bin/llc-14 90

cmake/modules/cxxopts.cmake

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
#
3+
# Copyright (C) 2026 The Falco Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
6+
# in compliance with the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software distributed under the License
11+
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12+
# or implied. See the License for the specific language governing permissions and limitations under
13+
# the License.
14+
#
15+
16+
#
17+
# cxxopts (https://github.com/jarro2783/cxxopts)
18+
#
19+
20+
option(USE_BUNDLED_CXXOPTS "Enable building of the bundled cxxopts" ${USE_BUNDLED_DEPS})
21+
22+
if(CXXOPTS_INCLUDE_DIR)
23+
# we already have cxxopts
24+
elseif(NOT USE_BUNDLED_CXXOPTS)
25+
find_package(cxxopts CONFIG)
26+
if(CXXOPTS_INCLUDE_DIR)
27+
get_target_property(CXXOPTS_INCLUDE_DIR cxxopts::cxxopts INTERFACE_INCLUDE_DIRECTORIES)
28+
else()
29+
# Was it manually installed?
30+
find_path(CXXOPTS_INCLUDE_DIR cxxopts.hpp)
31+
if(CXXOPTS_INCLUDE_DIR)
32+
message(STATUS "Found cxxopts: include: ${CXXOPTS_INCLUDE_DIR}")
33+
else()
34+
message(FATAL_ERROR "Couldn't find system cxxopts")
35+
endif()
36+
endif()
37+
else()
38+
set(CXXOPTS_SRC "${PROJECT_BINARY_DIR}/cxxopts-prefix/src/cxxopts/")
39+
set(CXXOPTS_INCLUDE_DIR "${CXXOPTS_SRC}/include")
40+
41+
message(STATUS "Using bundled cxxopts in ${CXXOPTS_SRC}")
42+
43+
ExternalProject_Add(
44+
cxxopts
45+
URL "https://github.com/jarro2783/cxxopts/archive/refs/tags/v3.3.1.tar.gz"
46+
URL_HASH "SHA256=3bfc70542c521d4b55a46429d808178916a579b28d048bd8c727ee76c39e2072"
47+
CONFIGURE_COMMAND ""
48+
BUILD_COMMAND ""
49+
INSTALL_COMMAND ""
50+
)
51+
endif()
52+
53+
if(NOT TARGET cxxopts)
54+
add_custom_target(cxxopts)
55+
endif()

cmake/modules/libsinsp.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ if(NOT HAVE_LIBSINSP)
3535
include(jsoncpp)
3636
include(valijson)
3737
include(re2)
38+
include(cxxopts)
3839

3940
if(ENABLE_THREAD_POOL AND NOT EMSCRIPTEN)
4041
include(bs_threadpool)

userspace/libsinsp/examples/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# the License.
1414
#
1515

16+
include(cxxopts)
1617
include(jsoncpp)
1718

1819
set(sources util.cpp test.cpp)
@@ -23,6 +24,7 @@ endif()
2324

2425
add_executable(sinsp-example ${sources})
2526

27+
target_include_directories(sinsp-example PRIVATE "${CXXOPTS_INCLUDE_DIR}")
2628
target_link_libraries(sinsp-example sinsp "${JSONCPP_LIB}")
2729

2830
if(EMSCRIPTEN)

0 commit comments

Comments
 (0)