Skip to content

Commit 34d8c45

Browse files
committed
Make individual build script compatible with Xcode.
1 parent bd8840d commit 34d8c45

File tree

3 files changed

+86
-53
lines changed

3 files changed

+86
-53
lines changed

src/scripts/build_individual_libldk.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
from script_config import ScriptConfig, BuildConfig
66

7+
RUSTUP_PATH = os.getenv('HOME') + '/.cargo/bin/rustup'
8+
CARGO_PATH = os.getenv('HOME') + '/.cargo/bin/cargo'
9+
710

811
def run(config: ScriptConfig):
912
if len(config.LIBLDK_BUILD_CONFIGURATIONS) != 1:
@@ -12,15 +15,14 @@ def run(config: ScriptConfig):
1215

1316
ldkBuildConfig = config.LIBLDK_BUILD_CONFIGURATIONS[0]
1417
platform = ldkBuildConfig.platform
18+
human_readable_platform = ldkBuildConfig.human_readable_platform
1519
llvm_target_triple_suffix = ldkBuildConfig.llvm_target_triple_suffix
1620
architectures = ldkBuildConfig.architectures
1721

1822
build_products_directory = os.path.realpath(os.path.join(os.path.dirname(__file__), '../../bindings/bin'))
1923

20-
human_readable_platform = platform
2124
rust_target_os = 'ios'
2225
if platform == 'macosx' and llvm_target_triple_suffix == '-macabi':
23-
human_readable_platform = 'catalyst'
2426
rust_target_os = 'ios-macabi'
2527
elif platform == 'macosx':
2628
rust_target_os = 'darwin'
@@ -51,8 +53,9 @@ def run(config: ScriptConfig):
5153

5254
child_environment = dict(os.environ)
5355
child_environment['RUSTFLAGS'] = '--cfg=c_bindings'
56+
child_environment['PATH'] = '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin'
5457

55-
subprocess.check_call(['rustup', 'override', 'set', 'nightly'], cwd=config.LDK_C_BINDINGS_DIRECTORY)
58+
subprocess.check_call([RUSTUP_PATH, 'override', 'set', 'nightly'], cwd=config.LDK_C_BINDINGS_DIRECTORY)
5659

5760
lipo_executables_input: [str] = []
5861

@@ -87,12 +90,14 @@ def run(config: ScriptConfig):
8790
# create the directory if it doesn't exist
8891
os.makedirs(current_architecture_binary_directory, exist_ok=True)
8992

90-
subprocess.check_call(['cargo', 'clean'], cwd=config.LDK_C_BINDINGS_DIRECTORY)
93+
subprocess.check_call([CARGO_PATH, 'clean'], cwd=config.LDK_C_BINDINGS_DIRECTORY)
9194

9295
# cargo build -Z build-std=panic_abort,std --features "std" --target "${RUST_ARCH}-apple-${RUST_TARGET_OS}" $RUST_CONFIGURATION_FLAG
96+
build_arguments = [CARGO_PATH, 'build', '-Z', 'build-std=panic_abort,std', '--features', 'std', '--target', f'{rust_architecture}-apple-{rust_target_os}']
97+
if config.RUST_CONFIGURATION_FLAG:
98+
build_arguments.append(config.RUST_CONFIGURATION_FLAG)
9399
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],
100+
build_arguments,
96101
env=child_environment,
97102
cwd=config.LDK_C_BINDINGS_DIRECTORY
98103
)
@@ -101,7 +106,7 @@ def run(config: ScriptConfig):
101106
subprocess.check_call(['cp', cargo_raw_binary_origin, current_architecture_binary_directory])
102107
lipo_executables_input.append(os.path.join(current_architecture_binary_directory, 'libldk.a'))
103108

104-
subprocess.check_call(['rustup', 'override', 'unset'], cwd=config.LDK_C_BINDINGS_DIRECTORY)
109+
subprocess.check_call([RUSTUP_PATH, 'override', 'unset'], cwd=config.LDK_C_BINDINGS_DIRECTORY)
105110

106111
# xcrun --sdk $PLATFORM_NAME lipo -create "${EXECUTABLES[@]}" -output "${LIPO_BINARY_DIR}/${TARGET_NAME}.a"
107112
subprocess.check_call(
@@ -116,7 +121,7 @@ def run(config: ScriptConfig):
116121
parse_lipo_output_directory=True
117122
)
118123

119-
platform = os.getenv('PLATFORM')
124+
platform = os.getenv('PLATFORM_NAME')
120125
llvm_target_triple_suffix = os.getenv('LLVM_TARGET_TRIPLE_SUFFIX')
121126
architectures = os.getenv('ARCHS').split(' ')
122127

src/scripts/script_config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ def __init__(self, platform: str, llvm_target_triple_suffix: str, architectures:
88
self.llvm_target_triple_suffix = llvm_target_triple_suffix
99
self.architectures = architectures
1010

11+
if not self.platform:
12+
self.platform = 'macosx'
13+
14+
self.human_readable_platform = self.platform
15+
if self.platform == 'macosx' and llvm_target_triple_suffix == '-macabi':
16+
self.human_readable_platform = 'catalyst'
17+
1118

1219
class ScriptConfig:
1320
def __init__(self):

0 commit comments

Comments
 (0)