@@ -108,52 +108,59 @@ if (-not $SkipNative) {
108108
109109 Set-Location $ProjectRoot
110110
111- # Step 2b: Build wrapper library (FIXED )
111+ # Step 2b: Build wrapper library (FINAL FIX )
112112 Write-Host " 🔧 Building wrapper library..." - ForegroundColor Yellow
113+
114+ # --- ADD CLEANUP STEP ---
115+ Write-Host " 🧹 Cleaning up old build artifacts..."
116+ Remove-Item - Path " wrapper.c" , " wrapper.def" , " libpgquery_wrapper.dll" - ErrorAction SilentlyContinue
113117
114118 $WrapperPath = Join-Path $ProjectRoot " wrapper.c"
115119 $DefPath = Join-Path $ProjectRoot " wrapper.def"
116120
117- # Create the wrapper.c file with the same logic as the bash script
118- Write-Host " Creating wrapper.c with explicit wrapper functions ..."
121+ # Create the wrapper.c file, forcing __stdcall calling convention to match .NET's P/Invoke default
122+ Write-Host " Creating wrapper.c with __stdcall calling convention ..."
119123 @"
120124#include "libpg_query/pg_query.h"
121125
122- PgQueryProtobufParseResult pg_query_parse_protobuf_wrapper(const char* input) {
126+ // Forcing __stdcall is crucial for default .NET P/Invoke on Windows
127+ #define STDCALL __stdcall
128+
129+ PgQueryProtobufParseResult STDCALL pg_query_parse_protobuf_wrapper(const char* input) {
123130 return pg_query_parse_protobuf(input);
124131}
125132
126- PgQueryProtobufParseResult pg_query_parse_protobuf_opts_wrapper(const char* input, int parser_options) {
133+ PgQueryProtobufParseResult STDCALL pg_query_parse_protobuf_opts_wrapper(const char* input, int parser_options) {
127134 return pg_query_parse_protobuf_opts(input, parser_options);
128135}
129136
130- void pg_query_free_protobuf_parse_result_wrapper(PgQueryProtobufParseResult result) {
137+ void STDCALL pg_query_free_protobuf_parse_result_wrapper(PgQueryProtobufParseResult result) {
131138 pg_query_free_protobuf_parse_result(result);
132139}
133140
134- PgQueryDeparseResult pg_query_deparse_protobuf_wrapper(PgQueryProtobuf parse_tree) {
141+ PgQueryDeparseResult STDCALL pg_query_deparse_protobuf_wrapper(PgQueryProtobuf parse_tree) {
135142 return pg_query_deparse_protobuf(parse_tree);
136143}
137144
138- PgQueryParseResult pg_query_parse_wrapper(const char* input) {
145+ PgQueryParseResult STDCALL pg_query_parse_wrapper(const char* input) {
139146 return pg_query_parse(input);
140147}
141148
142- void pg_query_free_parse_result_wrapper(PgQueryParseResult result) {
149+ void STDCALL pg_query_free_parse_result_wrapper(PgQueryParseResult result) {
143150 pg_query_free_parse_result(result);
144151}
145152
146- PgQueryNormalizeResult pg_query_normalize_wrapper(const char* input) {
153+ PgQueryNormalizeResult STDCALL pg_query_normalize_wrapper(const char* input) {
147154 return pg_query_normalize(input);
148155}
149156
150- void pg_query_free_normalize_result_wrapper(PgQueryNormalizeResult result) {
157+ void STDCALL pg_query_free_normalize_result_wrapper(PgQueryNormalizeResult result) {
151158 pg_query_free_normalize_result(result);
152159}
153160"@ | Set-Content - Path $WrapperPath - Encoding Ascii
154161
155- # Create the .def file to explicitly export the wrapper functions
156- Write-Host " Creating wrapper.def to export wrapper functions..."
162+ # Create the .def file to export the wrapper functions with undecorated names
163+ Write-Host " Creating wrapper.def to export functions..."
157164 @"
158165EXPORTS
159166 pg_query_parse_protobuf_wrapper
0 commit comments