Skip to content

Commit 152a1e4

Browse files
committed
Add swift type normalization as a method
1 parent 3213d4a commit 152a1e4

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

src/conversion_helper.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ class ConversionHelper:
1010
freeable_types = set()
1111
nullable_inner_types = {'LDKOutPoint'}
1212

13+
@classmethod
14+
def normalize_swift_type(cls, swift_type: str):
15+
if swift_type == 'Type':
16+
return 'BindingsType'
17+
18+
return swift_type
19+
1320
@classmethod
1421
def is_instance_type(cls, swift_type: str, raw_rust_type: str, include_options_and_results: bool = True):
1522
if raw_rust_type == 'LDK' + swift_type:

src/generators/trait_generator.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ def generate_trait(self, struct_name, struct_details):
2121
# native_method_names = ['ChannelHandler_openChannel', 'ChannelHandler_closeChannel']
2222

2323
# swift_struct_name = struct_name[3:] + 'Trait'
24-
swift_struct_name = struct_name[3:]
25-
if swift_struct_name == 'Type':
26-
swift_struct_name = 'BindingsType'
24+
swift_struct_name = ConversionHelper.normalize_swift_type(struct_name[3:])
2725

2826
native_callback_template_regex = re.compile("(\/\* NATIVE_CALLBACKS_START \*\/\n)(.*)(\n[\t ]*\/\* NATIVE_CALLBACKS_END \*\/)", flags=re.MULTILINE | re.DOTALL)
2927
native_callback_template = native_callback_template_regex.search(self.template).group(2)

src/swift_type_mapper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from src.binding_types import TypeInfo
22
from src.type_parsing_regeces import TypeParsingRegeces
3+
from src.conversion_helper import ConversionHelper
34

45
var_is_arr_regex = TypeParsingRegeces.IS_VARIABLE_AN_ARRAY_REGEX
56
var_ty_regex = TypeParsingRegeces.VARIABLE_TYPE_REGEX
@@ -291,8 +292,7 @@ def map_types_to_swift(fn_arg, ret_arr_len, java_c_types_none_allowed, tuple_typ
291292

292293
# TODO: remove java_hu_type vs java_type duality artifact
293294

294-
if swift_type == 'Type':
295-
swift_type = 'BindingsType'
295+
swift_type = ConversionHelper.normalize_swift_type(swift_type)
296296

297297
var_is_arr = var_is_arr_regex.match(fn_arg)
298298
if var_is_arr is not None or ret_arr_len is not None:

xcode/compile_dependency_binaries.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ usage() {
1212
exit 1
1313
}
1414

15-
[ "${LDK_DIRECTORY}" = "" ] && echo "Usage: ./docker_shell.sh /path/to/ldk-c-bindings" && exit 1;
15+
[ "${LDK_DIRECTORY}" = "" ] && echo "Usage: ./compile_dependency_binaries.sh /path/to/ldk-c-bindings" && exit 1;
1616
[ ! -d "${LDK_DIRECTORY}" ] && echo "Provided directory does not exist" && exit 1;
1717

1818

@@ -28,7 +28,8 @@ cp "${LDK_DIRECTORY}/ldk-net/ldk_net."{c,h} $DIRECT_BINDINGS_PROJECT_DIRECTORY
2828

2929
# build for Catalyst
3030
pushd $C_BINDINGS_SOURCE_DIRECTORY
31-
export RUSTFLAGS=""
31+
#export RUSTFLAGS=""
32+
export RUSTFLAGS="--cfg=c_bindings"
3233

3334
rustup override set nightly
3435
cargo clean

0 commit comments

Comments
 (0)