Skip to content

Commit bd8840d

Browse files
committed
Allow lipo binary path output override from env
1 parent 9b19f6c commit bd8840d

File tree

4 files changed

+58
-20
lines changed

4 files changed

+58
-20
lines changed

src/scripts/build_bulk_libldks.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@
99

1010

1111
def parse_config() -> ScriptConfig:
12-
config = ScriptConfig.parse(allow_ldk_argument=True, parse_configuration=(not CALL_INDIVIDUAL_BUILD_METHOD_VIA_SHELL))
13-
14-
individual_configurations: [BuildConfig] = [BuildConfig('iphoneos', '', ['arm64']),
15-
BuildConfig('iphonesimulator', '-simulator', ['arm64', 'x86_64']),
16-
BuildConfig('macosx', '', ['arm64', 'x86_64']),
17-
BuildConfig('macosx', '-macabi', ['arm64', 'x86_64']), ]
12+
config = ScriptConfig.parse(
13+
allow_ldk_argument=True,
14+
parse_configuration=(not CALL_INDIVIDUAL_BUILD_METHOD_VIA_SHELL)
15+
)
16+
17+
individual_configurations: [BuildConfig] = [
18+
BuildConfig('iphoneos', '', ['arm64']),
19+
BuildConfig('iphonesimulator', '-simulator', ['arm64', 'x86_64']),
20+
BuildConfig('macosx', '', ['arm64', 'x86_64']),
21+
BuildConfig('macosx', '-macabi', ['arm64', 'x86_64'])
22+
]
1823

1924
config.LIBLDK_BUILD_CONFIGURATIONS = individual_configurations
2025

src/scripts/build_individual_libldk.py

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
from script_config import ScriptConfig, BuildConfig
66

77

8-
def parse_config() -> ScriptConfig:
9-
config = ScriptConfig.parse(allow_ldk_argument=False, parse_configuration=True)
10-
return config
11-
12-
138
def run(config: ScriptConfig):
149
if len(config.LIBLDK_BUILD_CONFIGURATIONS) != 1:
1510
print('Individual libldk build must have exactly 1 build configuration.')
@@ -34,8 +29,20 @@ def run(config: ScriptConfig):
3429
print('Configuration:', config.RUST_CONFIGURATION)
3530
print('LLVM Target Triple Suffix:', llvm_target_triple_suffix)
3631

37-
individual_architecture_binary_directory = os.path.join(build_products_directory, config.RUST_CONFIGURATION, human_readable_platform, 'raw')
38-
lipo_binary_directory = os.path.join(build_products_directory, config.RUST_CONFIGURATION, human_readable_platform, 'lipo')
32+
individual_architecture_binary_directory = os.path.join(
33+
build_products_directory,
34+
config.RUST_CONFIGURATION,
35+
human_readable_platform,
36+
'raw'
37+
)
38+
lipo_binary_directory = os.path.join(
39+
build_products_directory,
40+
config.RUST_CONFIGURATION,
41+
human_readable_platform,
42+
'lipo'
43+
)
44+
if config.LIPO_BINARY_OUTPUT_DIRECTORY:
45+
lipo_binary_directory = config.LIPO_BINARY_OUTPUT_DIRECTORY
3946
lipo_binary_output_path = os.path.join(lipo_binary_directory, 'libldk.a')
4047

4148
print(individual_architecture_binary_directory)
@@ -50,7 +57,10 @@ def run(config: ScriptConfig):
5057
lipo_executables_input: [str] = []
5158

5259
for current_architecture in architectures:
53-
current_architecture_binary_directory = os.path.join(individual_architecture_binary_directory, current_architecture)
60+
current_architecture_binary_directory = os.path.join(
61+
individual_architecture_binary_directory,
62+
current_architecture
63+
)
5464
print(f'\nCurrent architecture:', current_architecture)
5565

5666
rust_architecture = current_architecture
@@ -64,7 +74,13 @@ def run(config: ScriptConfig):
6474
print('Rust architecture:', rust_architecture)
6575
print('Rust target OS:', rust_target_os)
6676

67-
cargo_raw_binary_origin = os.path.join(config.LDK_C_BINDINGS_DIRECTORY, 'target', f'{rust_architecture}-apple-{rust_target_os}', config.RUST_CONFIGURATION, 'libldk.a')
77+
cargo_raw_binary_origin = os.path.join(
78+
config.LDK_C_BINDINGS_DIRECTORY,
79+
'target',
80+
f'{rust_architecture}-apple-{rust_target_os}',
81+
config.RUST_CONFIGURATION,
82+
'libldk.a'
83+
)
6884
print('Raw binary origin:', cargo_raw_binary_origin)
6985
print('Raw binary target:', current_architecture_binary_directory)
7086

@@ -74,7 +90,12 @@ def run(config: ScriptConfig):
7490
subprocess.check_call(['cargo', 'clean'], cwd=config.LDK_C_BINDINGS_DIRECTORY)
7591

7692
# cargo build -Z build-std=panic_abort,std --features "std" --target "${RUST_ARCH}-apple-${RUST_TARGET_OS}" $RUST_CONFIGURATION_FLAG
77-
subprocess.check_call(['cargo', 'build', '-Z', 'build-std=panic_abort,std', '--features', 'std', '--target', f'{rust_architecture}-apple-{rust_target_os}', config.RUST_CONFIGURATION_FLAG], env=child_environment, cwd=config.LDK_C_BINDINGS_DIRECTORY)
93+
subprocess.check_call(
94+
['cargo', 'build', '-Z', 'build-std=panic_abort,std', '--features', 'std', '--target',
95+
f'{rust_architecture}-apple-{rust_target_os}', config.RUST_CONFIGURATION_FLAG],
96+
env=child_environment,
97+
cwd=config.LDK_C_BINDINGS_DIRECTORY
98+
)
7899

79100
# copy the generated binary to a monitored directory
80101
subprocess.check_call(['cp', cargo_raw_binary_origin, current_architecture_binary_directory])
@@ -83,11 +104,17 @@ def run(config: ScriptConfig):
83104
subprocess.check_call(['rustup', 'override', 'unset'], cwd=config.LDK_C_BINDINGS_DIRECTORY)
84105

85106
# xcrun --sdk $PLATFORM_NAME lipo -create "${EXECUTABLES[@]}" -output "${LIPO_BINARY_DIR}/${TARGET_NAME}.a"
86-
subprocess.check_call(['xcrun', '--sdk', platform, 'lipo', '-create', *lipo_executables_input, '-output', lipo_binary_output_path])
107+
subprocess.check_call(
108+
['xcrun', '--sdk', platform, 'lipo', '-create', *lipo_executables_input, '-output', lipo_binary_output_path]
109+
)
87110

88111

89112
if __name__ == '__main__':
90-
script_config = parse_config()
113+
script_config = ScriptConfig.parse(
114+
allow_ldk_argument=False,
115+
parse_configuration=True,
116+
parse_lipo_output_directory=True
117+
)
91118

92119
platform = os.getenv('PLATFORM')
93120
llvm_target_triple_suffix = os.getenv('LLVM_TARGET_TRIPLE_SUFFIX')

src/scripts/prepare_headers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ def run(config: ScriptConfig):
1010
os.path.join(config.LDK_C_BINDINGS_BASE, 'ldk-net'),
1111
]
1212

13-
header_destination_directory = os.path.realpath(os.path.join(os.path.dirname(__file__), '../../xcode/LDKFramework/headers'))
13+
header_destination_directory = os.path.realpath(
14+
os.path.join(os.path.dirname(__file__), '../../xcode/LDKFramework/headers')
15+
)
1416
os.makedirs(header_destination_directory, exist_ok=True)
1517

1618
for current_directory in header_directories:

src/scripts/script_config.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ def __init__(self):
1717
self.CONFIGURATION: str = ''
1818
self.RUST_CONFIGURATION: str = ''
1919
self.RUST_CONFIGURATION_FLAG: str = ''
20+
self.LIPO_BINARY_OUTPUT_DIRECTORY: str = ''
2021

2122
@classmethod
22-
def parse(cls, allow_ldk_argument=True, parse_configuration=False):
23+
def parse(cls, allow_ldk_argument=True, parse_configuration=False, parse_lipo_output_directory=False):
2324

2425
ldk_directory_string = os.getenv('LDK_C_BINDINGS_BASE')
2526
if allow_ldk_argument and len(sys.argv) > 1:
@@ -52,4 +53,7 @@ def parse(cls, allow_ldk_argument=True, parse_configuration=False):
5253
config.RUST_CONFIGURATION = 'release'
5354
config.RUST_CONFIGURATION_FLAG = '--release'
5455

56+
if parse_lipo_output_directory:
57+
config.LIPO_BINARY_OUTPUT_DIRECTORY = os.getenv('LDK_C_BINDINGS_BINARY_DIRECTORY')
58+
5559
return config

0 commit comments

Comments
 (0)