Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AppleAppBuilder] Entitlements to run tests on catalyst using the JIT #50637

Merged
5 commits merged into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ set_target_properties(%ProjectName% PROPERTIES
RESOURCE "${APP_RESOURCES}"
)

set(HARDENED_RUNTIME
%HardenedRuntime%
)

set(HARDENED_RUNTIME_USE_JIT
%HardenedRuntimeUseJit%
)

if("${HARDENED_RUNTIME}")
set_target_properties(%ProjectName% PROPERTIES XCODE_ATTRIBUTE_HARDENED_RUNTIME "YES")
if("${HARDENED_RUNTIME_USE_JIT}")
set_target_properties(%ProjectName% PROPERTIES XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS "app.entitlements")
endif()
endif()

# FIXME: `XCODE_ATTRIBUTE_DEAD_CODE_STRIPPING` should not be NO

target_link_libraries(
Expand Down
10 changes: 10 additions & 0 deletions src/tasks/AppleAppBuilder/Templates/app.entitlements.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
</dict>
</plist>
4 changes: 2 additions & 2 deletions src/tasks/AppleAppBuilder/Templates/runtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,14 @@
const char *appctx_keys [] = {
"RUNTIME_IDENTIFIER",
"APP_CONTEXT_BASE_DIRECTORY",
#ifndef INVARIANT_GLOBALIZATION
#if !defined(INVARIANT_GLOBALIZATION) && !TARGET_OS_MACCATALYST
"ICU_DAT_FILE_PATH"
#endif
};
const char *appctx_values [] = {
APPLE_RUNTIME_IDENTIFIER,
bundle,
#ifndef INVARIANT_GLOBALIZATION
#if !defined(INVARIANT_GLOBALIZATION) && !TARGET_OS_MACCATALYST
icu_dat_path
#endif
};
Expand Down
17 changes: 16 additions & 1 deletion src/tasks/AppleAppBuilder/Xcode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,20 @@ public string GenerateXCode(
}
}

bool hardenedRuntime = false;
bool hardenedRuntimeUseJit = false;
if (Target == TargetNames.MacCatalyst && !(forceInterpreter || forceAOT)) {
hardenedRuntime = true;
lambdageek marked this conversation as resolved.
Show resolved Hide resolved
hardenedRuntimeUseJit = true;
}

string cmakeLists = Utils.GetEmbeddedResource("CMakeLists.txt.template")
.Replace("%ProjectName%", projectName)
.Replace("%AppResources%", string.Join(Environment.NewLine, resources.Select(r => " " + r)))
.Replace("%MainSource%", nativeMainSource)
.Replace("%MonoInclude%", monoInclude);
.Replace("%MonoInclude%", monoInclude)
.Replace("%HardenedRuntime%", hardenedRuntime ? "TRUE" : "FALSE")
.Replace("%HardenedRuntimeUseJit%", hardenedRuntimeUseJit ? "TRUE" : "FALSE");


string[] dylibs = Directory.GetFiles(workspace, "*.dylib");
Expand Down Expand Up @@ -154,6 +163,12 @@ public string GenerateXCode(
File.WriteAllText(Path.Combine(binDir, "Info.plist"), plist);
File.WriteAllText(Path.Combine(binDir, "CMakeLists.txt"), cmakeLists);

if (hardenedRuntimeUseJit) {
/* FIXME: right now the entitlements template just hardcodes the JIT entitlement. */
string entitlements = Utils.GetEmbeddedResource("app.entitlements.template");
File.WriteAllText(Path.Combine(binDir, "app.entitlements"), entitlements);
}

string targetName;
switch (Target)
{
Expand Down