Initial Support for MacOS IL2CPP Builds (#326)

* Add intial framework for macos builds. Test install editor

* Fix unity hub path space

* Single quote space in path

* Escape space character

* More backslashes

* Move to bash scripts for setup

* Add path to command args

* Different command to run shell script

* Use full path to scripts

* Unpack changeset value and fix missing escape characters

* Print changeset

* More debug

* Remove debug

* Fix script paths

* Printenv debug

* Write environment variables to file to read in bash script

* Debug file write

* More debug

* Fix missing await

* Move back to process.env

* Fix path typo

* Add missing flags

* Make directory for license activation

* Add missing sudo

* Give permissions to license folder

* Fix path issues

* Add build tests

* Try ts setup again

* Try quoting path

* Further migrate mac scripts to align with linux scripts

* print pwd

* Fix changeset and remove unneeded env vars

* Ignore return code

* fix missing current directory

* Fix project path

* pwd

* Remove project path

* Revert to cwd being the workspace folder and pass action folder as an env variable.

* Add blank project to use for activation

* Add blank project path

* Fix build tests

* Don't rebuild library on windows

* Fix project path windows

* Fix platform specific workspace env variable

* Fix incorrect variable name

* Update .github/workflows/mac-build-tests.yml

Co-authored-by: Webber Takken <webber.nl@gmail.com>

* Update .github/workflows/mac-build-tests.yml

Co-authored-by: Webber Takken <webber.nl@gmail.com>

* Update dist/BlankProject/Packages/packages-lock.json

Co-authored-by: Webber Takken <webber.nl@gmail.com>

* Update src/model/platform-setup/setup-mac.ts

Co-authored-by: Webber Takken <webber.nl@gmail.com>

* Update src/model/platform-setup/setup-mac.ts

Co-authored-by: Webber Takken <webber.nl@gmail.com>

* Fix formatting

Co-authored-by: Webber Takken <webber.nl@gmail.com>
This commit is contained in:
AndrewKahr
2022-02-02 01:15:37 -08:00
committed by GitHub
parent 9f13e1d9cf
commit c7907c7e78
55 changed files with 149397 additions and 5008 deletions

View File

@@ -1,6 +1,7 @@
import * as core from '@actions/core';
import { Action, BuildParameters, Cache, Docker, ImageTag, Output, CloudRunner } from './model';
import { CLI } from './model/cli/cli';
import MacBuilder from './model/mac-builder';
import PlatformSetup from './model/platform-setup';
async function runMain() {
try {
@@ -11,6 +12,9 @@ async function runMain() {
const buildParameters = await BuildParameters.create();
const baseImage = new ImageTag(buildParameters);
let builtImage;
if (
buildParameters.cloudRunnerCluster &&
buildParameters.cloudRunnerCluster !== '' &&
@@ -19,9 +23,13 @@ async function runMain() {
await CloudRunner.run(buildParameters, baseImage.toString());
} else {
core.info('Building locally');
PlatformSetup.setup(buildParameters);
const builtImage = await Docker.build({ path: actionFolder, dockerfile, baseImage });
await Docker.run(builtImage, { workspace, ...buildParameters });
await PlatformSetup.setup(buildParameters, actionFolder);
if (process.platform === 'darwin') {
MacBuilder.run(actionFolder, workspace, buildParameters);
} else {
builtImage = await Docker.build({ path: actionFolder, dockerfile, baseImage });
await Docker.run(builtImage, { workspace, ...buildParameters });
}
}
// Set output

View File

@@ -1,4 +1,4 @@
/* eslint-disable unicorn/prevent-abbreviations */
/* eslint unicorn/prevent-abbreviations: "off" */
// Import these named export into your test file:
export const mockProjectPath = jest.fn().mockResolvedValue('mockProjectPath');

View File

@@ -4,11 +4,15 @@ import Action from './action';
describe('Action', () => {
describe('compatibility check', () => {
it('throws for anything other than linux or windows', () => {
if (process.platform !== 'linux' && process.platform !== 'win32') {
expect(() => Action.checkCompatibility()).toThrow();
} else {
expect(() => Action.checkCompatibility()).not.toThrow();
it('throws for anything other than linux, windows, or mac', () => {
switch (process.platform) {
case 'linux':
case 'win32':
case 'darwin':
expect(() => Action.checkCompatibility()).not.toThrow();
break;
default:
expect(() => Action.checkCompatibility()).toThrow();
}
});
});

View File

@@ -2,7 +2,7 @@ import path from 'path';
class Action {
static get supportedPlatforms() {
return ['linux', 'win32'];
return ['linux', 'win32', 'darwin'];
}
static get isRunningLocally() {
@@ -36,6 +36,8 @@ class Action {
return `${Action.actionFolder}/platforms/ubuntu/Dockerfile`;
case 'win32':
return `${Action.actionFolder}/platforms/windows/Dockerfile`;
case 'darwin':
return 'unused'; //Mac doesn't use a container
default:
throw new Error(`No Dockerfile for currently unsupported platform: ${currentPlatform}`);
}

View File

@@ -43,6 +43,7 @@ class Docker {
switch (baseOs) {
case 'linux':
return `--env UNITY_SERIAL \
--env GITHUB_WORKSPACE=/github/workspace \
${sshAgent ? '--env SSH_AUTH_SOCK=/ssh-agent' : ''} \
--volume "/var/run/docker.sock":"/var/run/docker.sock" \
--volume "${runnerTemporaryPath}/_github_home":"/root" \
@@ -52,6 +53,7 @@ class Docker {
${sshAgent ? '--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro' : ''}`;
case 'win32':
return `--env UNITY_SERIAL="${unitySerial}" \
--env GITHUB_WORKSPACE=c:/github/workspace \
--volume "${workspace}":"c:/github/workspace" \
--volume "c:/regkeys":"c:/regkeys" \
--volume "C:/Program Files (x86)/Microsoft Visual Studio":"C:/Program Files (x86)/Microsoft Visual Studio" \

13
src/model/mac-builder.ts Normal file
View File

@@ -0,0 +1,13 @@
import { exec } from '@actions/exec';
import { BuildParameters } from '.';
class MacBuilder {
public static async run(actionFolder, workspace, buildParameters: BuildParameters, silent = false) {
await exec('bash', [`${actionFolder}/platforms/mac/entrypoint.sh`], {
silent,
ignoreReturnCode: true,
});
}
}
export default MacBuilder;

View File

@@ -1,14 +1,17 @@
import { BuildParameters } from '.';
import SetupWindows from './platform-setup/setup-windows';
import { SetupWindows, SetupMac } from './platform-setup/';
import ValidateWindows from './platform-validation/validate-windows';
class PlatformSetup {
static async setup(buildParameters: BuildParameters) {
static async setup(buildParameters: BuildParameters, actionFolder: string) {
switch (process.platform) {
case 'win32':
ValidateWindows.validate(buildParameters);
SetupWindows.setup(buildParameters);
break;
case 'darwin':
await SetupMac.setup(buildParameters, actionFolder);
break;
//Add other baseOS's here
}
}

View File

@@ -0,0 +1,4 @@
import SetupWindows from './setup-windows';
import SetupMac from './setup-mac';
export { SetupWindows, SetupMac };

View File

@@ -0,0 +1,75 @@
import { BuildParameters } from '..';
import { getUnityChangeset } from 'unity-changeset';
import { exec } from '@actions/exec';
import fs from 'fs';
class SetupMac {
static unityHubPath = `"/Applications/Unity Hub.app/Contents/MacOS/Unity Hub"`;
public static async setup(buildParameters: BuildParameters, actionFolder: string) {
const unityEditorPath = `/Applications/Unity/Hub/Editor/${buildParameters.version}/Unity.app/Contents/MacOS/Unity`;
// Only install unity if the editor doesn't already exist
if (!fs.existsSync(unityEditorPath)) {
await SetupMac.installUnityHub();
await SetupMac.installUnity(buildParameters);
}
await SetupMac.setEnvironmentVariables(buildParameters, actionFolder);
}
private static async installUnityHub(silent = false) {
const command = 'brew install unity-hub';
if (!fs.existsSync(this.unityHubPath)) {
// Ignoring return code because the log seems to overflow the internal buffer which triggers
// a false error
const errorCode = await exec(command, undefined, { silent, ignoreReturnCode: true });
if (errorCode) {
throw new Error(`There was an error installing the Unity Editor. See logs above for details.`);
}
}
}
private static async installUnity(buildParameters: BuildParameters, silent = false) {
const unityChangeset = await getUnityChangeset(buildParameters.version);
const command = `${this.unityHubPath} -- --headless install \
--version ${buildParameters.version} \
--changeset ${unityChangeset.changeset} \
--module mac-il2cpp \
--childModules`;
// Ignoring return code because the log seems to overflow the internal buffer which triggers
// a false error
const errorCode = await exec(command, undefined, { silent, ignoreReturnCode: true });
if (errorCode) {
throw new Error(`There was an error installing the Unity Editor. See logs above for details.`);
}
}
private static async setEnvironmentVariables(buildParameters: BuildParameters, actionFolder: string) {
// Need to set environment variables from here because we execute
// the scripts on the host for mac
process.env.ACTION_FOLDER = actionFolder;
process.env.UNITY_VERSION = buildParameters.version;
process.env.UNITY_SERIAL = buildParameters.unitySerial;
process.env.PROJECT_PATH = buildParameters.projectPath;
process.env.BUILD_TARGET = buildParameters.platform;
process.env.BUILD_NAME = buildParameters.buildName;
process.env.BUILD_PATH = buildParameters.buildPath;
process.env.BUILD_FILE = buildParameters.buildFile;
process.env.BUILD_METHOD = buildParameters.buildMethod;
process.env.VERSION = buildParameters.buildVersion;
process.env.ANDROID_VERSION_CODE = buildParameters.androidVersionCode;
process.env.ANDROID_KEYSTORE_NAME = buildParameters.androidKeystoreName;
process.env.ANDROID_KEYSTORE_BASE64 = buildParameters.androidKeystoreBase64;
process.env.ANDROID_KEYSTORE_PASS = buildParameters.androidKeystorePass;
process.env.ANDROID_KEYALIAS_NAME = buildParameters.androidKeyaliasName;
process.env.ANDROID_KEYALIAS_PASS = buildParameters.androidKeyaliasPass;
process.env.ANDROID_TARGET_SDK_VERSION = buildParameters.androidTargetSdkVersion;
process.env.ANDROID_SDK_MANAGER_PARAMETERS = buildParameters.androidSdkManagerParameters;
process.env.CUSTOM_PARAMETERS = buildParameters.customParameters;
process.env.CHOWN_FILES_TO = buildParameters.chownFilesTo;
}
}
export default SetupMac;