Skip to content

Commit a3eeba4

Browse files
mergify[bot]aruniversepmconnemarkschlosseratbentleyskirby1996
authored
Fix DTA iOS compilation, and consume native from xcframework (backport #4151) (#4163)
Co-authored-by: Arun George <[email protected]> Co-authored-by: Paul Connelly <[email protected]> Co-authored-by: Arun George <[email protected]> Co-authored-by: Mark Schlosser <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Seamus Kirby <[email protected]>
1 parent 4ad58a3 commit a3eeba4

File tree

11 files changed

+142
-106
lines changed

11 files changed

+142
-106
lines changed

common/config/azure-pipelines/templates/core-build.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ steps:
3232
displayName: rush build
3333
workingDirectory: ${{ parameters.workingDir }}
3434
condition: and(succeeded(), eq(variables['Build.Reason'], 'PullRequest'), eq(variables['Agent.OS'], 'Darwin'))
35+
- script: npm run build:ios
36+
workingDirectory: "test-apps/display-test-app"
37+
displayName: "Build iOS display-test-app"
38+
condition: and(succeeded(), eq(variables['Build.Reason'], 'PullRequest'), eq(variables['Agent.OS'], 'Darwin'))
3539
- script: node common/scripts/install-run-rush.js lint
3640
displayName: rush lint
3741
workingDirectory: ${{ parameters.workingDir }}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/bin/bash
2+
3+
usage() {
4+
echo "Updates the itwinjs-core repository to use a new version of the @bentley/imodeljs-native package."
5+
echo "Usage: $0 -v VERSION"
6+
echo " -v VERSION: The semantic version (e.g., 3.2.7) of the @bentley/imodeljs-native package to which to update."
7+
}
8+
9+
checkfail() {
10+
if [ $? -ne 0 ]; then
11+
>&2 echo "Error - aborting."
12+
exit 1
13+
fi
14+
}
15+
16+
while getopts "v:" options; do
17+
case "${options}" in
18+
v) AddonVersion=${OPTARG} ;;
19+
?) usage ; exit 1 ;;
20+
esac
21+
done
22+
23+
if [ "$AddonVersion" = "" ]; then
24+
usage
25+
exit 1
26+
fi
27+
28+
# Find repo root and verify it's an itwinjs-core repo.
29+
RepoRoot=`git rev-parse --show-toplevel`
30+
if [[ $? -ne 0 || ! -f "$RepoRoot/core/backend/package.json" ]]; then
31+
>&2 echo "This script must be executed from within itwinjs-core repo."
32+
exit 1;
33+
fi
34+
35+
updatePackageJson() {
36+
packageJson="$RepoRoot/$1/package.json"
37+
packageTmp="$RepoRoot/package.json.tmp"
38+
jq --arg version $AddonVersion '.dependencies."@bentley/imodeljs-native"=$version' "$packageJson" > "$packageTmp"
39+
checkfail
40+
mv "$packageTmp" "$packageJson"
41+
checkfail
42+
}
43+
44+
echo "Updating @bentley/imodeljs-native to $AddonVersion..."
45+
46+
# Update package.json files
47+
updatePackageJson "core/backend"
48+
updatePackageJson "full-stack-tests/backend"
49+
50+
# Update XCode projects. This relies on the "version = " string occurring exactly once, specifying the imodeljs-native version.
51+
PbxProj1="$RepoRoot/tools/internal/ios/core-test-runner/core-test-runner.xcodeproj/project.pbxproj"
52+
PbxProj2="$RepoRoot/test-apps/display-test-app/ios/imodeljs-test-app/imodeljs-test-app.xcodeproj/project.pbxproj"
53+
54+
for PbxProj in PbxProj1 PbxProj2
55+
do
56+
sed -i "s/version = .*;/version = $AddonVersion;/" "$PbxProj"
57+
done
58+
59+
# Purge node_modules
60+
rm "$RepoRoot/common/config/rush/browser-approved-packages.json"
61+
rm "$RepoRoot/common/config/rush/pnpm-lock.yaml"
62+
rm -rf "$RepoRoot/common/temp"
63+
64+
# Update to new @bentley/imodeljs-native package.
65+
rush update
66+
checkfail
67+
68+
git commit -am"@bentley/imodeljs-native $AddonVersion"
69+
checkfail
70+
71+
# Generate empty change logs.
72+
yes "" | rush change
73+
checkfail
74+
75+
git add "$RepoRoot/common/changes"
76+
git commit --amend --no-edit
77+
78+
echo "Update complete."
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Package.resolved

test-apps/display-test-app/assets/Settings/Schemas/.empty

Whitespace-only changes.

test-apps/display-test-app/ios/backend.config.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,33 +43,40 @@ function getConfig(env) {
4343
devtool: "source-map",
4444
resolve: { mainFields: ["main", "module"] },
4545
module: {
46+
// don't parse @bentley/imodeljs-native/NativeLibrary.js,
47+
// we don't need to pull in the Native here as it gets loaded by the runtime
48+
// via (process as any)._linkedBinding("iModelJsNative")
49+
noParse: [/NativeLibrary.js$/],
4650
rules: [
4751
{
4852
test: /AzCopyFileHandler\.js/g,
49-
use: 'null-loader'
53+
use: "null-loader",
5054
},
5155
{
5256
test: /itwin\+electron-authorization/g,
53-
use: 'null-loader'
57+
use: "null-loader",
5458
},
5559
{
5660
test: /ElectronBackend\.js/g,
57-
use: 'null-loader'
58-
}
59-
]
61+
use: "null-loader",
62+
},
63+
],
6064
},
6165
stats: {
62-
warnings: false
66+
warnings: false,
6367
},
6468
externals: {
65-
"electron": "electron",
66-
"bufferutil": "bufferutil",
67-
"utf-8-validate": "utf-8-validate"
69+
electron: "electron",
70+
bufferutil: "bufferutil",
71+
"utf-8-validate": "utf-8-validate",
6872
},
6973
plugins: [
7074
new plugins.CopyAppAssetsPlugin("./assets/"),
7175
new plugins.CopyBentleyStaticResourcesPlugin(["assets"]),
72-
new webpack.DefinePlugin({ "global.GENTLY": false, "process.version": "'v10.9.0'" })
76+
new webpack.DefinePlugin({
77+
"global.GENTLY": false,
78+
"process.version": "'v10.9.0'",
79+
}),
7380
],
7481
};
7582

test-apps/display-test-app/ios/imodeljs-test-app/imodeljs-test-app.xcodeproj/project.pbxproj

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 50;
6+
objectVersion = 52;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -16,8 +16,7 @@
1616
415D589C23E38D0C00907B7B /* Config.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 415D589B23E38D0C00907B7B /* Config.xcconfig */; };
1717
415D58A123E38DD100907B7B /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 415D589923E38CCF00907B7B /* WebKit.framework */; };
1818
415D58B723E4ACAA00907B7B /* AssetHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 415D58B623E4ACAA00907B7B /* AssetHandler.swift */; };
19-
4180D5312472EEBB00EF5E14 /* IModelJsNative.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4180D5302472EEBB00EF5E14 /* IModelJsNative.framework */; };
20-
4180D5322472EEBB00EF5E14 /* IModelJsNative.framework in Embed Libraries */ = {isa = PBXBuildFile; fileRef = 4180D5302472EEBB00EF5E14 /* IModelJsNative.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
19+
F4A4D86028A599050015ED63 /* IModelJsNative in Frameworks */ = {isa = PBXBuildFile; productRef = F4A4D85F28A599050015ED63 /* IModelJsNative */; };
2120
/* End PBXBuildFile section */
2221

2322
/* Begin PBXCopyFilesBuildPhase section */
@@ -27,7 +26,6 @@
2726
dstPath = "";
2827
dstSubfolderSpec = 10;
2928
files = (
30-
4180D5322472EEBB00EF5E14 /* IModelJsNative.framework in Embed Libraries */,
3129
);
3230
name = "Embed Libraries";
3331
runOnlyForDeploymentPostprocessing = 0;
@@ -47,15 +45,14 @@
4745
415D589B23E38D0C00907B7B /* Config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = "<group>"; };
4846
415D58A423E3907C00907B7B /* imodeljs-test-app-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "imodeljs-test-app-Bridging-Header.h"; sourceTree = "<group>"; };
4947
415D58B623E4ACAA00907B7B /* AssetHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssetHandler.swift; sourceTree = "<group>"; };
50-
4180D5302472EEBB00EF5E14 /* IModelJsNative.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IModelJsNative.framework; path = "../../node_modules/@itwin/core-backend/node_modules/@bentley/imodeljs-native/imodeljs-ios-arm64//IModelJsNative.framework"; sourceTree = SOURCE_ROOT; };
5148
/* End PBXFileReference section */
5249

5350
/* Begin PBXFrameworksBuildPhase section */
5451
415D587D23E37F5200907B7B /* Frameworks */ = {
5552
isa = PBXFrameworksBuildPhase;
5653
buildActionMask = 2147483647;
5754
files = (
58-
4180D5312472EEBB00EF5E14 /* IModelJsNative.framework in Frameworks */,
55+
F4A4D86028A599050015ED63 /* IModelJsNative in Frameworks */,
5956
415D58A123E38DD100907B7B /* WebKit.framework in Frameworks */,
6057
);
6158
runOnlyForDeploymentPostprocessing = 0;
@@ -100,7 +97,6 @@
10097
415D589823E38CCF00907B7B /* Frameworks */ = {
10198
isa = PBXGroup;
10299
children = (
103-
4180D5302472EEBB00EF5E14 /* IModelJsNative.framework */,
104100
415D589923E38CCF00907B7B /* WebKit.framework */,
105101
);
106102
name = Frameworks;
@@ -124,6 +120,9 @@
124120
dependencies = (
125121
);
126122
name = "imodeljs-test-app";
123+
packageProductDependencies = (
124+
F4A4D85F28A599050015ED63 /* IModelJsNative */,
125+
);
127126
productName = "imodeljs-test-app";
128127
productReference = 415D588023E37F5200907B7B /* imodeljs-test-app.app */;
129128
productType = "com.apple.product-type.application";
@@ -153,6 +152,9 @@
153152
Base,
154153
);
155154
mainGroup = 415D587723E37F5200907B7B;
155+
packageReferences = (
156+
F4A4D85E28A599050015ED63 /* XCRemoteSwiftPackageReference "mobile-native-ios" */,
157+
);
156158
productRefGroup = 415D588123E37F5200907B7B /* Products */;
157159
projectDirPath = "";
158160
projectRoot = "";
@@ -425,6 +427,25 @@
425427
defaultConfigurationName = Release;
426428
};
427429
/* End XCConfigurationList section */
430+
431+
/* Begin XCRemoteSwiftPackageReference section */
432+
F4A4D85E28A599050015ED63 /* XCRemoteSwiftPackageReference "mobile-native-ios" */ = {
433+
isa = XCRemoteSwiftPackageReference;
434+
repositoryURL = "https://github.com/iTwin/mobile-native-ios";
435+
requirement = {
436+
kind = exactVersion;
437+
version = 3.3.13;
438+
};
439+
};
440+
/* End XCRemoteSwiftPackageReference section */
441+
442+
/* Begin XCSwiftPackageProductDependency section */
443+
F4A4D85F28A599050015ED63 /* IModelJsNative */ = {
444+
isa = XCSwiftPackageProductDependency;
445+
package = F4A4D85E28A599050015ED63 /* XCRemoteSwiftPackageReference "mobile-native-ios" */;
446+
productName = IModelJsNative;
447+
};
448+
/* End XCSwiftPackageProductDependency section */
428449
};
429450
rootObject = 415D587823E37F5200907B7B /* Project object */;
430451
}

test-apps/display-test-app/ios/imodeljs-test-app/imodeljs-test-app.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test-apps/display-test-app/ios/imodeljs-test-app/imodeljs-test-app/AppDelegate.swift

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2727
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
2828
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
2929
}
30-
30+
3131
func application(_ application: UIApplication,
3232
handleEventsForBackgroundURLSession identifier: String,
3333
completionHandler: @escaping () -> Void) {
3434
IModelJsHost.sharedInstance().backgroundDownloadCompletionHandler = completionHandler;
3535
}
36-
37-
func application(_ app: UIApplication,
38-
open url: URL,
39-
options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
40-
// Sends the URL to the current authorization flow (if any) which will
41-
// process it if it relates to an authorization response.
42-
return IModelJsHost.sharedInstance().resumeExternalUserAgentFlow(url)
43-
// Your additional URL handling (if any)
44-
}
36+
4537
}
4638

test-apps/display-test-app/ios/imodeljs-test-app/imodeljs-test-app/ViewController.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ViewController: UIViewController, WKUIDelegate, WKNavigationDelegate, UIDo
1515
let bundlePath = Bundle.main.bundlePath;
1616
let mainPath = bundlePath.appending ("/Assets/main.js");
1717
let main = URL(fileURLWithPath: mainPath);
18-
let client = MobileAuthorizationClient(viewController: self);
18+
let client:AuthorizationClient? = nil;
1919
host.loadBackend(main, withAuthClient: client,withInspect: true)
2020
}
2121

@@ -47,7 +47,13 @@ class ViewController: UIViewController, WKUIDelegate, WKNavigationDelegate, UIDo
4747

4848
var queryParam = String(format: "#port=%u&platform=ios", host.getPort());
4949
if (bimFile != nil) {
50-
let encodedPath = bimFile?.path.replacingOccurrences(of: "/", with: "%2F");
50+
// Note: URL strings probably allow other characters, but we know for sure that these all work.
51+
// Also, we can't use `CharacterSet.alphanumerics` as a base, because that includes all Unicode
52+
// upper case and lower case letters, and we only want ASCII upper case and lower case letters.
53+
// Similarly, `CharacterSet.decimalDigits` includes the Unicode category Number, Decimal Digit,
54+
// which contains 660 characters.
55+
let allowedCharacters = CharacterSet(charactersIn: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.")
56+
let encodedPath = bimFile?.path.addingPercentEncoding(withAllowedCharacters: allowedCharacters)!
5157
queryParam.append("&standalone=true");
5258
queryParam.append("&iModelName=" + encodedPath!);
5359
}

test-apps/display-test-app/ios/scripts/installIosNativeLib.js

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)