Skip to content

Commit 909ae80

Browse files
authored
fix: Windows build for sam3_image/sam3_video + close CI coverage gap (#7)
1 parent 8cc6e62 commit 909ae80

5 files changed

Lines changed: 60 additions & 33 deletions

File tree

.github/workflows/ci.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030

3131
- name: Windows (MSVC)
3232
os: windows-latest
33-
cmake_args: "-DGGML_METAL=OFF -DSAM3_METAL=OFF -A x64"
33+
cmake_args: "-DGGML_METAL=OFF -DSAM3_METAL=OFF -A x64 -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows"
3434
build_args: "--config Release"
3535

3636
steps:
@@ -47,6 +47,11 @@ jobs:
4747
if: runner.os == 'macOS'
4848
run: brew install ninja
4949

50+
- name: Install SDL2 (Windows)
51+
if: runner.os == 'Windows'
52+
shell: pwsh
53+
run: vcpkg install sdl2:x64-windows
54+
5055
- name: ccache
5156
uses: hendrikmuhs/ccache-action@v1
5257
with:
@@ -64,7 +69,7 @@ jobs:
6469
- name: Build
6570
run: cmake --build build ${{ matrix.build_args }} --parallel
6671

67-
- name: Verify library
72+
- name: Verify build artifacts
6873
shell: bash
6974
run: |
7075
if [ -f build/libsam3.a ]; then
@@ -77,3 +82,14 @@ jobs:
7782
echo "ERROR: sam3 library not found"
7883
exit 1
7984
fi
85+
86+
if [ "$RUNNER_OS" = "Windows" ]; then
87+
for exe in sam3_image.exe sam3_video.exe; do
88+
if [ -f "build/examples/Release/$exe" ]; then
89+
echo "Found build/examples/Release/$exe"
90+
else
91+
echo "ERROR: $exe not built (GUI examples were silently skipped — likely SDL2 not found)"
92+
exit 1
93+
fi
94+
done
95+
fi

examples/main_image.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,14 @@
1414

1515
#include "sam3.h"
1616

17+
#define SDL_MAIN_HANDLED
1718
#include <SDL.h>
19+
#include <SDL_opengl.h>
20+
1821
#include <imgui.h>
1922
#include <imgui_impl_sdl2.h>
2023
#include <imgui_impl_opengl3.h>
2124

22-
#ifdef __APPLE__
23-
#ifndef GL_SILENCE_DEPRECATION
24-
#define GL_SILENCE_DEPRECATION
25-
#endif
26-
#include <OpenGL/gl3.h>
27-
#else
28-
#include <GL/gl.h>
29-
#endif
30-
3125
#include <algorithm>
3226
#include <cmath>
3327
#include <cstdio>

examples/main_video.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,14 @@
1313

1414
#include "sam3.h"
1515

16+
#define SDL_MAIN_HANDLED
1617
#include <SDL.h>
18+
#include <SDL_opengl.h>
19+
1720
#include <imgui.h>
1821
#include <imgui_impl_sdl2.h>
1922
#include <imgui_impl_opengl3.h>
2023

21-
#ifdef __APPLE__
22-
#ifndef GL_SILENCE_DEPRECATION
23-
#define GL_SILENCE_DEPRECATION
24-
#endif
25-
#include <OpenGL/gl3.h>
26-
#else
27-
#include <GL/gl.h>
28-
#endif
29-
3024
#include <algorithm>
3125
#include <cstdio>
3226
#include <cstring>

examples/third-party/CMakeLists.txt

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
1-
# ImGui library with SDL2 + OpenGL3 backend
2-
set(IMGUI_DIR ${CMAKE_CURRENT_SOURCE_DIR}/imgui)
1+
# ImGui library with SDL2 + OpenGL3 backend.
2+
#
3+
# ImGui is not vendored. Prefer a local checkout at examples/third-party/imgui
4+
# (useful for offline builds); otherwise fetch it at configure time via
5+
# FetchContent, pinned to a known-good tag.
6+
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/imgui/imgui.cpp")
7+
set(IMGUI_DIR ${CMAKE_CURRENT_SOURCE_DIR}/imgui)
8+
message(STATUS "Using local ImGui checkout at ${IMGUI_DIR}")
9+
else()
10+
include(FetchContent)
11+
FetchContent_Declare(
12+
imgui
13+
GIT_REPOSITORY https://github.com/ocornut/imgui.git
14+
GIT_TAG v1.91.8
15+
GIT_SHALLOW TRUE
16+
)
17+
FetchContent_MakeAvailable(imgui)
18+
set(IMGUI_DIR ${imgui_SOURCE_DIR})
19+
message(STATUS "Fetched ImGui v1.91.8 into ${IMGUI_DIR}")
20+
endif()
321

422
add_library(imgui-sdl2 STATIC
523
${IMGUI_DIR}/imgui.cpp
@@ -26,8 +44,9 @@ else()
2644
target_link_libraries(imgui-sdl2 PUBLIC OpenGL::GL)
2745
endif()
2846

47+
# On non-Apple, leave IMGUI_IMPL_OPENGL_LOADER_* undefined so imgui uses its
48+
# bundled imgl3w loader (required for GL 3+ on MSVC where opengl32.lib only
49+
# exports GL 1.1 symbols).
2950
if(APPLE)
3051
target_compile_definitions(imgui-sdl2 PUBLIC GL_SILENCE_DEPRECATION)
31-
else()
32-
target_compile_definitions(imgui-sdl2 PUBLIC IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
3352
endif()

sam3.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@
2323
#define popen _popen
2424
#define pclose _pclose
2525
#define mkdir(path, mode) _mkdir(path)
26+
#define SAM3_NULL_DEV "NUL"
27+
#define SAM3_POPEN_READ "rb"
2628
#else
2729
#include <sys/stat.h>
30+
#define SAM3_NULL_DEV "/dev/null"
31+
#define SAM3_POPEN_READ "r"
2832
#endif
2933

3034
/* C++ standard library */
@@ -12289,16 +12293,16 @@ sam3_image sam3_decode_video_frame(const std::string& video_path, int frame_inde
1228912293
snprintf(cmd, sizeof(cmd),
1229012294
"ffmpeg -nostdin -loglevel error -i \"%s\" "
1229112295
"-vf \"select=eq(n\\,%d)\" -vsync vfr -frames:v 1 "
12292-
"-f rawvideo -pix_fmt rgb24 pipe:1 2>/dev/null",
12293-
video_path.c_str(), frame_index);
12296+
"-f rawvideo -pix_fmt rgb24 pipe:1 2>%s",
12297+
video_path.c_str(), frame_index, SAM3_NULL_DEV);
1229412298

1229512299
// First, get dimensions
1229612300
char info_cmd[1024];
1229712301
snprintf(info_cmd, sizeof(info_cmd),
1229812302
"ffprobe -v error -select_streams v:0 "
12299-
"-show_entries stream=width,height -of csv=p=0 \"%s\" 2>/dev/null",
12300-
video_path.c_str());
12301-
FILE* fp = popen(info_cmd, "r");
12303+
"-show_entries stream=width,height -of csv=p=0 \"%s\" 2>%s",
12304+
video_path.c_str(), SAM3_NULL_DEV);
12305+
FILE* fp = popen(info_cmd, SAM3_POPEN_READ);
1230212306
if (!fp) return img;
1230312307
int w = 0, h = 0;
1230412308
if (fscanf(fp, "%d,%d", &w, &h) != 2) {
@@ -12312,7 +12316,7 @@ sam3_image sam3_decode_video_frame(const std::string& video_path, int frame_inde
1231212316
img.channels = 3;
1231312317
img.data.resize(w * h * 3);
1231412318

12315-
fp = popen(cmd, "r");
12319+
fp = popen(cmd, SAM3_POPEN_READ);
1231612320
if (!fp) {
1231712321
img.data.clear();
1231812322
return img;
@@ -12333,9 +12337,9 @@ sam3_video_info sam3_get_video_info(const std::string& video_path) {
1233312337
snprintf(cmd, sizeof(cmd),
1233412338
"ffprobe -v error -select_streams v:0 "
1233512339
"-show_entries stream=width,height,r_frame_rate,nb_frames "
12336-
"-of csv=p=0 \"%s\" 2>/dev/null",
12337-
video_path.c_str());
12338-
FILE* fp = popen(cmd, "r");
12340+
"-of csv=p=0 \"%s\" 2>%s",
12341+
video_path.c_str(), SAM3_NULL_DEV);
12342+
FILE* fp = popen(cmd, SAM3_POPEN_READ);
1233912343
if (!fp) return info;
1234012344

1234112345
int w = 0, h = 0, num = 0, den = 1, nf = 0;

0 commit comments

Comments
 (0)