This repository has been archived by the owner on Mar 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
build.py
57 lines (48 loc) · 1.79 KB
/
build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import os
import shutil
from distutils.core import Distribution
from pathlib import Path
from subprocess import call
from setuptools_rust import Binding, RustExtension, build_rust
# class BuildFailed(Exception):
# pass
def build(setup_kwargs):
"""
This function is mandatory in order to build the extensions.
"""
print("setup_kwargs:", setup_kwargs)
print("os.curdir:", os.getcwd())
original_project_dir = os.path.dirname(os.path.realpath(__file__))
cargo_toml_path = os.path.join("defi-wallet-core-rs", "common", "Cargo.toml")
print("original_project_dir:", original_project_dir)
print("cargo_toml_path:", cargo_toml_path)
print(os.listdir())
target_name = "chainlibpy.generated.defi_wallet_core_common"
extension = RustExtension(
target=target_name,
path=cargo_toml_path,
features=["uniffi-binding"],
binding=Binding.NoBinding,
)
print(extension)
# lib_name = extension.get_lib_name(quiet=False)
# print("lib_name:", lib_name)
# https://docs.python.org/3/distutils/apiref.html#distutils.core.Distribution
dist = Distribution(attrs=setup_kwargs)
builder = build_rust(dist)
builder.initialize_options()
builder.finalize_options()
dpaths = builder.build_extension(extension)
builder.install_extension(extension, dylib_paths=dpaths)
print("Extension built!")
print("*********** 0.")
call(["find", "."])
print("*********** 1.")
p = Path(builder.get_dylib_ext_path(extension, target_name))
np = Path(p.parent, "{}{}".format("libdefi_wallet_core_common", p.suffix))
p.rename(np)
shutil.copyfile(
np, os.path.join("chainlibpy", "generated", "libdefi_wallet_core_common" + p.suffix)
)
print("dylib path:", p)
# raise BuildFailed("Just to see the logs")