Skip to content

Commit

Permalink
attempt to fix file problems in win
Browse files Browse the repository at this point in the history
  • Loading branch information
jraymakers committed Jun 23, 2024
1 parent 9c84445 commit bbe4079
Showing 1 changed file with 36 additions and 35 deletions.
71 changes: 36 additions & 35 deletions generate-wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,62 +238,63 @@ def get_lib_file_name():
raise Exception("Unsupported system: " + system)

if __name__ == "__main__":
dir_path = os.path.dirname(os.path.realpath(__file__))

with tempfile.TemporaryDirectory() as tmp:
dir_path = os.path.dirname(os.path.realpath(__file__))

zip_path = os.path.join(tmp, "libduckdb.zip")
with tempfile.TemporaryDirectory() as zip_tmp:
zip_path = os.path.join(zip_tmp, "libduckdb.zip")

release_zip_url = get_release_zip_url()

print("Downloading " + release_zip_url)
urllib.request.urlretrieve(release_zip_url, zip_path)

print("Extracting zip")
zip = zipfile.ZipFile(zip_path)

lib_file_name = get_lib_file_name()
zip.extract(lib_file_name, tmp)
shutil.copy(os.path.join(tmp, lib_file_name), os.path.join(dir_path, "lib", "binding", "libduckdb"))
with tempfile.TemporaryDirectory() as ext_tmp:
lib_file_name = get_lib_file_name()
zip.extract(lib_file_name, ext_tmp)
shutil.copy(os.path.join(ext_tmp, lib_file_name), os.path.join(dir_path, "lib", "binding", "libduckdb"))

zip.extract("duckdb.h", "src")
zip.extract("duckdb.h", tmp)
zip.extract("duckdb.h", "src")
zip.extract("duckdb.h", ext_tmp)

print("Preprocessing duckdb.h")
os.system("sed -i -e 's/#include <stdlib.h>/#include <stddef.h>/' %s" % os.path.join(tmp, "duckdb.h")) # until 0.10.0 has been released
os.system("gcc -DDUCKDB_NO_EXTENSION_FUNCTIONS -DDUCKDB_API_NO_DEPRECATED -E -D__builtin_va_list=int -D'__attribute__(x)=' %s > %s" % (os.path.join(tmp, "duckdb.h"), os.path.join(tmp, "duckdb-preprocessed.h")))
print("Preprocessing duckdb.h")
os.system("sed -i -e 's/#include <stdlib.h>/#include <stddef.h>/' %s" % os.path.join(ext_tmp, "duckdb.h")) # until 0.10.0 has been released
os.system("gcc -DDUCKDB_NO_EXTENSION_FUNCTIONS -DDUCKDB_API_NO_DEPRECATED -E -D__builtin_va_list=int -D'__attribute__(x)=' %s > %s"
% (os.path.join(ext_tmp, "duckdb.h"), os.path.join(ext_tmp, "duckdb-preprocessed.h")))

print("Generating C code and TypeScript definitions")
cpp_result, types_result = create_func_defs(os.path.join(tmp, "duckdb-preprocessed.h"))
print("Generating C code and TypeScript definitions")
cpp_result, types_result = create_func_defs(os.path.join(ext_tmp, "duckdb-preprocessed.h"))

out = open(os.path.join(dir_path, "src", "duckdb_node_generated.cpp"), 'wb')
out.write('''// This file is generated by generate-wrapper.py, please do not edit
out = open(os.path.join(dir_path, "src", "duckdb_node_generated.cpp"), 'wb')
out.write('''// This file is generated by generate-wrapper.py, please do not edit
#include "duckdb.h"
#include "function_wrappers.hpp"
static void RegisterGenerated(Napi::Env env, Napi::Object exports,
std::unordered_map<const char *, Napi::FunctionReference> &constructors) {
'''.encode())
out.write(cpp_result.encode())
out.write('}\n'.encode())
out.write(cpp_result.encode())
out.write('}\n'.encode())

types_out = open('lib/duckdb.d.ts', 'wb')
types_out.write('// placeholder interfaces for pointer types\n'.encode())
types_out.write('export interface idx_pointer extends pointer {}\n'.encode())
types_out = open('lib/duckdb.d.ts', 'wb')

types_out.write('// placeholder interfaces for pointer types\n'.encode())
types_out.write('export interface idx_pointer extends pointer {}\n'.encode())

types_out.write('// bindings-defined types\n'.encode())
types_out.write('export class pointer {}\n'.encode())
types_out.write('export class uint64_pointer {}\n'.encode())
types_out.write('export class out_string_wrapper {}\n'.encode())
types_out.write('// bindings-defined types\n'.encode())
types_out.write('export class pointer {}\n'.encode())
types_out.write('export class uint64_pointer {}\n'.encode())
types_out.write('export class out_string_wrapper {}\n'.encode())

types_out.write('// generated types and functions\n'.encode())
types_out.write(types_result.encode())
types_out.write('// generated types and functions\n'.encode())
types_out.write(types_result.encode())

types_out.write('// bindings-defined constants\n'.encode())
types_out.write('export const sizeof_bool: number;\n'.encode())
types_out.write('// bindings-defined constants\n'.encode())
types_out.write('export const sizeof_bool: number;\n'.encode())

types_out.write('// bindings-defined functions\n'.encode())
types_out.write('export function copy_buffer(buffer: pointer, length: number): Uint8Array | null;\n'.encode())
types_out.write('export function copy_buffer_double(buffer: number, length: number): Uint8Array | null;\n'.encode())
types_out.write('export function out_get_string(string_wrapper: out_string_wrapper): string;\n'.encode())
types_out.write('// bindings-defined functions\n'.encode())
types_out.write('export function copy_buffer(buffer: pointer, length: number): Uint8Array | null;\n'.encode())
types_out.write('export function copy_buffer_double(buffer: number, length: number): Uint8Array | null;\n'.encode())
types_out.write('export function out_get_string(string_wrapper: out_string_wrapper): string;\n'.encode())

0 comments on commit bbe4079

Please sign in to comment.