Skip to content

Commit 12bb53f

Browse files
authored
fix: build native libs on windows (#1)
1 parent 5c55793 commit 12bb53f

File tree

3 files changed

+83
-36
lines changed

3 files changed

+83
-36
lines changed

.github/workflows/build-binaries.yml

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,35 +72,20 @@ jobs:
7272
echo "📋 Checking generated native libraries:"
7373
find src/GrepSQL/runtimes/ -name "libpgquery_wrapper.*" -type f || echo "No native libraries found"
7474
75-
- name: Build for Windows (Placeholder)
75+
- name: Build for Windows
7676
if: runner.os == 'Windows'
77-
shell: cmd
77+
shell: pwsh
7878
run: |
79-
echo "🏗️ Building for Windows (partial support)..."
80-
81-
REM Initialize submodules
8279
git submodule update --init --recursive
83-
84-
REM Create placeholder directory structure
85-
mkdir "src\GrepSQL\runtimes\win-x64\native" 2>nul
86-
87-
REM Create a minimal dummy DLL to satisfy the .NET runtime
88-
echo. > "src\GrepSQL\runtimes\win-x64\native\libpgquery_wrapper.dll"
89-
90-
REM Build .NET project only
91-
dotnet restore
92-
dotnet build --configuration Release --no-restore
93-
echo "⚠️ Windows build completed with placeholder native library"
80+
./scripts/build.ps1
9481
9582
- name: Test (non-Windows)
9683
if: runner.os != 'Windows'
9784
run: dotnet test --configuration Release --no-build --verbosity normal
9885

99-
- name: Test (Windows - without native dependencies)
86+
- name: Test (Windows)
10087
if: runner.os == 'Windows'
101-
run: |
102-
echo "Running limited tests on Windows..."
103-
# dotnet test --configuration Release --no-build --verbosity normal --filter "Category!=RequiresNative"
88+
run: dotnet test --configuration Release --no-build --verbosity normal
10489

10590
- name: Publish GrepSQL Binary
10691
run: dotnet publish src/GrepSQL.CLI/GrepSQL/GrepSQL.csproj --configuration Release --runtime ${{ matrix.platform }} --self-contained true --output ./publish/${{ matrix.platform }} -p:PublishSingleFile=true -p:PublishTrimmed=true -p:IncludeNativeLibrariesForSelfExtract=true

.github/workflows/ci.yml

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jobs:
3939
uses: actions/checkout@v4
4040
with:
4141
fetch-depth: 0
42+
submodules: recursive
4243

4344
- name: Setup .NET
4445
uses: actions/setup-dotnet@v4
@@ -53,26 +54,20 @@ jobs:
5354
sudo apt-get update
5455
sudo apt-get install -y build-essential libc6-dev
5556
56-
- name: Run comprehensive build script
57+
- name: Run build script (Windows)
58+
if: matrix.os == 'windows-latest'
59+
shell: pwsh
60+
run: |
61+
./scripts/build.ps1
62+
63+
- name: Run comprehensive build script (Unix)
64+
if: matrix.os != 'windows-latest'
5765
shell: bash
5866
run: |
59-
# Skip entire native build on Windows - needs different toolchain
60-
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
61-
echo "🏗️ Building for Windows (partial support)..."
62-
echo "Skipping native library build on Windows - .NET code will be tested without native dependencies"
63-
echo "Windows would need MSVC/Visual Studio build tools for native compilation"
64-
65-
# Initialize submodules and build .NET only
66-
git submodule update --init --recursive
67-
dotnet restore
68-
dotnet build --configuration Release --no-restore
69-
exit 0
70-
fi
71-
7267
echo "🏗️ Running comprehensive build script..."
7368
chmod +x scripts/build.sh
7469
./scripts/build.sh
75-
70+
7671
# Verify the build was successful
7772
echo "📋 Verifying build output:"
7873
find src/GrepSQL/runtimes/ -name "libpgquery_wrapper.*" -type f || echo "No native libraries found"
@@ -121,7 +116,18 @@ jobs:
121116
echo "Warning: Native library not found at src/GrepSQL/runtimes/$TARGET_RID/native/libpgquery_wrapper.$LIBRARY_EXT"
122117
echo "Available files in src/GrepSQL/runtimes/:"
123118
find src/GrepSQL/runtimes/ -name "*.so" -o -name "*.dylib" || echo "No native libraries found"
124-
fi
119+
fi
120+
121+
- name: Copy native libraries to test project (Windows)
122+
if: matrix.os == 'windows-latest'
123+
shell: pwsh
124+
run: |
125+
$TARGET_RID = 'win-x64'
126+
$LIB_PATH = "src\GrepSQL\runtimes\$TARGET_RID\native\libpgquery_wrapper.dll"
127+
$TEST_OUTPUT = "tests\GrepSQL.Tests\bin\Release\net9.0"
128+
New-Item -ItemType Directory -Force -Path "$TEST_OUTPUT\runtimes\$TARGET_RID\native" | Out-Null
129+
Copy-Item $LIB_PATH "$TEST_OUTPUT\runtimes\$TARGET_RID\native" -Force
130+
Copy-Item $LIB_PATH $TEST_OUTPUT -Force
125131
126132
- name: Run tests
127133
timeout-minutes: 10

scripts/build.ps1

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,63 @@ if (-not $SkipNative) {
103103
}
104104
}
105105

106+
106107
Set-Location $ProjectRoot
108+
109+
# Step 2b: Build wrapper library
110+
Write-Host "🔧 Building wrapper library..." -ForegroundColor Yellow
111+
112+
$WrapperPath = Join-Path $ProjectRoot "wrapper.c"
113+
if (-not (Test-Path $WrapperPath)) {
114+
Write-Host "Creating wrapper.c..."
115+
@"
116+
#include \"libpg_query/pg_query.h\"
117+
118+
PgQueryProtobufParseResult pg_query_parse_protobuf_wrapper(const char* input) {
119+
return pg_query_parse_protobuf(input);
120+
}
121+
122+
PgQueryProtobufParseResult pg_query_parse_protobuf_opts_wrapper(const char* input, int parser_options) {
123+
return pg_query_parse_protobuf_opts(input, parser_options);
124+
}
125+
126+
void pg_query_free_protobuf_parse_result_wrapper(PgQueryProtobufParseResult result) {
127+
pg_query_free_protobuf_parse_result(result);
128+
}
129+
130+
PgQueryDeparseResult pg_query_deparse_protobuf_wrapper(PgQueryProtobuf parse_tree) {
131+
return pg_query_deparse_protobuf(parse_tree);
132+
}
133+
134+
PgQueryParseResult pg_query_parse_wrapper(const char* input) {
135+
return pg_query_parse(input);
136+
}
137+
138+
void pg_query_free_parse_result_wrapper(PgQueryParseResult result) {
139+
pg_query_free_parse_result(result);
140+
}
141+
142+
PgQueryNormalizeResult pg_query_normalize_wrapper(const char* input) {
143+
return pg_query_normalize(input);
144+
}
145+
146+
void pg_query_free_normalize_result_wrapper(PgQueryNormalizeResult result) {
147+
pg_query_free_normalize_result(result);
148+
}
149+
"@ | Set-Content $WrapperPath -Encoding ascii
150+
}
151+
152+
$ClPath = Get-Command cl.exe -ErrorAction SilentlyContinue
153+
if (-not $ClPath) {
154+
Write-Error "cl.exe not found. Ensure Visual Studio Build Tools are installed and vcvars are loaded."
155+
exit 1
156+
}
157+
158+
& $ClPath /nologo /LD /I libpg_query $WrapperPath libpg_query\pg_query.lib /link /OUT:libpgquery_wrapper.dll
159+
if ($LASTEXITCODE -ne 0) {
160+
Write-Error "❌ Failed to compile wrapper library"
161+
exit $LASTEXITCODE
162+
}
107163
}
108164

109165
# Step 3: Create runtime directories and copy libraries

0 commit comments

Comments
 (0)