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

Feature/mac arm64 #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
9 changes: 8 additions & 1 deletion esy/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ else
echo "llvm toolset-7.0 does not need to be manually activated"
fi

bin/gn gen $cur__target_dir/out/Static --script-executable="$PYTHON_BINARY" "--args=cc=\"$CC\" cxx=\"$CXX\" skia_use_system_libjpeg_turbo=true esy_skia_enable_svg=true is_debug=false extra_cflags=[\"-I${ESY_LIBJPEG_TURBO_PREFIX}/include\"] extra_ldflags=[\"-L${ESY_LIBJPEG_TURBO_PREFIX}/lib\", \"-ljpeg\" ]" || exit -1
current_arch=$(arch)

if [[ $OS == "darwin" ]]
then
bin/gn gen $cur__target_dir/out/Static --script-executable="$PYTHON_BINARY" "--args=cc=\"$CC\" cxx=\"$CXX\" target_cpu=\"$current_arch\" skia_use_system_libjpeg_turbo=true esy_skia_enable_svg=true is_debug=false extra_cflags=[\"-I${ESY_LIBJPEG_TURBO_PREFIX}/include\"] extra_ldflags=[\"-L${ESY_LIBJPEG_TURBO_PREFIX}/lib\", \"-ljpeg\" ]" || exit -1
else
bin/gn gen $cur__target_dir/out/Static --script-executable="$PYTHON_BINARY" "--args=cc=\"$CC\" cxx=\"$CXX\" skia_use_system_libjpeg_turbo=true esy_skia_enable_svg=true is_debug=false extra_cflags=[\"-I${ESY_LIBJPEG_TURBO_PREFIX}/include\"] extra_ldflags=[\"-L${ESY_LIBJPEG_TURBO_PREFIX}/lib\", \"-ljpeg\" ]" || exit -1
fi
ninja.exe -C $cur__target_dir/out/Static || exit -1
fi
60 changes: 57 additions & 3 deletions gn/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ declare_args() {
extra_ldflags = []

malloc = ""
xcode_sysroot = ""

enable_bitcode = false
if (is_tvos || is_watchos) {
enable_bitcode = true
}
}

if (is_ios) {
if (is_ios && xcode_sysroot == "") {
if (is_tvos) {
sdk = "appletv"
} else if (is_watchos) {
Expand All @@ -34,6 +35,17 @@ if (is_ios) {
sdk += "os"
}
ios_sysroot = exec_script("find_ios_sysroot.py", [ sdk ], "trim string")
xcode_sysroot =
exec_script("find_xcode_sysroot.py", [ sdk ], "trim string")
}

# If building for mac on a mac then lookup all the system includes so that goma and the clang
# shipped with chrome can find them. When the gn_to_bp.py tool is run, then the host_os != mac.
# In this case leave the xcode_sysroot empty, and the cc/c++ that come with XCode will be able to
# find needed include paths.
if (is_mac && host_os == "mac" && xcode_sysroot == "") {
xcode_sysroot =
exec_script("find_xcode_sysroot.py", [ "macosx" ], "trim string")
}

config("default") {
Expand Down Expand Up @@ -252,12 +264,46 @@ config("default") {
libs += [ "pthread" ]
}
if (is_mac) {
# If there was a xcode_sysroot set in args or calculated then use it, else don't set anything
# because the XCode cc/c++ already know all this stuff.
if (xcode_sysroot != "") {
asmflags += [
"-isysroot",
xcode_sysroot,
]
cflags += [
"-isysroot",
xcode_sysroot,
]
ldflags += [
"-isysroot",
xcode_sysroot,
]
}

# Disable linker warnings. They're usually just annoyances like,
# ld: warning: text-based stub file
# /System/Library/Frameworks/foo.framework/foo.tbd and library file
# /System/Library/Frameworks/foo.framework/foo are out of sync.
# Falling back to library file for linking.
ldflags += [ "-Wl,-w" ]

# As of 11/2020, gn is an x86 binary and defaults the host_cpu to x86_64.
# This allows you to build arm64 mac binaries by setting target_cpu = "arm64"
if (current_cpu == "arm64") {
asmflags += [
"-target",
"arm64-apple-macos11",
]
cflags += [
"-target",
"arm64-apple-macos11",
]
ldflags += [
"-target",
"arm64-apple-macos11",
]
}
}

if (sanitize != "") {
Expand Down Expand Up @@ -354,7 +400,6 @@ config("warnings") {
]
} else {
cflags += [
"-Werror",
"-Wall",
"-Wextra",
"-Winit-self",
Expand All @@ -364,16 +409,23 @@ config("warnings") {

"-Wno-deprecated-declarations",
"-Wno-maybe-uninitialized",
"-Wno-extra-semi-stmt",
]
cflags_cc += [
"-Wnon-virtual-dtor",
"-Wno-noexcept-type",

# GCC 8+ bundles a number of fundamentally different warnings under this same flag,
# ranging from false positive (only copying a prefix of SkRRect from serialized form)
# to possibly useful (memcpy() with non-trivial types). Annoyingly you can't really
# break them up any finer.
# TODO(mtklein): suppress / fix each site as appropriate?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who is @mtklein ? Does this code from upstream ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I bet that's me!

This comment and suppressed warning was in upstream Skia for a couple weeks, but removed in December 2019. You can see the timeline at https://bugs.chromium.org/p/skia/issues/detail?id=9674. I think we fixed whatever was bothering -Wclass-memaccess at the time.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this code from upstream, I just cherry pick minimal changes needed to compile in M1.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok Github showed you were author. So you Co-authored the first commit and fully the second one ?

Does xcrun esy works ? and does our upstream mono/skia (We are fork of fork) compile fine ?

Copy link
Author

@syaiful6 syaiful6 Aug 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Et7f3 yes, that also works and it produces an arm64 library, previously it produces an x86 library.

The first attempt to compile our fork is actually merge mono SKIA to our repository, but that is too big to manage, and it also can't compile, not sure why. So, I try to build Google SKIA, and it compiled successfully. Based on that, I figure out how they do it. The changes on the first commit are just generated by applying a patch I created with their changes in gn/BUILD.gn file, the work should be credited to the Google team. The second commit is just putting back our changes to that file.

"-Wno-class-memaccess",
]
}

if (is_clang) {
cflags += [
"-fcolor-diagnostics",
"-Weverything",
"-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' warnings.

Expand Down Expand Up @@ -438,6 +490,7 @@ config("warnings") {
"-Wno-unused-member-function",
"-Wno-unused-template",
"-Wno-zero-as-null-pointer-constant",
"-Wno-thread-safety-negative",
]
cflags_cc += [
"-Wno-abstract-vbase-init",
Expand All @@ -458,6 +511,7 @@ config("warnings") {
"-Wno-c++98-compat",
"-Wno-c++98-compat-pedantic",
"-Wno-undefined-func-template",
"-Wno-return-std-move-in-c++11",
]
cflags_objc += [
"-Wno-direct-ivar-access",
Expand Down
13 changes: 13 additions & 0 deletions gn/find_xcode_sysroot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env python
#
# Copyright 2016 Google Inc.
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import subprocess
import sys

(sdk,) = sys.argv[1:]

print subprocess.check_output(['xcrun', '--sdk', sdk, '--show-sdk-path'])