Skip to content

Commit

Permalink
[iOS] Enable built from prebuilt (#417)
Browse files Browse the repository at this point in the history
This PR enables build iOS app from prebuilt
model and library distro same as CLI
  • Loading branch information
tqchen authored Jun 15, 2023
1 parent 9c27e41 commit 210d301
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
10 changes: 5 additions & 5 deletions ios/MLCChat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
C0D643C429F99B07004DDAA4 /* ChatView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0D643C229F99B07004DDAA4 /* ChatView.swift */; };
C0D643C829F99B34004DDAA4 /* MessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0D643C729F99B34004DDAA4 /* MessageView.swift */; };
C0DDBDF62A39103F00E9D060 /* ChatState.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0D643C029F99B07004DDAA4 /* ChatState.swift */; };
C0DDBE0A2A391CCF00E9D060 /* MLCChatSwift in Frameworks */ = {isa = PBXBuildFile; productRef = C0DDBE092A391CCF00E9D060 /* MLCChatSwift */; };
C0DDBE0D2A3BCD8000E9D060 /* MLCSwift in Frameworks */ = {isa = PBXBuildFile; productRef = C0DDBE0C2A3BCD8000E9D060 /* MLCSwift */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -71,7 +71,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
C0DDBE0A2A391CCF00E9D060 /* MLCChatSwift in Frameworks */,
C0DDBE0D2A3BCD8000E9D060 /* MLCSwift in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -159,7 +159,7 @@
);
name = MLCChat;
packageProductDependencies = (
C0DDBE092A391CCF00E9D060 /* MLCChatSwift */,
C0DDBE0C2A3BCD8000E9D060 /* MLCSwift */,
);
productName = MLCChat;
productReference = C0D643AF29F99A7F004DDAA4 /* MLCChat.app */;
Expand Down Expand Up @@ -474,9 +474,9 @@
/* End XCConfigurationList section */

/* Begin XCSwiftPackageProductDependency section */
C0DDBE092A391CCF00E9D060 /* MLCChatSwift */ = {
C0DDBE0C2A3BCD8000E9D060 /* MLCSwift */ = {
isa = XCSwiftPackageProductDependency;
productName = MLCChatSwift;
productName = MLCSwift;
};
/* End XCSwiftPackageProductDependency section */
};
Expand Down
14 changes: 10 additions & 4 deletions ios/prepare_model_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ def main():
tar_list = []

for local_id in app_config["model_libs"]:
path = os.path.join(artifact_path, local_id, f"{local_id}-{target}.tar")
if not os.path.isfile(path):
raise RuntimeError(f"Cannot find {path}")
tar_list.append(path)
paths = [
os.path.join(artifact_path, local_id, f"{local_id}-{target}.tar"),
os.path.join(artifact_path, "prebuilt", "lib", f"{local_id}-{target}.tar")
]
valid_paths = [p for p in paths if os.path.isfile(p)]
if not valid_paths:
raise RuntimeError(
f"Cannot find lib for {local_id} in the following candidate path: {paths}"
)
tar_list.append(valid_paths[0])

cc.create_staticlib(os.path.join("build", "lib", "libmodel_iphone.a"), tar_list)
print(f"Creating lib from {tar_list}..")
Expand Down
11 changes: 10 additions & 1 deletion ios/prepare_params.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ declare -a builtin_list=(

for model in "${builtin_list[@]}"
do
cp -r ../dist/$model/params dist/$model
if [ -d ../dist/$model/params ]; then
cp -r ../dist/$model/params dist/$model
elif [ -d ../dist/prebuilt/$model ]; then
cp -r ../dist/prebuilt/$model dist/$model
elif [ -d ../dist/prebuilt/mlc-chat-$model ]; then
cp -r ../dist/prebuilt/mlc-chat-$model dist/$model
else
echo "Cannot find prebuilt weights for " $model
exit 1
fi
done

0 comments on commit 210d301

Please sign in to comment.