Skip to content

Commit 3b5cdb4

Browse files
committed
Fix CI builds by making native libraries conditional and building them in CI - Add conditional Exists() checks for all native library includes - Add native library build step to CI workflow for Linux/macOS - Remove pre-built native libraries from repository - Libraries are now built dynamically for each platform in CI
1 parent 728d24b commit 3b5cdb4

File tree

5 files changed

+102
-11
lines changed

5 files changed

+102
-11
lines changed

.github/workflows/ci.yml

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,104 @@ jobs:
2626
with:
2727
fetch-depth: 0
2828

29-
- name: Setup .NET Core
29+
- name: Setup .NET
3030
uses: actions/setup-dotnet@v4
3131
with:
3232
dotnet-version: |
3333
${{ env.DOTNET_VERSION }}
3434
${{ env.DOTNET_FRAMEWORK_VERSION }}
3535
36+
- name: Initialize submodules
37+
run: git submodule update --init --recursive
38+
39+
- name: Build native libraries
40+
run: |
41+
cd libpg_query
42+
make clean
43+
make
44+
cd ..
45+
46+
# Determine platform and create wrapper
47+
if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then
48+
LIBRARY_EXT="so"
49+
TARGET_RID="linux-x64"
50+
elif [[ "${{ matrix.os }}" == "windows-latest" ]]; then
51+
LIBRARY_EXT="dll"
52+
TARGET_RID="win-x64"
53+
elif [[ "${{ matrix.os }}" == "macos-latest" ]]; then
54+
LIBRARY_EXT="dylib"
55+
if [[ $(uname -m) == "arm64" ]]; then
56+
TARGET_RID="osx-arm64"
57+
else
58+
TARGET_RID="osx-x64"
59+
fi
60+
fi
61+
62+
# Create wrapper.c if it doesn't exist
63+
if [ ! -f "wrapper.c" ]; then
64+
cat > wrapper.c << 'EOF'
65+
#include "libpg_query/pg_query.h"
66+
67+
// Simple wrapper to export pg_query functions
68+
PgQueryParseResult pg_query_parse_wrapper(const char* input) {
69+
return pg_query_parse(input);
70+
}
71+
72+
void pg_query_free_parse_result_wrapper(PgQueryParseResult result) {
73+
pg_query_free_parse_result(result);
74+
}
75+
76+
PgQueryNormalizeResult pg_query_normalize_wrapper(const char* input) {
77+
return pg_query_normalize(input);
78+
}
79+
80+
void pg_query_free_normalize_result_wrapper(PgQueryNormalizeResult result) {
81+
pg_query_free_normalize_result(result);
82+
}
83+
84+
// Protobuf wrapper functions
85+
PgQueryProtobufParseResult pg_query_parse_protobuf_wrapper(const char* input) {
86+
return pg_query_parse_protobuf(input);
87+
}
88+
89+
void pg_query_free_protobuf_parse_result_wrapper(PgQueryProtobufParseResult result) {
90+
pg_query_free_protobuf_parse_result(result);
91+
}
92+
93+
PgQueryFingerprintResult pg_query_fingerprint_wrapper(const char* input) {
94+
return pg_query_fingerprint(input);
95+
}
96+
97+
void pg_query_free_fingerprint_result_wrapper(PgQueryFingerprintResult result) {
98+
pg_query_free_fingerprint_result(result);
99+
}
100+
101+
PgQueryScanResult pg_query_scan_wrapper(const char* input) {
102+
return pg_query_scan(input);
103+
}
104+
105+
void pg_query_free_scan_result_wrapper(PgQueryScanResult result) {
106+
pg_query_free_scan_result(result);
107+
}
108+
EOF
109+
fi
110+
111+
# Compile wrapper
112+
if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then
113+
gcc -shared -fPIC -I. -o "libpgquery_wrapper.so" wrapper.c libpg_query/libpg_query.a
114+
elif [[ "${{ matrix.os }}" == "macos-latest" ]]; then
115+
gcc -shared -fPIC -I. -o "libpgquery_wrapper.dylib" wrapper.c libpg_query/libpg_query.a
116+
elif [[ "${{ matrix.os }}" == "windows-latest" ]]; then
117+
# Windows builds would need different compilation - skip for now
118+
echo "Windows native build not implemented yet"
119+
fi
120+
121+
# Copy to runtime directories
122+
mkdir -p "src/PgQuery.NET/runtimes/$TARGET_RID/native"
123+
if [ -f "libpgquery_wrapper.$LIBRARY_EXT" ]; then
124+
cp "libpgquery_wrapper.$LIBRARY_EXT" "src/PgQuery.NET/runtimes/$TARGET_RID/native/"
125+
fi
126+
36127
- name: Restore dependencies
37128
run: dotnet restore
38129

-2.89 MB
Binary file not shown.

src/PgQuery.NET/PgQuery.NET.csproj

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,64 +54,64 @@
5454

5555
<!-- Native libraries for Windows -->
5656
<ItemGroup Condition="$([MSBuild]::IsOSPlatform('Windows'))">
57-
<Content Include="runtimes\win-x64\native\$(PgQueryWrapperWin)">
57+
<Content Include="runtimes\win-x64\native\$(PgQueryWrapperWin)" Condition="Exists('runtimes\win-x64\native\$(PgQueryWrapperWin)')">
5858
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
5959
<PackagePath>runtimes\win-x64\native\$(PgQueryWrapperWin)</PackagePath>
6060
<Pack>true</Pack>
6161
</Content>
62-
<Content Include="runtimes\win-x86\native\$(PgQueryWrapperWin)">
62+
<Content Include="runtimes\win-x86\native\$(PgQueryWrapperWin)" Condition="Exists('runtimes\win-x86\native\$(PgQueryWrapperWin)')">
6363
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6464
<PackagePath>runtimes\win-x86\native\$(PgQueryWrapperWin)</PackagePath>
6565
<Pack>true</Pack>
6666
</Content>
67-
<Content Include="runtimes\win-arm64\native\$(PgQueryWrapperWin)">
67+
<Content Include="runtimes\win-arm64\native\$(PgQueryWrapperWin)" Condition="Exists('runtimes\win-arm64\native\$(PgQueryWrapperWin)')">
6868
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6969
<PackagePath>runtimes\win-arm64\native\$(PgQueryWrapperWin)</PackagePath>
7070
<Pack>true</Pack>
7171
</Content>
7272

7373
<!-- Fallback: Copy wrapper library directly to output directory for better compatibility -->
74-
<Content Include="runtimes\win-x64\native\$(PgQueryWrapperWin)">
74+
<Content Include="runtimes\win-x64\native\$(PgQueryWrapperWin)" Condition="Exists('runtimes\win-x64\native\$(PgQueryWrapperWin)')">
7575
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
7676
<Link>$(PgQueryWrapperWin)</Link>
7777
</Content>
7878
</ItemGroup>
7979

8080
<!-- Native libraries for Linux -->
8181
<ItemGroup Condition="$([MSBuild]::IsOSPlatform('Linux'))">
82-
<Content Include="runtimes\linux-x64\native\$(PgQueryWrapperLinux)">
82+
<Content Include="runtimes\linux-x64\native\$(PgQueryWrapperLinux)" Condition="Exists('runtimes\linux-x64\native\$(PgQueryWrapperLinux)')">
8383
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
8484
<PackagePath>runtimes\linux-x64\native\$(PgQueryWrapperLinux)</PackagePath>
8585
<Pack>true</Pack>
8686
</Content>
87-
<Content Include="runtimes\linux-arm64\native\$(PgQueryWrapperLinux)">
87+
<Content Include="runtimes\linux-arm64\native\$(PgQueryWrapperLinux)" Condition="Exists('runtimes\linux-arm64\native\$(PgQueryWrapperLinux)')">
8888
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
8989
<PackagePath>runtimes\linux-arm64\native\$(PgQueryWrapperLinux)</PackagePath>
9090
<Pack>true</Pack>
9191
</Content>
9292

9393
<!-- Fallback: Copy wrapper library directly to output directory for better compatibility -->
94-
<Content Include="runtimes\linux-x64\native\$(PgQueryWrapperLinux)">
94+
<Content Include="runtimes\linux-x64\native\$(PgQueryWrapperLinux)" Condition="Exists('runtimes\linux-x64\native\$(PgQueryWrapperLinux)')">
9595
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
9696
<Link>$(PgQueryWrapperLinux)</Link>
9797
</Content>
9898
</ItemGroup>
9999

100100
<!-- Native libraries for macOS -->
101101
<ItemGroup Condition="$([MSBuild]::IsOSPlatform('OSX'))">
102-
<Content Include="runtimes\osx-x64\native\$(PgQueryWrapperMac)">
102+
<Content Include="runtimes\osx-x64\native\$(PgQueryWrapperMac)" Condition="Exists('runtimes\osx-x64\native\$(PgQueryWrapperMac)')">
103103
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
104104
<PackagePath>runtimes\osx-x64\native\$(PgQueryWrapperMac)</PackagePath>
105105
<Pack>true</Pack>
106106
</Content>
107-
<Content Include="runtimes\osx-arm64\native\$(PgQueryWrapperMac)">
107+
<Content Include="runtimes\osx-arm64\native\$(PgQueryWrapperMac)" Condition="Exists('runtimes\osx-arm64\native\$(PgQueryWrapperMac)')">
108108
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
109109
<PackagePath>runtimes\osx-arm64\native\$(PgQueryWrapperMac)</PackagePath>
110110
<Pack>true</Pack>
111111
</Content>
112112

113113
<!-- Fallback: Copy wrapper library directly to output directory for better compatibility -->
114-
<Content Include="runtimes\osx-arm64\native\$(PgQueryWrapperMac)">
114+
<Content Include="runtimes\osx-arm64\native\$(PgQueryWrapperMac)" Condition="Exists('runtimes\osx-arm64\native\$(PgQueryWrapperMac)')">
115115
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
116116
<Link>$(PgQueryWrapperMac)</Link>
117117
</Content>
-2.89 MB
Binary file not shown.
-2.89 MB
Binary file not shown.

0 commit comments

Comments
 (0)