Windows: Build cef_sandbox.lib with different GN args for official binary distributions (issue #2220)

This commit is contained in:
Marshall Greenblatt 2017-07-18 15:25:11 -04:00
parent 6c71485135
commit 1b2f997a30
7 changed files with 207 additions and 89 deletions

View File

@ -329,22 +329,13 @@ if(OS_WINDOWS)
# Configure use of the sandbox.
option(USE_SANDBOX "Enable or disable use of the sandbox." ON)
if(USE_SANDBOX AND NOT MSVC_VERSION EQUAL 1900)
# The cef_sandbox.lib static library is currently built with VS2015. It will
# not link successfully with other VS versions.
if(USE_SANDBOX AND NOT MSVC_VERSION EQUAL 1900 AND NOT MSVC_VERSION EQUAL 1910)
# The cef_sandbox.lib static library is currently built with VS2015, which
# is compatible with VS2015 and VS2017. It will not link successfully with
# other VS versions.
set(USE_SANDBOX OFF)
endif()
# Configure use of official build compiler settings.
# When using an official build the "Debug" build is actually a Release build
# with DCHECKs enabled. In order to link the sandbox the Debug build must
# be configured with some Release-related compiler settings.
option(USE_OFFICIAL_BUILD_SANDBOX "Enable or disable use of an official build sandbox." ON)
if(NOT USE_SANDBOX)
# Don't need official build settings when the sandbox is off.
set(USE_OFFICIAL_BUILD_SANDBOX OFF)
endif()
# Consumers who run into LNK4099 warnings can pass /Z7 instead (see issue #385).
set(CEF_DEBUG_INFO_FLAG "/Zi" CACHE STRING "Optional flag specifying specific /Z flag to use")
@ -366,27 +357,11 @@ if(OS_WINDOWS)
/wd4996 # Ignore "function or variable may be unsafe" warning
${CEF_DEBUG_INFO_FLAG}
)
if(USE_OFFICIAL_BUILD_SANDBOX)
# CMake adds /RTC1, /D"_DEBUG" and a few other values by default for Debug
# builds. We can't link the sandbox with those values so clear the CMake
# defaults here.
set(CMAKE_CXX_FLAGS_DEBUG "")
# These flags are required to successfully link and run applications using
# the sandbox library.
list(APPEND CEF_COMPILER_FLAGS_DEBUG
/MT # Multithreaded release runtime
/O2 # Maximize speed optimization
/Zc:inline # Remove unreferenced functions or data
/Oy- # Disable frame-pointer omission
)
else()
list(APPEND CEF_COMPILER_FLAGS_DEBUG
/MTd # Multithreaded debug runtime
/RTC1 # Disable optimizations
/Od # Enable basic run-time checks
)
endif()
list(APPEND CEF_COMPILER_FLAGS_DEBUG
/MTd # Multithreaded debug runtime
/RTC1 # Disable optimizations
/Od # Enable basic run-time checks
)
list(APPEND CEF_COMPILER_FLAGS_RELEASE
/MT # Multithreaded release runtime
/O2 # Optimize for maximum speed
@ -408,12 +383,6 @@ if(OS_WINDOWS)
WIN32_LEAN_AND_MEAN # Exclude less common API declarations
_HAS_EXCEPTIONS=0 # Disable exceptions
)
if(USE_OFFICIAL_BUILD_SANDBOX)
list(APPEND CEF_COMPILER_DEFINES_DEBUG
NDEBUG _NDEBUG # Not a debug build
DCHECK_ALWAYS_ON=1 # DCHECKs are enabled
)
endif()
list(APPEND CEF_COMPILER_DEFINES_RELEASE
NDEBUG _NDEBUG # Not a debug build
)
@ -481,18 +450,25 @@ if(OS_WINDOWS)
# Configure use of ATL.
option(USE_ATL "Enable or disable use of ATL." ON)
if(USE_ATL)
# Locate the VC directory. The cl.exe path returned by CMAKE_CXX_COMPILER
# may be at different directory depths depending on the toolchain version
# (e.g. "VC/bin/cl.exe", "VC/bin/amd64_x86/cl.exe", etc).
# Locate the atlmfc directory if it exists. It may be at any depth inside
# the VC directory. The cl.exe path returned by CMAKE_CXX_COMPILER may also
# be at different depths depending on the toolchain version
# (e.g. "VC/bin/cl.exe", "VC/bin/amd64_x86/cl.exe",
# "VC/Tools/MSVC/14.10.25017/bin/HostX86/x86/cl.exe", etc).
set(HAS_ATLMFC 0)
get_filename_component(VC_DIR ${CMAKE_CXX_COMPILER} DIRECTORY)
get_filename_component(VC_DIR_NAME ${VC_DIR} NAME)
while(NOT ${VC_DIR_NAME} STREQUAL "VC")
get_filename_component(VC_DIR ${VC_DIR} DIRECTORY)
if(IS_DIRECTORY "${VC_DIR}/atlmfc")
set(HAS_ATLMFC 1)
break()
endif()
get_filename_component(VC_DIR_NAME ${VC_DIR} NAME)
endwhile()
# Determine if the Visual Studio install supports ATL.
if(NOT IS_DIRECTORY "${VC_DIR}/atlmfc")
if(NOT HAS_ATLMFC)
message(WARNING "ATL is not supported by your VC installation.")
set(USE_ATL OFF)
endif()

View File

@ -312,4 +312,9 @@ patches = [
'name': 'libangle_735986',
'path': 'third_party/angle/',
},
{
# Windows: Disable allocator for cef_sandbox builds.
# https://bitbucket.org/chromiumembedded/cef/issues/2220
'name': 'sandbox_2220',
},
]

View File

@ -0,0 +1,14 @@
diff --git base/allocator/BUILD.gn base/allocator/BUILD.gn
index 6ebbc11..b667064 100644
--- base/allocator/BUILD.gn
+++ base/allocator/BUILD.gn
@@ -15,8 +15,7 @@ declare_args() {
# The Windows-only allocator shim is only enabled for Release static builds, and
# is mutually exclusive with the generalized shim.
-win_use_allocator_shim = is_win && !is_component_build && !is_debug &&
- !use_allocator_shim && !is_asan
+win_use_allocator_shim = false
# This "allocator" meta-target will forward to the default allocator according
# to the build settings.

View File

@ -510,6 +510,18 @@ parser.add_option(
dest='clientdistribonly',
default=False,
help='Create a client CEF binary distribution only.')
parser.add_option(
'--sandbox-distrib',
action='store_true',
dest='sandboxdistrib',
default=False,
help='Create a cef_sandbox static library distribution.')
parser.add_option(
'--sandbox-distrib-only',
action='store_true',
dest='sandboxdistribonly',
default=False,
help='Create a cef_sandbox static library distribution only.')
parser.add_option(
'--no-distrib-docs',
action='store_true',
@ -557,7 +569,7 @@ if (options.nochromiumupdate and options.forceupdate) or \
if (options.noreleasebuild and \
(options.minimaldistrib or options.minimaldistribonly or \
options.clientdistrib or options.clientdistribonly)) or \
(options.minimaldistribonly and options.clientdistribonly):
(options.minimaldistribonly + options.clientdistribonly + options.sandboxdistribonly > 1):
print 'Invalid combination of options.'
parser.print_help(sys.stderr)
sys.exit()
@ -600,13 +612,20 @@ if options.clientdistrib or options.clientdistribonly:
parser.print_help(sys.stderr)
sys.exit()
if platform != 'windows' and (options.sandboxdistrib or
options.sandboxdistribonly):
print 'The sandbox distribution is only supported on Windows.'
sys.exit()
# CEF branch.
if options.branch != 'trunk' and not options.branch.isdigit():
print 'Invalid branch value: %s' % (options.branch)
sys.exit()
cef_branch = options.branch
if cef_branch != 'trunk' and int(cef_branch) <= 1453:
print 'The requested branch is too old to build using this tool'
print 'The requested branch is too old to build using this tool.'
sys.exit()
# True if the requested branch is 2272 or newer.
@ -1054,30 +1073,51 @@ if not options.nobuild and (chromium_checkout_changed or \
if platform == 'windows' and options.x64build:
build_dir_suffix = '_x64'
# Make a CEF Debug build.
if not options.nodebugbuild:
build_path = os.path.join('out', 'Debug' + build_dir_suffix)
if use_gn:
args_path = os.path.join(chromium_src_dir, build_path, 'args.gn')
if os.path.exists(args_path):
msg(args_path + ' contents:\n' + read_file(args_path))
msg(args_path + ' contents:\n' + read_file(args_path))
# Make a CEF Debug build.
run(command + build_path + target, chromium_src_dir, depot_tools_dir,
os.path.join(download_dir, 'build-%s-debug.log' % (cef_branch)) \
if options.buildlogfile else None)
if use_gn and platform == 'windows':
# Make the separate cef_sandbox.lib build when GN is_official_build=true.
build_path = os.path.join('out', 'Debug' + build_dir_suffix + '_sandbox')
if os.path.exists(os.path.join(chromium_src_dir, build_path)):
args_path = os.path.join(chromium_src_dir, build_path, 'args.gn')
msg(args_path + ' contents:\n' + read_file(args_path))
run(command + build_path + ' cef_sandbox', chromium_src_dir, depot_tools_dir,
os.path.join(download_dir, 'build-%s-debug-sandbox.log' % (cef_branch)) \
if options.buildlogfile else None)
# Make a CEF Release build.
if not options.noreleasebuild:
build_path = os.path.join('out', 'Release' + build_dir_suffix)
if use_gn:
args_path = os.path.join(chromium_src_dir, build_path, 'args.gn')
if os.path.exists(args_path):
msg(args_path + ' contents:\n' + read_file(args_path))
msg(args_path + ' contents:\n' + read_file(args_path))
# Make a CEF Release build.
run(command + build_path + target, chromium_src_dir, depot_tools_dir,
os.path.join(download_dir, 'build-%s-release.log' % (cef_branch)) \
if options.buildlogfile else None)
if use_gn and platform == 'windows':
# Make the separate cef_sandbox.lib build when GN is_official_build=true.
build_path = os.path.join('out',
'Release' + build_dir_suffix + '_sandbox')
if os.path.exists(os.path.join(chromium_src_dir, build_path)):
args_path = os.path.join(chromium_src_dir, build_path, 'args.gn')
msg(args_path + ' contents:\n' + read_file(args_path))
run(command + build_path + ' cef_sandbox', chromium_src_dir, depot_tools_dir,
os.path.join(download_dir, 'build-%s-release-sandbox.log' % (cef_branch)) \
if options.buildlogfile else None)
elif not options.nobuild:
msg('Not building. The source hashes have not changed and ' +
'the output folder "%s" already exists' % (out_src_dir))
@ -1099,12 +1139,16 @@ if not options.nodistrib and (chromium_checkout_changed or \
distrib_types.append('minimal')
elif options.clientdistribonly:
distrib_types.append('client')
elif options.sandboxdistribonly:
distrib_types.append('sandbox')
else:
distrib_types.append('standard')
if options.minimaldistrib:
distrib_types.append('minimal')
if options.clientdistrib:
distrib_types.append('client')
if options.sandboxdistrib:
distrib_types.append('sandbox')
cef_tools_dir = os.path.join(cef_src_dir, 'tools')
@ -1124,6 +1168,8 @@ if not options.nodistrib and (chromium_checkout_changed or \
path = path + ' --minimal'
elif type == 'client':
path = path + ' --client'
elif type == 'sandbox':
path = path + ' --sandbox'
if first_type:
if options.nodistribdocs:

View File

@ -0,0 +1,14 @@
CONTENTS
--------
Debug Contains the Debug build of cef_sandbox.lib.
Release Contains the Release build of cef_sandbox.lib.
USAGE
-----
Please visit the CEF Website for usage information.
https://bitbucket.org/chromiumembedded/cef/

View File

@ -419,6 +419,28 @@ def GetConfigArgs(args, is_debug, cpu):
return result
def WinGetConfigArgsSandbox(args, is_debug, cpu):
"""
Return merged GN args for the Windows cef_sandbox.lib configuration and
validate.
"""
add_args = {
# Avoid libucrt.lib linker errors.
'use_allocator_shim': False,
# Avoid /LTCG linker warnings and generate smaller lib files.
'is_official_build': False
}
result = MergeDicts(args, add_args, {
'is_debug': is_debug,
'target_cpu': cpu,
})
ValidateArgs(result)
return result
def LinuxSysrootExists(cpu):
"""
Returns true if the sysroot for the specified |cpu| architecture exists.
@ -481,6 +503,14 @@ def GetAllPlatformConfigs(build_args):
result['Debug_GN_' + cpu] = GetConfigArgs(args, True, cpu)
result['Release_GN_' + cpu] = GetConfigArgs(args, False, cpu)
if platform == 'windows' and GetArgValue(args, 'is_official_build'):
# Build cef_sandbox.lib with a different configuration.
if create_debug:
result['Debug_GN_' + cpu + '_sandbox'] = WinGetConfigArgsSandbox(
args, True, cpu)
result['Release_GN_' + cpu + '_sandbox'] = WinGetConfigArgsSandbox(
args, False, cpu)
return result

View File

@ -112,7 +112,10 @@ def create_readme():
footer_data = get_readme_component('footer')
# format the file
data = header_data + '\n\n' + mode_data + '\n\n' + redistrib_data + '\n\n' + footer_data
data = header_data + '\n\n' + mode_data
if mode != 'sandbox':
data += '\n\n' + redistrib_data
data += '\n\n' + footer_data
data = data.replace('$CEF_URL$', cef_url)
data = data.replace('$CEF_REV$', cef_rev)
data = data.replace('$CEF_VER$', cef_ver)
@ -149,6 +152,10 @@ def create_readme():
distrib_desc = 'This distribution contains a release build of the ' + client_app + ' sample application\n' \
'for the ' + platform_str + ' platform. Please see the LICENSING section of this document for\n' \
'licensing terms and conditions.'
elif mode == 'sandbox':
distrib_type = 'Sandbox'
distrib_desc = 'This distribution contains only the cef_sandbox static library. Please see\n' \
'the LICENSING section of this document for licensing terms and conditions.'
data = data.replace('$DISTRIB_TYPE$', distrib_type)
data = data.replace('$DISTRIB_DESC$', distrib_desc)
@ -343,7 +350,7 @@ parser.add_option(
action='store_true',
dest='armbuild',
default=False,
help='create an ARM binary distribution')
help='create an ARM binary distribution (Linux only)')
parser.add_option(
'--minimal',
action='store_true',
@ -356,6 +363,12 @@ parser.add_option(
dest='client',
default=False,
help='include only the sample application')
parser.add_option(
'--sandbox',
action='store_true',
dest='sandbox',
default=False,
help='include only the cef_sandbox static library (Windows only)')
parser.add_option(
'-q',
'--quiet',
@ -393,6 +406,10 @@ if options.armbuild and platform != 'linux':
print '--arm-build is only supported on Linux.'
sys.exit()
if options.sandbox and platform != 'windows':
print '--sandbox is only supported on Windows.'
sys.exit()
if not options.ninjabuild:
print 'Ninja build is required on all platforms'
sys.exit()
@ -456,6 +473,9 @@ if options.minimal:
elif options.client:
mode = 'client'
output_dir_name = output_dir_name + '_client'
elif options.sandbox:
mode = 'sandbox'
output_dir_name = output_dir_name + '_sandbox'
else:
mode = 'standard'
@ -645,15 +665,31 @@ if platform == 'windows':
]
libcef_dll_file = 'libcef.dll.lib'
cef_sandbox_lib = 'obj\\cef\\cef_sandbox.lib'
sandbox_libs = [
'obj\\base\\allocator\\unified_allocator_shim\\*.obj',
'obj\\base\\base.lib',
'obj\\base\\base_static.lib',
'obj\\base\\third_party\\dynamic_annotations\\dynamic_annotations.lib',
'obj\\cef\\cef_sandbox.lib',
cef_sandbox_lib,
'obj\\sandbox\\win\\sandbox.lib',
]
# Generate the cef_sandbox.lib merged library. A separate *_sandbox build
# should exist when GN is_official_build=true.
if mode in ('standard', 'minimal', 'sandbox'):
dirs = {
'Debug': (build_dir_debug + '_sandbox', build_dir_debug),
'Release': (build_dir_release + '_sandbox', build_dir_release)
}
for dir_name in dirs.keys():
for src_dir in dirs[dir_name]:
if path_exists(os.path.join(src_dir, cef_sandbox_lib)):
dst_dir = os.path.join(output_dir, dir_name)
make_dir(dst_dir, options.quiet)
combine_libs(src_dir, sandbox_libs,
os.path.join(dst_dir, 'cef_sandbox.lib'))
break
valid_build_dir = None
if mode == 'standard':
@ -672,8 +708,6 @@ if platform == 'windows':
os.path.join(dst_dir, os.path.basename(binary)), options.quiet)
copy_file(os.path.join(build_dir, libcef_dll_file), os.path.join(dst_dir, 'libcef.lib'), \
options.quiet)
combine_libs(build_dir, sandbox_libs,
os.path.join(dst_dir, 'cef_sandbox.lib'))
if not options.nosymbols:
# create the symbol output directory
@ -686,39 +720,38 @@ if platform == 'windows':
else:
sys.stderr.write("No Debug build files.\n")
# transfer Release files
build_dir = build_dir_release
if not options.allowpartial or path_exists(
os.path.join(build_dir, 'libcef.dll')):
valid_build_dir = build_dir
dst_dir = os.path.join(output_dir, 'Release')
make_dir(dst_dir, options.quiet)
copy_files(
os.path.join(script_dir, 'distrib/win/*.dll'), dst_dir, options.quiet)
for binary in binaries:
copy_file(
os.path.join(build_dir, binary),
os.path.join(dst_dir, os.path.basename(binary)), options.quiet)
if mode != 'sandbox':
# transfer Release files
build_dir = build_dir_release
if not options.allowpartial or path_exists(
os.path.join(build_dir, 'libcef.dll')):
valid_build_dir = build_dir
dst_dir = os.path.join(output_dir, 'Release')
make_dir(dst_dir, options.quiet)
copy_files(
os.path.join(script_dir, 'distrib/win/*.dll'), dst_dir, options.quiet)
for binary in binaries:
copy_file(
os.path.join(build_dir, binary),
os.path.join(dst_dir, os.path.basename(binary)), options.quiet)
if mode != 'client':
copy_file(os.path.join(build_dir, libcef_dll_file), os.path.join(dst_dir, 'libcef.lib'), \
options.quiet)
combine_libs(build_dir, sandbox_libs,
os.path.join(dst_dir, 'cef_sandbox.lib'))
if mode != 'client':
copy_file(os.path.join(build_dir, libcef_dll_file), os.path.join(dst_dir, 'libcef.lib'), \
options.quiet)
else:
copy_file(
os.path.join(build_dir, 'cefclient.exe'), dst_dir, options.quiet)
if not options.nosymbols:
# create the symbol output directory
symbol_output_dir = create_output_dir(
output_dir_name + '_release_symbols', options.outputdir)
# transfer contents
copy_file(
os.path.join(build_dir, 'libcef.dll.pdb'), symbol_output_dir,
options.quiet)
else:
copy_file(
os.path.join(build_dir, 'cefclient.exe'), dst_dir, options.quiet)
if not options.nosymbols:
# create the symbol output directory
symbol_output_dir = create_output_dir(
output_dir_name + '_release_symbols', options.outputdir)
# transfer contents
copy_file(
os.path.join(build_dir, 'libcef.dll.pdb'), symbol_output_dir,
options.quiet)
else:
sys.stderr.write("No Release build files.\n")
sys.stderr.write("No Release build files.\n")
if not valid_build_dir is None:
# transfer resource files