Skip to content

Commit

Permalink
Enable cross-compilation from Linux to Mac (#13537)
Browse files Browse the repository at this point in the history
* Enable cross-compilation from Linux to Mac
  • Loading branch information
mherrmann authored Jul 7, 2022
1 parent 04d2722 commit 32ff5ab
Show file tree
Hide file tree
Showing 12 changed files with 206 additions and 89 deletions.
39 changes: 28 additions & 11 deletions DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ deps = {
"vendor/boto": "https://github.com/boto/boto@f7574aa6cc2c819430c1f05e9a1a1a666ef8169b",
"vendor/python-patch": "https://github.com/brave/python-patch@d8880110be6554686bc08261766538c2926d4e82",
"vendor/omaha": "https://github.com/brave/omaha.git@3fe2f833fabd91f943a0babd5c69c4a55b1570cf",
"vendor/sparkle": "https://github.com/brave/Sparkle.git@57fb153bea4c71ed10102d50e68ead89ca483b49",
"vendor/sparkle": "https://github.com/brave/Sparkle.git@f69ba7b7fae7dda475ba6cda12fba8d72270478d",
"vendor/bat-native-rapidjson": "https://github.com/brave-intl/bat-native-rapidjson.git@60b7e4574cebdd79f441bdd6f0f3ab469fd7e04c",
"vendor/bip39wally-core-native": "https://github.com/brave-intl/bat-native-bip39wally-core.git@0d3a8713a2b388d2156fe49a70ef3f7cdb44b190",
"vendor/bat-native-anonize": "https://github.com/brave-intl/bat-native-anonize.git@e3742ba3e8942eea9e4755d91532491871bd3116",
Expand All @@ -26,6 +26,10 @@ recursedeps = [
'vendor/omaha'
]

vars = {
'download_prebuilt_sparkle': True
}

hooks = [
{
'name': 'bootstrap',
Expand All @@ -36,31 +40,44 @@ hooks = [
# Download hermetic xcode for goma
'name': 'download_hermetic_xcode',
'pattern': '.',
'condition': 'host_os == "mac"',
'condition': 'checkout_mac or checkout_ios',
'action': ['vpython3', 'build/mac/download_hermetic_xcode.py'],
},
{
# Download rust deps if necessary for Android
'name': 'download_sparkle',
'pattern': '.',
'condition': 'checkout_mac and download_prebuilt_sparkle',
'action': ['vpython3', 'build/mac/download_sparkle.py', '1.24.2'],
},
{
'name': 'download_rust_deps',
'pattern': '.',
'condition': 'checkout_android',
'action': ['vpython3', 'script/download_rust_deps.py',
'--platform', 'android'],
'action': ['vpython3', 'script/download_rust_deps.py', 'android'],
},
{
# Download rust deps if necessary for iOS
'name': 'download_rust_deps',
'pattern': '.',
'condition': 'checkout_ios',
'action': ['vpython3', 'script/download_rust_deps.py',
'--platform', 'ios'],
'action': ['vpython3', 'script/download_rust_deps.py', 'ios'],
},
{
# Download rust deps if necessary for Windows, Linux, and macOS
'name': 'download_rust_deps',
'pattern': '.',
'condition': 'not checkout_android and not checkout_ios',
'action': ['vpython3', 'script/download_rust_deps.py'],
'condition': 'checkout_win',
'action': ['vpython3', 'script/download_rust_deps.py', 'win32'],
},
{
'name': 'download_rust_deps',
'pattern': '.',
'condition': 'checkout_mac',
'action': ['vpython3', 'script/download_rust_deps.py', 'darwin'],
},
{
'name': 'download_rust_deps',
'pattern': '.',
'condition': 'checkout_linux',
'action': ['vpython3', 'script/download_rust_deps.py', 'linux'],
},
{
# Install Web Discovery Project dependencies for Windows, Linux, and macOS
Expand Down
13 changes: 12 additions & 1 deletion browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ buildflag_header("sparkle_buildflags") {
flags = [ "ENABLE_SPARKLE=$enable_sparkle" ]
}

if (enable_sparkle && !build_sparkle) {
bundle_data("prebuilt_sparkle_framework_bundle_data") {
sources = [ "//build/mac_files/sparkle_binaries/Sparkle.framework" ]
outputs = [ "{{bundle_contents_dir}}/Frameworks/{{source_file_part}}" ]
}
}

source_set("browser_process") {
visibility = [
"//brave/browser/*",
Expand Down Expand Up @@ -43,7 +50,11 @@ group("browser") {
]

if (enable_sparkle) {
deps = [ "//brave/vendor/sparkle:sparkle_framework_bundle_data" ]
if (build_sparkle) {
deps = [ "//brave/vendor/sparkle:sparkle_framework_bundle_data" ]
} else {
deps = [ ":prebuilt_sparkle_framework_bundle_data" ]
}
}

# Group depending on upstream's counterpart to make it easier to manage
Expand Down
32 changes: 22 additions & 10 deletions build/commands/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,6 @@ Config.prototype.buildArgs = function () {

if (process.platform === 'darwin') {
args.allow_runtime_configurable_key_storage = true
// always use hermetic xcode for macos when available
if (this.targetOS !== 'ios' && fs.existsSync(path.join(
this.srcDir, 'build', 'mac_files', 'xcode_binaries', 'Contents'))) {
args.use_system_xcode = false
}
}

if (this.isDebug() &&
Expand Down Expand Up @@ -397,15 +392,22 @@ Config.prototype.buildArgs = function () {
args.symbol_level = 1
}

if (this.targetArch === 'x64' &&
process.platform === 'linux' &&
this.targetOS !== 'android') {
if (this.getTargetOS() === 'mac' &&
fs.existsSync(path.join(this.srcDir, 'build', 'mac_files', 'xcode_binaries', 'Contents'))) {
// always use hermetic xcode for macos when available
args.use_system_xcode = false
}

if (this.getTargetOS() === 'linux' && this.targetArch === 'x64') {
// Include vaapi support
args.use_vaapi = true
}

if (this.targetOS) {
args.target_os = this.targetOS;
}

if (this.targetOS === 'android') {
args.target_os = 'android'
args.android_channel = this.channel
args.enable_jdk_library_desugaring = false
if (!this.isOfficialBuild()) {
Expand Down Expand Up @@ -462,7 +464,6 @@ Config.prototype.buildArgs = function () {
}

if (this.targetOS === 'ios') {
args.target_os = 'ios'
if (this.targetEnvironment) {
args.target_environment = this.targetEnvironment
}
Expand Down Expand Up @@ -887,6 +888,17 @@ Config.prototype.update = function (options) {
}
}

Config.prototype.getTargetOS = function() {
if (this.targetOS)
return this.targetOS
if (process.platform === 'darwin')
return 'mac'
if (process.platform === 'win32')
return 'win'
assert(process.platform === 'linux')
return 'linux'
}

Config.prototype.getCachePath = function () {
return this.git_cache_path || process.env.GIT_CACHE_PATH
}
Expand Down
6 changes: 2 additions & 4 deletions build/commands/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,8 @@ const util = {
let out = 'solutions = ' + JSON.stringify(solutions, replacer, 2)
.replace(/"%None%"/g, "None").replace(/"%False%"/g, "False").replace(/"%True%"/g, "True") + cache_dir

if (config.targetOS === 'android') {
out = out + "target_os = [ 'android' ]"
} else if (config.targetOS === 'ios') {
out = out + "target_os = [ 'ios' ]"
if (config.targetOS) {
out = out + "target_os = [ '" + config.targetOS + "' ]"
}

fs.writeFileSync(config.defaultGClientFile, out)
Expand Down
1 change: 1 addition & 0 deletions build/commands/scripts/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ program
.option('--goma_offline', 'use offline mode for goma')
.option('--force_gn_gen', 'always run gn gen')
.option('--target <target>', 'Custom target to build, instead of the default browser target')
.option('--build_sparkle', 'Build the Sparkle macOS update framework from source')
.arguments('[build_config]')
.action(build)

Expand Down
1 change: 1 addition & 0 deletions build/config.gni
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ declare_args() {
is_release_channel = false
base_sparkle_update_url = ""
enable_sparkle = !is_component_build && is_mac
build_sparkle = false

sparkle_dsa_private_key_file = ""
sparkle_eddsa_private_key = ""
Expand Down
54 changes: 34 additions & 20 deletions build/mac/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ dmg_icon = rebase_path("//brave/build/mac/$dmg_icon_file_name.icns")
action("generate_dsa_sig_for_dmg") {
script = "generate_sig.py"

sign_update_path = "$root_out_dir/old_dsa_scripts/sign_update"
if (build_sparkle) {
sign_update_path = "$root_out_dir/old_dsa_scripts/sign_update"
} else {
sign_update_path = "//build/mac_files/sparkle_binaries/sign_update_dsa"
}
target_dmg_path = "$root_out_dir/$brave_dmg"
output_dmg_dsa_path = "$root_out_dir/$brave_dmg.dsa"

Expand All @@ -129,16 +133,22 @@ action("generate_dsa_sig_for_dmg") {

outputs = [ "$output_dmg_dsa_path" ]

deps = [
":copy_dmg_pkg",
"//brave/vendor/sparkle:copy_old_sign_update",
]
deps = [ ":copy_dmg_pkg" ]

if (build_sparkle) {
deps += [ "//brave/vendor/sparkle:copy_old_sign_update" ]
}
}

action("generate_eddsa_sig_for_dmg") {
script = "generate_sig.py"

sign_update_path = "$root_out_dir/sign_update"
if (build_sparkle) {
sign_update_path = "$root_out_dir/sign_update"
} else {
sign_update_path = "//build/mac_files/sparkle_binaries/sign_update"
}

target_dmg_path = "$root_out_dir/$brave_dmg"
output_dmg_eddsa_path = "$root_out_dir/$brave_dmg.eddsa"

Expand All @@ -162,16 +172,22 @@ action("generate_eddsa_sig_for_dmg") {

outputs = [ "$output_dmg_eddsa_path" ]

deps = [
":copy_dmg_pkg",
"//brave/vendor/sparkle:build_sparkle_framework",
]
deps = [ ":copy_dmg_pkg" ]

if (build_sparkle) {
deps += [ "//brave/vendor/sparkle:build_sparkle_framework" ]
}
}

action("build_delta_installer") {
script = "build_delta_installer.py"

binary_delta_path = "$root_out_dir/BinaryDelta"
if (build_sparkle) {
binary_delta_path = "$root_out_dir/BinaryDelta"
} else {
binary_delta_path = "//build/mac_files/sparkle_binaries/BinaryDelta"
}

target_dmg_path = "$root_out_dir/$brave_dmg"
output_delta_path = "$root_out_dir/$brave_delta"

Expand All @@ -196,16 +212,17 @@ action("build_delta_installer") {

outputs = [ "$output_delta_path" ]

deps = [
":copy_dmg_pkg",
"//brave/vendor/sparkle:build_sparkle_framework",
]
deps = [ ":copy_dmg_pkg" ]

if (build_sparkle) {
deps += [ "//brave/vendor/sparkle:build_sparkle_framework" ]
}
}

action("generate_eddsa_sig_for_delta") {
script = "generate_sig.py"

sign_update_path = "$root_out_dir/sign_update"
sign_update_path = "//build/mac_files/sparkle_binaries/sign_update"
target_delta_path = "$root_out_dir/$brave_delta"
output_delta_eddsa_path = "$root_out_dir/$brave_delta.eddsa"

Expand All @@ -229,10 +246,7 @@ action("generate_eddsa_sig_for_delta") {

outputs = [ "$output_delta_eddsa_path" ]

deps = [
":build_delta_installer",
"//brave/vendor/sparkle:build_sparkle_framework",
]
deps = [ ":build_delta_installer" ]
}

group("finalize_app") {
Expand Down
36 changes: 20 additions & 16 deletions build/mac/download_hermetic_xcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import pkg_resources

import deps
from deps_config import DEPS_PACKAGES_URL
from deps_config import DEPS_PACKAGES_URL, MAC_TOOLCHAIN_ROOT


def LoadPList(path):
Expand All @@ -40,20 +40,17 @@ def LoadPList(path):
# the OS minimum through Xcode 12.4, still seems to work.
MAC_MINIMUM_OS_VERSION = [19, 4]

BASE_DIR = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', '..', '..', 'build'))
TOOLCHAIN_ROOT = os.path.join(BASE_DIR, 'mac_files')
TOOLCHAIN_BUILD_DIR = os.path.join(TOOLCHAIN_ROOT, 'Xcode.app')
TOOLCHAIN_BUILD_DIR = os.path.join(MAC_TOOLCHAIN_ROOT, 'Xcode.app')


def PlatformMeetsHermeticXcodeRequirements():
if sys.platform != 'darwin':
return False
needed = MAC_MINIMUM_OS_VERSION
major_version = [
int(v) for v in platform.release().split('.')[:len(needed)]
]
return major_version >= needed
if sys.platform == 'darwin':
needed = MAC_MINIMUM_OS_VERSION
major_version = [
int(v) for v in platform.release().split('.')[:len(needed)]
]
return major_version >= needed
return sys.platform.startswith('linux')


def GetHermeticXcodeVersion(binaries_root):
Expand All @@ -76,7 +73,7 @@ def InstallXcodeBinaries():
print("Goma server host is not configured for Brave")
return 0

binaries_root = os.path.join(TOOLCHAIN_ROOT, 'xcode_binaries')
binaries_root = os.path.join(MAC_TOOLCHAIN_ROOT, 'xcode_binaries')
if (XCODE_VERSION == GetHermeticXcodeVersion(binaries_root) and
not os.path.islink(binaries_root)):
print(f"Hermetic Xcode {XCODE_VERSION} already installed")
Expand All @@ -91,6 +88,13 @@ def InstallXcodeBinaries():
print("Exiting.")
return 1

if sys.platform == 'darwin':
AcceptXcodeLicense(binaries_root)

return 0


def AcceptXcodeLicense(binaries_root):
# Accept the license for this version of Xcode if it's newer than the
# currently accepted version.
hermetic_xcode_version = GetHermeticXcodeVersion(binaries_root)
Expand All @@ -112,7 +116,7 @@ def InstallXcodeBinaries():
should_overwrite_license = False

if not should_overwrite_license:
return 0
return

# Use puppet's sudoers script to accept the license if its available.
license_accept_script = '/usr/local/bin/xcode_accept_license.py'
Expand All @@ -123,7 +127,7 @@ def InstallXcodeBinaries():
hermetic_xcode_license_version
]
subprocess.check_call(args)
return 0
return

# Otherwise manually accept the license. This will prompt for sudo.
print('Accepting new Xcode license. Requires sudo.')
Expand All @@ -141,7 +145,7 @@ def InstallXcodeBinaries():
args = ['sudo', 'plutil', '-convert', 'xml1', current_license_path]
subprocess.check_call(args)

return 0
return


def main():
Expand Down
Loading

0 comments on commit 32ff5ab

Please sign in to comment.