From: Matt Corallo <649246+TheBlueMatt@users.noreply.github.com> Date: Fri, 17 Nov 2023 01:56:29 +0000 (+0000) Subject: Merge pull request #145 from TheBlueMatt/main X-Git-Tag: v0.0.121.0~18 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=d8656f7b597edd7ae8c34cb677c35d3b1635efd5;hp=c66eb68474c7578854943430e6362455b90b77b9;p=ldk-java Merge pull request #145 from TheBlueMatt/main Switch C# builds to use `dotnet` on Fedora --- diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b57cbad2..c6b18284 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -162,28 +162,21 @@ jobs: runs-on: ubuntu-latest # Ubuntu's version of clang doesn't support....anything that should work. # Ubuntu is an utter trash OS and should generally never be used for anything. - # We also require at least rustc 1.51 (ie https://github.com/rust-lang/rust/pull/79998), - # so we use debian testing - container: debian:bookworm + # We also require dotnet so we use fedora + container: fedora:39 strategy: fail-fast: false steps: - name: Install required dependencies run: | - apt-get update - apt-get -y dist-upgrade - apt-get -y install cargo libstd-rust-dev-windows lld llvm git g++ clang curl gcc-mingw-w64-x86-64-win32 python3 mono-devel zip faketime + dnf install -y mingw64-gcc git cargo dotnet clang llvm lld faketime rust-std-static-x86_64-pc-windows-gnu which diffutils - name: Checkout source code uses: actions/checkout@v2 with: fetch-depth: 0 - name: Install cbindgen run: | - git clone https://github.com/eqrion/cbindgen - cd cbindgen/ - git checkout v0.20.0 - cargo update -p indexmap --precise "1.6.2" --verbose - cargo install --locked --path . + cargo install cbindgen - name: Checkout Rust-Lightning and LDK-C-Bindings git run: | git config --global safe.directory '*' @@ -208,7 +201,7 @@ jobs: - name: Build Windows C# Bindings run: | export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)" - LDK_TARGET=x86_64-pc-windows-gnu faketime -f "2021-01-01 00:00:00" ./genbindings.sh ./ldk-c-bindings/ c_sharp false false + LDK_TARGET=x86_64-pc-windows-gnu ./genbindings.sh ./ldk-c-bindings/ c_sharp false false - name: Build Linux C# Bindings run: | export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)" @@ -217,6 +210,10 @@ jobs: run: | cd c_sharp ./build-release-nupkg.sh + - uses: actions/upload-artifact@v3 + with: + name: org.ldk.nupkg + path: c_sharp/org.ldk.nupkg - name: Check latest auto-generated code is in git run: | # Checkout files that get updated with version information @@ -241,7 +238,7 @@ jobs: run: | export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)" if ! diff ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"org.ldk.nupkg c_sharp/org.ldk.nupkg; then - apt-get -y install diffoscope + dnf -y install diffoscope diffoscope ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"org.ldk.nupkg c_sharp/org.ldk.nupkg || echo exit 1 fi diff --git a/c_sharp/bindings.c b/c_sharp/bindings.c index ae8f11a5..5f7c5c2e 100644 --- a/c_sharp/bindings.c +++ b/c_sharp/bindings.c @@ -72,11 +72,11 @@ static inline LDKStr str_ref_to_owned_c(const jstring str) { typedef bool jboolean; int64_t CS_LDK_allocate_buffer(int64_t len) { - return MALLOC(len, "C#-requested buffer"); + return (int64_t)MALLOC(len, "C#-requested buffer"); } void CS_LDK_free_buffer(int64_t buf) { - FREE(buf); + FREE((void*)buf); } jstring CS_LDK_get_ldk_c_bindings_version() { @@ -87,21 +87,21 @@ jstring CS_LDK_get_ldk_version() { } #include "version.c" -typedef int8_tArray (*invoker_l_l)(int obj_ptr, int fn_id, int64_t a); +typedef int64_t (*invoker_l_l)(int obj_ptr, int fn_id, int64_t a); static invoker_l_l js_invoke_function_l_l; int CS_LDK_register_l_l_invoker(invoker_l_l invoker) { js_invoke_function_l_l = invoker; return 0; } -typedef int64_t (*invoker_l_ll)(int obj_ptr, int fn_id, int64_t a, ptrArray b); +typedef int64_t (*invoker_l_ll)(int obj_ptr, int fn_id, int64_t a, int64_t b); static invoker_l_ll js_invoke_function_l_ll; int CS_LDK_register_l_ll_invoker(invoker_l_ll invoker) { js_invoke_function_l_ll = invoker; return 0; } -typedef int8_tArray (*invoker_l_)(int obj_ptr, int fn_id); +typedef int64_t (*invoker_l_)(int obj_ptr, int fn_id); static invoker_l_ js_invoke_function_l_; int CS_LDK_register_l__invoker(invoker_l_ invoker) { js_invoke_function_l_ = invoker; @@ -115,21 +115,21 @@ int CS_LDK_register_void_l_invoker(invoker_void_l invoker) { return 0; } -typedef int64_t (*invoker_l_llll)(int obj_ptr, int fn_id, int8_tArray a, int64_t b, int64_t c, int8_tArray d); +typedef int64_t (*invoker_l_llll)(int obj_ptr, int fn_id, int64_t a, int64_t b, int64_t c, int64_t d); static invoker_l_llll js_invoke_function_l_llll; int CS_LDK_register_l_llll_invoker(invoker_l_llll invoker) { js_invoke_function_l_llll = invoker; return 0; } -typedef int64_t (*invoker_l_lllll)(int obj_ptr, int fn_id, int8_tArray a, int64_t b, int64_t c, int8_tArray d, int64_t e); +typedef int64_t (*invoker_l_lllll)(int obj_ptr, int fn_id, int64_t a, int64_t b, int64_t c, int64_t d, int64_t e); static invoker_l_lllll js_invoke_function_l_lllll; int CS_LDK_register_l_lllll_invoker(invoker_l_lllll invoker) { js_invoke_function_l_lllll = invoker; return 0; } -typedef int64_t (*invoker_l_lll)(int obj_ptr, int fn_id, int8_tArray a, int64_t b, int64_t c); +typedef int64_t (*invoker_l_lll)(int obj_ptr, int fn_id, int64_t a, int64_t b, int64_t c); static invoker_l_lll js_invoke_function_l_lll; int CS_LDK_register_l_lll_invoker(invoker_l_lll invoker) { js_invoke_function_l_lll = invoker; @@ -157,21 +157,21 @@ int CS_LDK_register_l_Recipient_invoker(invoker_l_Recipient invoker) { return 0; } -typedef int64_t (*invoker_l_Recipientll)(int obj_ptr, int fn_id, int32_t a, int8_tArray b, int64_t c); +typedef int64_t (*invoker_l_Recipientll)(int obj_ptr, int fn_id, int32_t a, int64_t b, int64_t c); static invoker_l_Recipientll js_invoke_function_l_Recipientll; int CS_LDK_register_l_Recipientll_invoker(invoker_l_Recipientll invoker) { js_invoke_function_l_Recipientll = invoker; return 0; } -typedef int64_t (*invoker_l_llRecipient)(int obj_ptr, int fn_id, int8_tArray a, ptrArray b, int32_t c); +typedef int64_t (*invoker_l_llRecipient)(int obj_ptr, int fn_id, int64_t a, int64_t b, int32_t c); static invoker_l_llRecipient js_invoke_function_l_llRecipient; int CS_LDK_register_l_llRecipient_invoker(invoker_l_llRecipient invoker) { js_invoke_function_l_llRecipient = invoker; return 0; } -typedef int8_tArray (*invoker_l_bll)(int obj_ptr, int fn_id, jboolean a, int64_t b, int8_tArray c); +typedef int64_t (*invoker_l_bll)(int obj_ptr, int fn_id, jboolean a, int64_t b, int64_t c); static invoker_l_bll js_invoke_function_l_bll; int CS_LDK_register_l_bll_invoker(invoker_l_bll invoker) { js_invoke_function_l_bll = invoker; @@ -185,7 +185,7 @@ int CS_LDK_register_i_ConfirmationTarget_invoker(invoker_i_ConfirmationTarget in return 0; } -typedef int64_t (*invoker_l_llllll)(int obj_ptr, int fn_id, int8_tArray a, int64_t b, int64_tArray c, int64_t d, int8_tArray e, int8_tArray f); +typedef int64_t (*invoker_l_llllll)(int obj_ptr, int fn_id, int64_t a, int64_t b, int64_t c, int64_t d, int64_t e, int64_t f); static invoker_l_llllll js_invoke_function_l_llllll; int CS_LDK_register_l_llllll_invoker(invoker_l_llllll invoker) { js_invoke_function_l_llllll = invoker; @@ -199,7 +199,7 @@ int CS_LDK_register_s__invoker(invoker_s_ invoker) { return 0; } -typedef int64_t (*invoker_l_lllb)(int obj_ptr, int fn_id, jstring a, jstring b, jstring c, jboolean d); +typedef int64_t (*invoker_l_lllb)(int obj_ptr, int fn_id, int64_t a, int64_t b, int64_t c, jboolean d); static invoker_l_lllb js_invoke_function_l_lllb; int CS_LDK_register_l_lllb_invoker(invoker_l_lllb invoker) { js_invoke_function_l_lllb = invoker; @@ -227,21 +227,21 @@ int CS_LDK_register_void__invoker(invoker_void_ invoker) { return 0; } -typedef void (*invoker_void_lli)(int obj_ptr, int fn_id, int8_tArray a, int64_tArray b, int32_t c); +typedef void (*invoker_void_lli)(int obj_ptr, int fn_id, int64_t a, int64_t b, int32_t c); static invoker_void_lli js_invoke_function_void_lli; int CS_LDK_register_void_lli_invoker(invoker_void_lli invoker) { js_invoke_function_void_lli = invoker; return 0; } -typedef void (*invoker_void_li)(int obj_ptr, int fn_id, int8_tArray a, int32_t b); +typedef void (*invoker_void_li)(int obj_ptr, int fn_id, int64_t a, int32_t b); static invoker_void_li js_invoke_function_void_li; int CS_LDK_register_void_li_invoker(invoker_void_li invoker) { js_invoke_function_void_li = invoker; return 0; } -typedef int64_t (*invoker_l_llb)(int obj_ptr, int fn_id, int8_tArray a, int64_t b, jboolean c); +typedef int64_t (*invoker_l_llb)(int obj_ptr, int fn_id, int64_t a, int64_t b, jboolean c); static invoker_l_llb js_invoke_function_l_llb; int CS_LDK_register_l_llb_invoker(invoker_l_llb invoker) { js_invoke_function_l_llb = invoker; @@ -255,14 +255,14 @@ int CS_LDK_register_b__invoker(invoker_b_ invoker) { return 0; } -typedef int64_t (*invoker_l_sl)(int obj_ptr, int fn_id, int16_t a, int8_tArray b); +typedef int64_t (*invoker_l_sl)(int obj_ptr, int fn_id, int16_t a, int64_t b); static invoker_l_sl js_invoke_function_l_sl; int CS_LDK_register_l_sl_invoker(invoker_l_sl invoker) { js_invoke_function_l_sl = invoker; return 0; } -typedef int64_t (*invoker_l_lb)(int obj_ptr, int fn_id, int8_tArray a, jboolean b); +typedef int64_t (*invoker_l_lb)(int obj_ptr, int fn_id, int64_t a, jboolean b); static invoker_l_lb js_invoke_function_l_lb; int CS_LDK_register_l_lb_invoker(invoker_l_lb invoker) { js_invoke_function_l_lb = invoker; @@ -276,7 +276,7 @@ int CS_LDK_register_b_l_invoker(invoker_b_l invoker) { return 0; } -typedef int64_t (*invoker_l_llli)(int obj_ptr, int fn_id, int8_tArray a, int64_tArray b, int64_tArray c, int32_t d); +typedef int64_t (*invoker_l_llli)(int obj_ptr, int fn_id, int64_t a, int64_t b, int64_t c, int32_t d); static invoker_l_llli js_invoke_function_l_llli; int CS_LDK_register_l_llli_invoker(invoker_l_llli invoker) { js_invoke_function_l_llli = invoker; @@ -12000,7 +12000,7 @@ LDKCResult_CVec_u8ZIOErrorZ read_LDKKVStore_jcall(const void* this_arg, LDKStr p LDKStr key_str = key; jstring key_conv = str_ref_to_cs(key_str.chars, key_str.len); Str_free(key_str); - uint64_t ret = js_invoke_function_l_lll(j_calls->instance_ptr, 53, primary_namespace_conv, secondary_namespace_conv, key_conv); + uint64_t ret = js_invoke_function_l_lll(j_calls->instance_ptr, 53, (int64_t)primary_namespace_conv, (int64_t)secondary_namespace_conv, (int64_t)key_conv); void* ret_ptr = untag_ptr(ret); CHECK_ACCESS(ret_ptr); LDKCResult_CVec_u8ZIOErrorZ ret_conv = *(LDKCResult_CVec_u8ZIOErrorZ*)(ret_ptr); @@ -12021,7 +12021,7 @@ LDKCResult_NoneIOErrorZ write_LDKKVStore_jcall(const void* this_arg, LDKStr prim LDKu8slice buf_var = buf; int8_tArray buf_arr = init_int8_tArray(buf_var.datalen, __LINE__); memcpy(buf_arr->elems, buf_var.data, buf_var.datalen); - uint64_t ret = js_invoke_function_l_llll(j_calls->instance_ptr, 54, primary_namespace_conv, secondary_namespace_conv, key_conv, (int64_t)buf_arr); + uint64_t ret = js_invoke_function_l_llll(j_calls->instance_ptr, 54, (int64_t)primary_namespace_conv, (int64_t)secondary_namespace_conv, (int64_t)key_conv, (int64_t)buf_arr); void* ret_ptr = untag_ptr(ret); CHECK_ACCESS(ret_ptr); LDKCResult_NoneIOErrorZ ret_conv = *(LDKCResult_NoneIOErrorZ*)(ret_ptr); @@ -12040,7 +12040,7 @@ LDKCResult_NoneIOErrorZ remove_LDKKVStore_jcall(const void* this_arg, LDKStr pri jstring key_conv = str_ref_to_cs(key_str.chars, key_str.len); Str_free(key_str); jboolean lazy_conv = lazy; - uint64_t ret = js_invoke_function_l_lllb(j_calls->instance_ptr, 55, primary_namespace_conv, secondary_namespace_conv, key_conv, lazy_conv); + uint64_t ret = js_invoke_function_l_lllb(j_calls->instance_ptr, 55, (int64_t)primary_namespace_conv, (int64_t)secondary_namespace_conv, (int64_t)key_conv, lazy_conv); void* ret_ptr = untag_ptr(ret); CHECK_ACCESS(ret_ptr); LDKCResult_NoneIOErrorZ ret_conv = *(LDKCResult_NoneIOErrorZ*)(ret_ptr); @@ -12055,7 +12055,7 @@ LDKCResult_CVec_StrZIOErrorZ list_LDKKVStore_jcall(const void* this_arg, LDKStr LDKStr secondary_namespace_str = secondary_namespace; jstring secondary_namespace_conv = str_ref_to_cs(secondary_namespace_str.chars, secondary_namespace_str.len); Str_free(secondary_namespace_str); - uint64_t ret = js_invoke_function_l_ll(j_calls->instance_ptr, 56, primary_namespace_conv, secondary_namespace_conv); + uint64_t ret = js_invoke_function_l_ll(j_calls->instance_ptr, 56, (int64_t)primary_namespace_conv, (int64_t)secondary_namespace_conv); void* ret_ptr = untag_ptr(ret); CHECK_ACCESS(ret_ptr); LDKCResult_CVec_StrZIOErrorZ ret_conv = *(LDKCResult_CVec_StrZIOErrorZ*)(ret_ptr); diff --git a/c_sharp/bindings.c.body b/c_sharp/bindings.c.body index 672bc9fa..b595907e 100644 --- a/c_sharp/bindings.c.body +++ b/c_sharp/bindings.c.body @@ -68,11 +68,11 @@ static inline LDKStr str_ref_to_owned_c(const jstring str) { typedef bool jboolean; int64_t CS_LDK_allocate_buffer(int64_t len) { - return MALLOC(len, "C#-requested buffer"); + return (int64_t)MALLOC(len, "C#-requested buffer"); } void CS_LDK_free_buffer(int64_t buf) { - FREE(buf); + FREE((void*)buf); } jstring CS_LDK_get_ldk_c_bindings_version() { @@ -83,21 +83,21 @@ jstring CS_LDK_get_ldk_version() { } #include "version.c" -typedef int8_tArray (*invoker_l_l)(int obj_ptr, int fn_id, int64_t a); +typedef int64_t (*invoker_l_l)(int obj_ptr, int fn_id, int64_t a); static invoker_l_l js_invoke_function_l_l; int CS_LDK_register_l_l_invoker(invoker_l_l invoker) { js_invoke_function_l_l = invoker; return 0; } -typedef int64_t (*invoker_l_ll)(int obj_ptr, int fn_id, int64_t a, ptrArray b); +typedef int64_t (*invoker_l_ll)(int obj_ptr, int fn_id, int64_t a, int64_t b); static invoker_l_ll js_invoke_function_l_ll; int CS_LDK_register_l_ll_invoker(invoker_l_ll invoker) { js_invoke_function_l_ll = invoker; return 0; } -typedef int8_tArray (*invoker_l_)(int obj_ptr, int fn_id); +typedef int64_t (*invoker_l_)(int obj_ptr, int fn_id); static invoker_l_ js_invoke_function_l_; int CS_LDK_register_l__invoker(invoker_l_ invoker) { js_invoke_function_l_ = invoker; @@ -111,21 +111,21 @@ int CS_LDK_register_void_l_invoker(invoker_void_l invoker) { return 0; } -typedef int64_t (*invoker_l_llll)(int obj_ptr, int fn_id, int8_tArray a, int64_t b, int64_t c, int8_tArray d); +typedef int64_t (*invoker_l_llll)(int obj_ptr, int fn_id, int64_t a, int64_t b, int64_t c, int64_t d); static invoker_l_llll js_invoke_function_l_llll; int CS_LDK_register_l_llll_invoker(invoker_l_llll invoker) { js_invoke_function_l_llll = invoker; return 0; } -typedef int64_t (*invoker_l_lllll)(int obj_ptr, int fn_id, int8_tArray a, int64_t b, int64_t c, int8_tArray d, int64_t e); +typedef int64_t (*invoker_l_lllll)(int obj_ptr, int fn_id, int64_t a, int64_t b, int64_t c, int64_t d, int64_t e); static invoker_l_lllll js_invoke_function_l_lllll; int CS_LDK_register_l_lllll_invoker(invoker_l_lllll invoker) { js_invoke_function_l_lllll = invoker; return 0; } -typedef int64_t (*invoker_l_lll)(int obj_ptr, int fn_id, int8_tArray a, int64_t b, int64_t c); +typedef int64_t (*invoker_l_lll)(int obj_ptr, int fn_id, int64_t a, int64_t b, int64_t c); static invoker_l_lll js_invoke_function_l_lll; int CS_LDK_register_l_lll_invoker(invoker_l_lll invoker) { js_invoke_function_l_lll = invoker; @@ -153,21 +153,21 @@ int CS_LDK_register_l_Recipient_invoker(invoker_l_Recipient invoker) { return 0; } -typedef int64_t (*invoker_l_Recipientll)(int obj_ptr, int fn_id, int32_t a, int8_tArray b, int64_t c); +typedef int64_t (*invoker_l_Recipientll)(int obj_ptr, int fn_id, int32_t a, int64_t b, int64_t c); static invoker_l_Recipientll js_invoke_function_l_Recipientll; int CS_LDK_register_l_Recipientll_invoker(invoker_l_Recipientll invoker) { js_invoke_function_l_Recipientll = invoker; return 0; } -typedef int64_t (*invoker_l_llRecipient)(int obj_ptr, int fn_id, int8_tArray a, ptrArray b, int32_t c); +typedef int64_t (*invoker_l_llRecipient)(int obj_ptr, int fn_id, int64_t a, int64_t b, int32_t c); static invoker_l_llRecipient js_invoke_function_l_llRecipient; int CS_LDK_register_l_llRecipient_invoker(invoker_l_llRecipient invoker) { js_invoke_function_l_llRecipient = invoker; return 0; } -typedef int8_tArray (*invoker_l_bll)(int obj_ptr, int fn_id, jboolean a, int64_t b, int8_tArray c); +typedef int64_t (*invoker_l_bll)(int obj_ptr, int fn_id, jboolean a, int64_t b, int64_t c); static invoker_l_bll js_invoke_function_l_bll; int CS_LDK_register_l_bll_invoker(invoker_l_bll invoker) { js_invoke_function_l_bll = invoker; @@ -181,7 +181,7 @@ int CS_LDK_register_i_ConfirmationTarget_invoker(invoker_i_ConfirmationTarget in return 0; } -typedef int64_t (*invoker_l_llllll)(int obj_ptr, int fn_id, int8_tArray a, int64_t b, int64_tArray c, int64_t d, int8_tArray e, int8_tArray f); +typedef int64_t (*invoker_l_llllll)(int obj_ptr, int fn_id, int64_t a, int64_t b, int64_t c, int64_t d, int64_t e, int64_t f); static invoker_l_llllll js_invoke_function_l_llllll; int CS_LDK_register_l_llllll_invoker(invoker_l_llllll invoker) { js_invoke_function_l_llllll = invoker; @@ -195,7 +195,7 @@ int CS_LDK_register_s__invoker(invoker_s_ invoker) { return 0; } -typedef int64_t (*invoker_l_lllb)(int obj_ptr, int fn_id, jstring a, jstring b, jstring c, jboolean d); +typedef int64_t (*invoker_l_lllb)(int obj_ptr, int fn_id, int64_t a, int64_t b, int64_t c, jboolean d); static invoker_l_lllb js_invoke_function_l_lllb; int CS_LDK_register_l_lllb_invoker(invoker_l_lllb invoker) { js_invoke_function_l_lllb = invoker; @@ -223,21 +223,21 @@ int CS_LDK_register_void__invoker(invoker_void_ invoker) { return 0; } -typedef void (*invoker_void_lli)(int obj_ptr, int fn_id, int8_tArray a, int64_tArray b, int32_t c); +typedef void (*invoker_void_lli)(int obj_ptr, int fn_id, int64_t a, int64_t b, int32_t c); static invoker_void_lli js_invoke_function_void_lli; int CS_LDK_register_void_lli_invoker(invoker_void_lli invoker) { js_invoke_function_void_lli = invoker; return 0; } -typedef void (*invoker_void_li)(int obj_ptr, int fn_id, int8_tArray a, int32_t b); +typedef void (*invoker_void_li)(int obj_ptr, int fn_id, int64_t a, int32_t b); static invoker_void_li js_invoke_function_void_li; int CS_LDK_register_void_li_invoker(invoker_void_li invoker) { js_invoke_function_void_li = invoker; return 0; } -typedef int64_t (*invoker_l_llb)(int obj_ptr, int fn_id, int8_tArray a, int64_t b, jboolean c); +typedef int64_t (*invoker_l_llb)(int obj_ptr, int fn_id, int64_t a, int64_t b, jboolean c); static invoker_l_llb js_invoke_function_l_llb; int CS_LDK_register_l_llb_invoker(invoker_l_llb invoker) { js_invoke_function_l_llb = invoker; @@ -251,14 +251,14 @@ int CS_LDK_register_b__invoker(invoker_b_ invoker) { return 0; } -typedef int64_t (*invoker_l_sl)(int obj_ptr, int fn_id, int16_t a, int8_tArray b); +typedef int64_t (*invoker_l_sl)(int obj_ptr, int fn_id, int16_t a, int64_t b); static invoker_l_sl js_invoke_function_l_sl; int CS_LDK_register_l_sl_invoker(invoker_l_sl invoker) { js_invoke_function_l_sl = invoker; return 0; } -typedef int64_t (*invoker_l_lb)(int obj_ptr, int fn_id, int8_tArray a, jboolean b); +typedef int64_t (*invoker_l_lb)(int obj_ptr, int fn_id, int64_t a, jboolean b); static invoker_l_lb js_invoke_function_l_lb; int CS_LDK_register_l_lb_invoker(invoker_l_lb invoker) { js_invoke_function_l_lb = invoker; @@ -272,7 +272,7 @@ int CS_LDK_register_b_l_invoker(invoker_b_l invoker) { return 0; } -typedef int64_t (*invoker_l_llli)(int obj_ptr, int fn_id, int8_tArray a, int64_tArray b, int64_tArray c, int32_t d); +typedef int64_t (*invoker_l_llli)(int obj_ptr, int fn_id, int64_t a, int64_t b, int64_t c, int32_t d); static invoker_l_llli js_invoke_function_l_llli; int CS_LDK_register_l_llli_invoker(invoker_l_llli invoker) { js_invoke_function_l_llli = invoker; @@ -11996,7 +11996,7 @@ LDKCResult_CVec_u8ZIOErrorZ read_LDKKVStore_jcall(const void* this_arg, LDKStr p LDKStr key_str = key; jstring key_conv = str_ref_to_cs(key_str.chars, key_str.len); Str_free(key_str); - uint64_t ret = js_invoke_function_l_lll(j_calls->instance_ptr, 53, primary_namespace_conv, secondary_namespace_conv, key_conv); + uint64_t ret = js_invoke_function_l_lll(j_calls->instance_ptr, 53, (int64_t)primary_namespace_conv, (int64_t)secondary_namespace_conv, (int64_t)key_conv); void* ret_ptr = untag_ptr(ret); CHECK_ACCESS(ret_ptr); LDKCResult_CVec_u8ZIOErrorZ ret_conv = *(LDKCResult_CVec_u8ZIOErrorZ*)(ret_ptr); @@ -12017,7 +12017,7 @@ LDKCResult_NoneIOErrorZ write_LDKKVStore_jcall(const void* this_arg, LDKStr prim LDKu8slice buf_var = buf; int8_tArray buf_arr = init_int8_tArray(buf_var.datalen, __LINE__); memcpy(buf_arr->elems, buf_var.data, buf_var.datalen); - uint64_t ret = js_invoke_function_l_llll(j_calls->instance_ptr, 54, primary_namespace_conv, secondary_namespace_conv, key_conv, (int64_t)buf_arr); + uint64_t ret = js_invoke_function_l_llll(j_calls->instance_ptr, 54, (int64_t)primary_namespace_conv, (int64_t)secondary_namespace_conv, (int64_t)key_conv, (int64_t)buf_arr); void* ret_ptr = untag_ptr(ret); CHECK_ACCESS(ret_ptr); LDKCResult_NoneIOErrorZ ret_conv = *(LDKCResult_NoneIOErrorZ*)(ret_ptr); @@ -12036,7 +12036,7 @@ LDKCResult_NoneIOErrorZ remove_LDKKVStore_jcall(const void* this_arg, LDKStr pri jstring key_conv = str_ref_to_cs(key_str.chars, key_str.len); Str_free(key_str); jboolean lazy_conv = lazy; - uint64_t ret = js_invoke_function_l_lllb(j_calls->instance_ptr, 55, primary_namespace_conv, secondary_namespace_conv, key_conv, lazy_conv); + uint64_t ret = js_invoke_function_l_lllb(j_calls->instance_ptr, 55, (int64_t)primary_namespace_conv, (int64_t)secondary_namespace_conv, (int64_t)key_conv, lazy_conv); void* ret_ptr = untag_ptr(ret); CHECK_ACCESS(ret_ptr); LDKCResult_NoneIOErrorZ ret_conv = *(LDKCResult_NoneIOErrorZ*)(ret_ptr); @@ -12051,7 +12051,7 @@ LDKCResult_CVec_StrZIOErrorZ list_LDKKVStore_jcall(const void* this_arg, LDKStr LDKStr secondary_namespace_str = secondary_namespace; jstring secondary_namespace_conv = str_ref_to_cs(secondary_namespace_str.chars, secondary_namespace_str.len); Str_free(secondary_namespace_str); - uint64_t ret = js_invoke_function_l_ll(j_calls->instance_ptr, 56, primary_namespace_conv, secondary_namespace_conv); + uint64_t ret = js_invoke_function_l_ll(j_calls->instance_ptr, 56, (int64_t)primary_namespace_conv, (int64_t)secondary_namespace_conv); void* ret_ptr = untag_ptr(ret); CHECK_ACCESS(ret_ptr); LDKCResult_CVec_StrZIOErrorZ ret_conv = *(LDKCResult_CVec_StrZIOErrorZ*)(ret_ptr); diff --git a/c_sharp/build-release-nupkg.sh b/c_sharp/build-release-nupkg.sh index 476a431d..b881848f 100755 --- a/c_sharp/build-release-nupkg.sh +++ b/c_sharp/build-release-nupkg.sh @@ -7,7 +7,7 @@ set -x echo "Checking that required release native libraries are present..." ls packaging_artifacts/runtimes/win-x64/native/ldkcsharp.dll ls packaging_artifacts/runtimes/linux-x64/native/libldkcsharp.so -ls packaging_artifacts/lib/net3.0/csharpldk.dll +ls packaging_artifacts/lib/net6.0/csharpldk.dll cd packaging_artifacts find . | xargs -L1 touch -d "2021-01-01 00:00 UTC" diff --git a/c_sharp/csharpldk.csproj b/c_sharp/csharpldk.csproj new file mode 100644 index 00000000..ef96f96b --- /dev/null +++ b/c_sharp/csharpldk.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + true + true + true + $(DefaultItemExcludes);test\**\* + + + diff --git a/c_sharp/packaging_artifacts/org.ldk.nuspec b/c_sharp/packaging_artifacts/org.ldk.nuspec index 74129edd..66d6a0dd 100644 --- a/c_sharp/packaging_artifacts/org.ldk.nuspec +++ b/c_sharp/packaging_artifacts/org.ldk.nuspec @@ -13,7 +13,7 @@ bitcoin lightning ldk sdk non-custodial - + diff --git a/csharp_strings.py b/csharp_strings.py index b1ae3d20..17b0bf88 100644 --- a/csharp_strings.py +++ b/csharp_strings.py @@ -391,11 +391,11 @@ static inline LDKStr str_ref_to_owned_c(const jstring str) { typedef bool jboolean; int64_t CS_LDK_allocate_buffer(int64_t len) { - return MALLOC(len, "C#-requested buffer"); + return (int64_t)MALLOC(len, "C#-requested buffer"); } void CS_LDK_free_buffer(int64_t buf) { - FREE(buf); + FREE((void*)buf); } jstring CS_LDK_get_ldk_c_bindings_version() { @@ -915,7 +915,10 @@ public class {struct_name.replace("LDK","")} : CommonBase {{ for arg_info in fn_line.args_ty: fn_suffix += ty_to_c(arg_info.java_ty, arg_info) fn_java_callback_args += ", " + arg_info.java_ty + " " + chr(ord("a") + idx) - fn_c_callback_args += ", " + arg_info.c_ty + " " + chr(ord("a") + idx) + if arg_info.c_ty.endswith("Array") or arg_info.c_ty == "jstring": + fn_c_callback_args += ", int64_t " + chr(ord("a") + idx) + else: + fn_c_callback_args += ", " + arg_info.c_ty + " " + chr(ord("a") + idx) if idx != 0: fn_callback_call_args += ", " fn_callback_call_args += chr(ord("a") + idx) @@ -933,13 +936,16 @@ public class {struct_name.replace("LDK","")} : CommonBase {{ out_c += "\tuint64_t ret = js_invoke_function_" + fn_suffix + "(j_calls->instance_ptr, " + str(self.function_ptr_counter) if fn_suffix not in self.function_ptrs: - self.function_ptrs[fn_suffix] = {"args": [fn_java_callback_args, fn_c_callback_args], "ret": [fn_line.ret_ty_info.java_ty, fn_line.ret_ty_info.c_ty]} + caller_ret_c_ty = fn_line.ret_ty_info.c_ty + if fn_line.ret_ty_info.c_ty.endswith("Array") or fn_line.ret_ty_info.c_ty == "jstring": + caller_ret_c_ty = "int64_t" + self.function_ptrs[fn_suffix] = {"args": [fn_java_callback_args, fn_c_callback_args], "ret": [fn_line.ret_ty_info.java_ty, caller_ret_c_ty]} self.function_ptrs[fn_suffix][self.function_ptr_counter] = (struct_name, fn_line.fn_name, fn_callback_call_args) self.function_ptr_counter += 1 for idx, arg_info in enumerate(fn_line.args_ty): if arg_info.ret_conv is not None: - if arg_info.c_ty.endswith("Array"): + if arg_info.c_ty.endswith("Array") or arg_info.c_ty == "jstring": out_c += ", (int64_t)" + arg_info.ret_conv_name else: out_c += ", " + arg_info.ret_conv_name diff --git a/genbindings.sh b/genbindings.sh index c4a1b270..2e07752a 100755 --- a/genbindings.sh +++ b/genbindings.sh @@ -43,6 +43,11 @@ case "$TARGET_STRING" in CS_PLATFORM_NAME="linux-x64" LDK_JAR_TARGET=true ;; + "x86_64-redhat-linux"*) + LDK_TARGET_SUFFIX="_Linux-amd64" + CS_PLATFORM_NAME="linux-x64" + LDK_JAR_TARGET=true + ;; "x86_64-apple-darwin"*) LDK_TARGET_SUFFIX="_MacOSX-x86_64" CS_PLATFORM_NAME="osx-x64" @@ -129,11 +134,12 @@ if [ "$2" = "c_sharp" ]; then fi # Compiling C# bindings with Mono - MONO_COMPILE="-out:csharpldk.dll -langversion:3 -t:library -unsafe c_sharp/src/org/ldk/enums/*.cs c_sharp/src/org/ldk/impl/*.cs c_sharp/src/org/ldk/util/*.cs c_sharp/src/org/ldk/structs/*.cs" if [ "$3" = "true" ]; then - mono-csc -g $MONO_COMPILE + mono-csc -g -out:csharpldk.dll -langversion:3 -t:library -unsafe c_sharp/src/org/ldk/enums/*.cs c_sharp/src/org/ldk/impl/*.cs c_sharp/src/org/ldk/util/*.cs c_sharp/src/org/ldk/structs/*.cs else - mono-csc -optimize+ $MONO_COMPILE + cd c_sharp + dotnet build --configuration Release + cd .. fi echo "Building C# bindings..." @@ -153,21 +159,23 @@ if [ "$2" = "c_sharp" ]; then [ "$IS_APPLE_CLANG" = "false" ] && COMPILE="$COMPILE -flto" [ "$IS_MAC" = "false" ] && LINK="$LINK -Wl,--no-undefined" [ "$IS_WIN" = "false" ] && LINK="$LINK -Wl,--lto-O3" - [ "$IS_WIN" = "true" ] && LINK="$LINK --target=x86_64-pc-windows-gnu -L/usr/lib/gcc/x86_64-w64-mingw32/12-win32/ -lbcrypt -static-libgcc" + [ "$IS_WIN" = "true" ] && LINK="$LINK --target=x86_64-pc-windows-gnu -L/usr/lib/gcc/x86_64-w64-mingw32/12-win32/ -lbcrypt -lntdll -static-libgcc" [ "$IS_WIN" = "true" ] && COMPILE="$COMPILE --target=x86_64-pc-windows-gnu" LDK_LIB="$1"/lightning-c-bindings/target/$LDK_TARGET/release/libldk.a if [ "$IS_MAC" = "false" -a "$IS_WIN" = "false" -a "$4" = "false" ]; then - LINK="$LINK -Wl,--version-script=c_sharp/libcode.version" + LINK="$LINK -Wl,--version-script=c_sharp/libcode.version -Wl,--build-id=0x0000000000000000" fi - $COMPILE -o bindings.o -c -O3 -I"$1"/lightning-c-bindings/include/ c_sharp/bindings.c - $COMPILE $LINK -o libldkcsharp_release$LDK_TARGET_SUFFIX.so -O3 bindings.o $LDK_LIB -lm + # When building for Windows, a timestamp is included in the resulting dll, + # so we have to build with faketime. + faketime -f "2021-01-01 00:00:00" $COMPILE -o bindings.o -c -O3 -I"$1"/lightning-c-bindings/include/ c_sharp/bindings.c + faketime -f "2021-01-01 00:00:00" $COMPILE $LINK -o libldkcsharp_release$LDK_TARGET_SUFFIX.so -O3 bindings.o $LDK_LIB -lm [ "$IS_APPLE_CLANG" != "true" ] && llvm-strip libldkcsharp_release$LDK_TARGET_SUFFIX.so if [ "$LDK_JAR_TARGET" = "true" ]; then # Copy resulting native binary for inclusion in release nuget zip - mkdir -p c_sharp/packaging_artifacts/lib/net3.0/ - cp csharpldk.dll c_sharp/packaging_artifacts/lib/net3.0/ + mkdir -p c_sharp/packaging_artifacts/lib/net6.0/ + cp c_sharp/bin/Release/net6.0/csharpldk.dll c_sharp/packaging_artifacts/lib/net6.0/ mkdir -p c_sharp/packaging_artifacts/runtimes/"$CS_PLATFORM_NAME"/native/ if [ "$IS_WIN" = "true" ]; then