Fix strict-aliasing violation on traits holding inner fields
[ldk-c-bindings] / genbindings.sh
index 1d53b96ca1804077661b7603e9974c1f75615350..c5025982dc36a15704da88bbd69580ee1bcc2d49 100755 (executable)
@@ -231,6 +231,9 @@ cbindgen -v --config cbindgen.toml -o include/lightning.h >/dev/null 2>&1
 if is_gnu_sed; then
        sed -i 's/typedef LDKnative.*Import.*LDKnative.*;//g' include/lightning.h
 
+       # UnsafeCell is `repr(transparent)` so should be ignored here
+       sed -i 's/LDKUnsafeCell<\(.*\)> /\1 /g' include/lightning.h
+
        # stdlib.h doesn't exist in clang's wasm sysroot, and cbindgen
        # doesn't actually use it anyway, so drop the import.
        sed -i 's/#include <stdlib.h>/#include "ldk_rust_types.h"/g' include/lightning.h
@@ -238,6 +241,9 @@ else
        # OSX sed is for some reason not compatible with GNU sed
        sed -i '' 's/typedef LDKnative.*Import.*LDKnative.*;//g' include/lightning.h
 
+       # UnsafeCell is `repr(transparent)` so should be ignored by cbindgen
+       sed -i '' 's/LDKUnsafeCell<\(.*\)> /\1 /g' include/lightning.h
+
        # stdlib.h doesn't exist in clang's wasm sysroot, and cbindgen
        # doesn't actually use it anyway, so drop the import.
        sed -i '' 's/#include <stdlib.h>/#include "ldk_rust_types.h"/g' include/lightning.h