Skip to content

Commit

Permalink
Fix DTA iOS compilation, and consume native from xcframework (backport
Browse files Browse the repository at this point in the history
…#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]>
  • Loading branch information
6 people authored Sep 1, 2022
1 parent 4ad58a3 commit a3eeba4
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 106 deletions.
4 changes: 4 additions & 0 deletions common/config/azure-pipelines/templates/core-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ steps:
displayName: rush build
workingDirectory: ${{ parameters.workingDir }}
condition: and(succeeded(), eq(variables['Build.Reason'], 'PullRequest'), eq(variables['Agent.OS'], 'Darwin'))
- script: npm run build:ios
workingDirectory: "test-apps/display-test-app"
displayName: "Build iOS display-test-app"
condition: and(succeeded(), eq(variables['Build.Reason'], 'PullRequest'), eq(variables['Agent.OS'], 'Darwin'))
- script: node common/scripts/install-run-rush.js lint
displayName: rush lint
workingDirectory: ${{ parameters.workingDir }}
Expand Down
78 changes: 78 additions & 0 deletions common/scripts/update-imodeljs-native-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash

usage() {
echo "Updates the itwinjs-core repository to use a new version of the @bentley/imodeljs-native package."
echo "Usage: $0 -v VERSION"
echo " -v VERSION: The semantic version (e.g., 3.2.7) of the @bentley/imodeljs-native package to which to update."
}

checkfail() {
if [ $? -ne 0 ]; then
>&2 echo "Error - aborting."
exit 1
fi
}

while getopts "v:" options; do
case "${options}" in
v) AddonVersion=${OPTARG} ;;
?) usage ; exit 1 ;;
esac
done

if [ "$AddonVersion" = "" ]; then
usage
exit 1
fi

# Find repo root and verify it's an itwinjs-core repo.
RepoRoot=`git rev-parse --show-toplevel`
if [[ $? -ne 0 || ! -f "$RepoRoot/core/backend/package.json" ]]; then
>&2 echo "This script must be executed from within itwinjs-core repo."
exit 1;
fi

updatePackageJson() {
packageJson="$RepoRoot/$1/package.json"
packageTmp="$RepoRoot/package.json.tmp"
jq --arg version $AddonVersion '.dependencies."@bentley/imodeljs-native"=$version' "$packageJson" > "$packageTmp"
checkfail
mv "$packageTmp" "$packageJson"
checkfail
}

echo "Updating @bentley/imodeljs-native to $AddonVersion..."

# Update package.json files
updatePackageJson "core/backend"
updatePackageJson "full-stack-tests/backend"

# Update XCode projects. This relies on the "version = " string occurring exactly once, specifying the imodeljs-native version.
PbxProj1="$RepoRoot/tools/internal/ios/core-test-runner/core-test-runner.xcodeproj/project.pbxproj"
PbxProj2="$RepoRoot/test-apps/display-test-app/ios/imodeljs-test-app/imodeljs-test-app.xcodeproj/project.pbxproj"

for PbxProj in PbxProj1 PbxProj2
do
sed -i "s/version = .*;/version = $AddonVersion;/" "$PbxProj"
done

# Purge node_modules
rm "$RepoRoot/common/config/rush/browser-approved-packages.json"
rm "$RepoRoot/common/config/rush/pnpm-lock.yaml"
rm -rf "$RepoRoot/common/temp"

# Update to new @bentley/imodeljs-native package.
rush update
checkfail

git commit -am"@bentley/imodeljs-native $AddonVersion"
checkfail

# Generate empty change logs.
yes "" | rush change
checkfail

git add "$RepoRoot/common/changes"
git commit --amend --no-edit

echo "Update complete."
1 change: 1 addition & 0 deletions test-apps/display-test-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Package.resolved
Empty file.
27 changes: 17 additions & 10 deletions test-apps/display-test-app/ios/backend.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,33 +43,40 @@ function getConfig(env) {
devtool: "source-map",
resolve: { mainFields: ["main", "module"] },
module: {
// don't parse @bentley/imodeljs-native/NativeLibrary.js,
// we don't need to pull in the Native here as it gets loaded by the runtime
// via (process as any)._linkedBinding("iModelJsNative")
noParse: [/NativeLibrary.js$/],
rules: [
{
test: /AzCopyFileHandler\.js/g,
use: 'null-loader'
use: "null-loader",
},
{
test: /itwin\+electron-authorization/g,
use: 'null-loader'
use: "null-loader",
},
{
test: /ElectronBackend\.js/g,
use: 'null-loader'
}
]
use: "null-loader",
},
],
},
stats: {
warnings: false
warnings: false,
},
externals: {
"electron": "electron",
"bufferutil": "bufferutil",
"utf-8-validate": "utf-8-validate"
electron: "electron",
bufferutil: "bufferutil",
"utf-8-validate": "utf-8-validate",
},
plugins: [
new plugins.CopyAppAssetsPlugin("./assets/"),
new plugins.CopyBentleyStaticResourcesPlugin(["assets"]),
new webpack.DefinePlugin({ "global.GENTLY": false, "process.version": "'v10.9.0'" })
new webpack.DefinePlugin({
"global.GENTLY": false,
"process.version": "'v10.9.0'",
}),
],
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 52;
objects = {

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

/* Begin PBXCopyFilesBuildPhase section */
Expand All @@ -27,7 +26,6 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
4180D5322472EEBB00EF5E14 /* IModelJsNative.framework in Embed Libraries */,
);
name = "Embed Libraries";
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -47,15 +45,14 @@
415D589B23E38D0C00907B7B /* Config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = "<group>"; };
415D58A423E3907C00907B7B /* imodeljs-test-app-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "imodeljs-test-app-Bridging-Header.h"; sourceTree = "<group>"; };
415D58B623E4ACAA00907B7B /* AssetHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssetHandler.swift; sourceTree = "<group>"; };
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; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
415D587D23E37F5200907B7B /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
4180D5312472EEBB00EF5E14 /* IModelJsNative.framework in Frameworks */,
F4A4D86028A599050015ED63 /* IModelJsNative in Frameworks */,
415D58A123E38DD100907B7B /* WebKit.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -100,7 +97,6 @@
415D589823E38CCF00907B7B /* Frameworks */ = {
isa = PBXGroup;
children = (
4180D5302472EEBB00EF5E14 /* IModelJsNative.framework */,
415D589923E38CCF00907B7B /* WebKit.framework */,
);
name = Frameworks;
Expand All @@ -124,6 +120,9 @@
dependencies = (
);
name = "imodeljs-test-app";
packageProductDependencies = (
F4A4D85F28A599050015ED63 /* IModelJsNative */,
);
productName = "imodeljs-test-app";
productReference = 415D588023E37F5200907B7B /* imodeljs-test-app.app */;
productType = "com.apple.product-type.application";
Expand Down Expand Up @@ -153,6 +152,9 @@
Base,
);
mainGroup = 415D587723E37F5200907B7B;
packageReferences = (
F4A4D85E28A599050015ED63 /* XCRemoteSwiftPackageReference "mobile-native-ios" */,
);
productRefGroup = 415D588123E37F5200907B7B /* Products */;
projectDirPath = "";
projectRoot = "";
Expand Down Expand Up @@ -425,6 +427,25 @@
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
F4A4D85E28A599050015ED63 /* XCRemoteSwiftPackageReference "mobile-native-ios" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/iTwin/mobile-native-ios";
requirement = {
kind = exactVersion;
version = 3.3.13;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
F4A4D85F28A599050015ED63 /* IModelJsNative */ = {
isa = XCSwiftPackageProductDependency;
package = F4A4D85E28A599050015ED63 /* XCRemoteSwiftPackageReference "mobile-native-ios" */;
productName = IModelJsNative;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 415D587823E37F5200907B7B /* Project object */;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}

func application(_ application: UIApplication,
handleEventsForBackgroundURLSession identifier: String,
completionHandler: @escaping () -> Void) {
IModelJsHost.sharedInstance().backgroundDownloadCompletionHandler = completionHandler;
}

func application(_ app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
// Sends the URL to the current authorization flow (if any) which will
// process it if it relates to an authorization response.
return IModelJsHost.sharedInstance().resumeExternalUserAgentFlow(url)
// Your additional URL handling (if any)
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ViewController: UIViewController, WKUIDelegate, WKNavigationDelegate, UIDo
let bundlePath = Bundle.main.bundlePath;
let mainPath = bundlePath.appending ("/Assets/main.js");
let main = URL(fileURLWithPath: mainPath);
let client = MobileAuthorizationClient(viewController: self);
let client:AuthorizationClient? = nil;
host.loadBackend(main, withAuthClient: client,withInspect: true)
}

Expand Down Expand Up @@ -47,7 +47,13 @@ class ViewController: UIViewController, WKUIDelegate, WKNavigationDelegate, UIDo

var queryParam = String(format: "#port=%u&platform=ios", host.getPort());
if (bimFile != nil) {
let encodedPath = bimFile?.path.replacingOccurrences(of: "/", with: "%2F");
// Note: URL strings probably allow other characters, but we know for sure that these all work.
// Also, we can't use `CharacterSet.alphanumerics` as a base, because that includes all Unicode
// upper case and lower case letters, and we only want ASCII upper case and lower case letters.
// Similarly, `CharacterSet.decimalDigits` includes the Unicode category Number, Decimal Digit,
// which contains 660 characters.
let allowedCharacters = CharacterSet(charactersIn: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.")
let encodedPath = bimFile?.path.addingPercentEncoding(withAllowedCharacters: allowedCharacters)!
queryParam.append("&standalone=true");
queryParam.append("&iModelName=" + encodedPath!);
}
Expand Down
72 changes: 0 additions & 72 deletions test-apps/display-test-app/ios/scripts/installIosNativeLib.js

This file was deleted.

7 changes: 3 additions & 4 deletions test-apps/display-test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@
"test": "",
"cover": "",
"copy:config": "internal-tools copy-config",
"build:ios-backend": "npm run -s build:backend && webpack --config ./ios/backend.config --env.outdir=./lib/ios --env.entry=./lib/backend/MobileMain.js --env.bundlename=main",
"install-ios-lib": "node ./ios/scripts/installIosNativeLib.js",
"build:ios-backend": "npm run -s build:backend && webpack --config ./ios/backend.config --env outdir=./lib/ios --env entry=./lib/backend/MobileMain.js --env bundlename=main",
"copy:ios-frontend": "mkdir -p ./lib/ios && rm -rf ./lib/ios/www && cp -R ./build ./lib/ios/www",
"build:ios": "npm run -s install-ios-lib && npm run -s build:frontend && npm run -s build:ios-backend && npm run -s copy:ios-frontend",
"build:ios": "npm run -s build:frontend-webpack && npm run -s build:ios-backend && npm run -s copy:ios-frontend",
"build:android-backend": "npm run -s build:backend && webpack --config ./android/backend.config --env.outdir=./lib/android --env.entry=./lib/backend/MobileMain.js --env.bundlename=main",
"install-android-lib": "node ./android/scripts/installAndroidNativeLib.js",
"copy:android-assets": "node ./android/scripts/copyAndroidAssets.js",
"build:android": "npm run -s install-android-lib && npm run -s build:frontend && npm run -s build:android-backend && npm run -s copy:android-assets"
"build:android": "npm run -s install-android-lib && npm run -s build:frontend-webpack && npm run -s build:android-backend && npm run -s copy:android-assets"
},
"repository": {},
"dependencies": {
Expand Down

0 comments on commit a3eeba4

Please sign in to comment.