Skip to content

Commit

Permalink
WinUWP store application support is out of date
Browse files Browse the repository at this point in the history
This is required to support building Microsoft's WinUWP store
application version of WebRTC.

vs_toolchain.py
- needed to perform environment variable expansion for "Program
Files(x86)" to correctly identify Visual Studio installation location

config/BUILD.gn
- remove delayimp.lib, kernel32.lib and ole32.lib from store
applications (instead requires dloadhelper.lib/WindowsApp.lib
must be used)

BUILDCONFIG.gn
- Do not use clang when compiling Windows UWP targets;
- Added declare_args for is_target_winuwp rather and stripped multi
defined variations of the host_os/current_os == "winrt_10", "winrt_81",
"winrt_81_phone" that heavily polluted the platform / target selections
(as the current targeting methodology is incorrect anyway). The
host_os/current_os is always be "win" and only the target should be
Windows UWP / store applications based on the target_os == "winuwp"
rather than all the flavors of UWP.
- Added filter for _winuwp source files (separate from just windows)
- Added default configs for desktop vs store applications to correctly set
the defines according to the desktop vs store targets

config/win/BUILD.gn
- The Windows UWP versioning assumes to be Windows 10 / store
app now although a updated GN allows for targeting older Windows UWP
versions/SDKs/device families. This allows the definitions for the
various application support versioning and application families required
for UWP to be set.
- The linker calls vsvarsall.bat to be executed via
toolchain/win/setup_toolchain.py in order to correctly identify the
correct linker library path information for Windows store SDK targets.
The hard coded and assumed library paths are fixed in all cases to be
discovered from the tooling for forward future platform support in all
cases.
- Added ARM linkage definitions for the Windows ARM CPU required for
properly targeting all three CPUs (x86, x64, arm) for universal store
binaries.
- Added the proper family C++/C defines required to target the various
Windows store application types currently offered for Windows UWP store
applications.

toolchain/win/BUILD.gn
- The name to support the storage of the environment variables now is
passed into the setup script to allow for easier extension of the
CPUs and target combinations (arm, x64, x86 in the desktop vs store
variations)
- "desktop" vs "store" is now specified the setup for the
correct toolchain targeting
- Sets true/false for is_target_winuwp is dependent on the toolchain
activated (so configurations will be set correctly when the toolchain is
specified for host tool targets required for build tools vs finalized
application targets)
- Cleaned up the Windows RT section to properly support Windows UWP
toolchains

toolchain/win/setup_toolchain.py
- the setup was missing the arm CPU for universal binaries required for
the UWP platform
- The calling of vcvarsall.bat was missing the "store" option for store
applications and all the CPU offered
- Added returning of linker paths by searching the library environments
for well-known library files expected in each of the 3 library paths
required "lib", "um" and "atlmfc"

R=phoglund@google.com

Bug: 812814
Change-Id: If1a6b1b1bc3ed940fc8e2ce726ac016e2491e61d
Reviewed-on: https://chromium-review.googlesource.com/923161
Commit-Queue: Patrik Höglund <phoglund@chromium.org>
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545751}
  • Loading branch information
robin-raymond authored and Commit Bot committed Mar 26, 2018
1 parent 6520f68 commit c568657
Show file tree
Hide file tree
Showing 7 changed files with 256 additions and 119 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,7 @@ Neverware Inc. <*@neverware.com>
NIKE, Inc. <*@nike.com>
NVIDIA Corporation <*@nvidia.com>
Opera Software ASA <*@opera.com>
Optical Tone Ltd <*@opticaltone.com>
Seznam.cz, a.s. <*@firma.seznam.cz>
Spotify AB <*@spotify.com>
Tableau Software <*@tableau.com>
Expand Down
17 changes: 14 additions & 3 deletions build/config/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,11 @@ config("default_libs") {
"advapi32.lib",
"comdlg32.lib",
"dbghelp.lib",
"delayimp.lib",
"dnsapi.lib",
"gdi32.lib",
"kernel32.lib",
"msimg32.lib",
"odbc32.lib",
"odbccp32.lib",
"ole32.lib",
"oleaut32.lib",
"psapi.lib",
"shell32.lib",
Expand All @@ -234,6 +231,20 @@ config("default_libs") {
# some extra libraries, please just add a libs = [ "foo.lib" ] to your
# target that needs it.
]
if (current_os == "winuwp") {
# These libraries are needed for Windows UWP (i.e. store apps).
libs += [
"dloadhelper.lib",
"WindowsApp.lib",
]
} else {
# These libraries are not compatible with Windows UWP (i.e. store apps.)
libs += [
"delayimp.lib",
"kernel32.lib",
"ole32.lib",
]
}
} else if (is_android) {
libs = [
"dl",
Expand Down
17 changes: 8 additions & 9 deletions build/config/BUILDCONFIG.gn
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,14 @@ if (target_os == "android") {
} else {
_default_toolchain = "//build/toolchain/win:$target_cpu"
}
} else if (target_os == "winuwp") {
# Only target WinUWP on for a Windows store application and only
# x86, x64 and arm are supported target CPUs.
assert(target_cpu == "x86" || target_cpu == "x64" || target_cpu == "arm" ||
target_cpu == "arm64")
_default_toolchain = "//build/toolchain/win:uwp_$target_cpu"
} else if (target_os == "aix") {
_default_toolchain = "//build/toolchain/aix:$target_cpu"
} else if (target_os == "winrt_81" || target_os == "winrt_81_phone" ||
target_os == "winrt_10") {
_default_toolchain = "//build/toolchain/win:winrt_$target_cpu"
} else {
assert(false, "Unsupported target_os: $target_os")
}
Expand Down Expand Up @@ -285,8 +288,7 @@ if (custom_toolchain != "") {
# aix or one of the BSDs. If you need to check these, just check the
# current_os value directly.

if (current_os == "win" || current_os == "winrt_81" ||
current_os == "winrt_81_phone" || current_os == "winrt_10") {
if (current_os == "win" || current_os == "winuwp") {
is_android = false
is_chromeos = false
is_fuchsia = false
Expand Down Expand Up @@ -536,6 +538,7 @@ default_compiler_configs = [
"//build/config/coverage:default_coverage",
"//build/config/sanitizers:default_sanitizer_flags",
]

if (is_win) {
default_compiler_configs += [
"//build/config/win:default_crt",
Expand All @@ -546,10 +549,6 @@ if (is_win) {
"//build/config/win:vs_code_analysis",
]
}
if (current_os == "winrt_81" || current_os == "winrt_81_phone" ||
current_os == "winrt_10") {
default_compiler_configs += [ "//build/config/win:target_winrt" ]
}

if (is_posix) {
if (current_os != "aix") {
Expand Down
131 changes: 103 additions & 28 deletions build/config/win/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ import("//build/config/clang/clang.gni")
import("//build/config/compiler/compiler.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//build/config/win/visual_studio_version.gni")
import("//build/toolchain/goma.gni")
import("//build/toolchain/toolchain.gni")

assert(is_win)

if (disable_goma) {
goma_disabled = "true"
} else {
goma_disabled = "false"
}

declare_args() {
# Set this to true to enable static analysis through Visual Studio's
# /analyze. This dramatically slows compiles and reports thousands of
Expand All @@ -24,6 +31,20 @@ declare_args() {

# Turn this on to have the compiler output extra timing information.
win_compiler_timing = false

# possible values for target_winuwp_version:
# "10" - Windows UWP 10
# "8.1" - Windows RT 8.1
# "8.0" - Windows RT 8.0
target_winuwp_version = "10"

# possible values:
# "app" - Windows Store Applications
# "phone" - Windows Phone Applications
# "system" - Windows Drivers and Tools
# "server" - Windows Server Applications
# "desktop" - Windows Desktop Applications
target_winuwp_family = "app"
}

# This is included by reference in the //build/config/compiler config that
Expand Down Expand Up @@ -239,6 +260,50 @@ config("runtime_library") {
# not match ours.
defines += [ "_LIBCPP_NO_AUTO_LINK" ]
}

if (current_os == "winuwp") {
# When targeting Windows Runtime, certain compiler/linker flags are
# necessary.
defines += [
"WINUWP",
"__WRL_NO_DEFAULT_LIB__",
]
if (target_winuwp_family == "app") {
defines += [ "WINAPI_FAMILY=WINAPI_FAMILY_PC_APP" ]
} else if (target_winuwp_family == "phone") {
defines += [ "WINAPI_FAMILY=WINAPI_FAMILY_PHONE_APP" ]
} else if (target_winuwp_family == "system") {
defines += [ "WINAPI_FAMILY=WINAPI_FAMILY_SYSTEM" ]
} else if (target_winuwp_family == "server") {
defines += [ "WINAPI_FAMILY=WINAPI_FAMILY_SERVER" ]
} else {
defines += [ "WINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP" ]
}
cflags_cc += [
"/ZW",
"/EHsc",
]

# This warning is given because the linker cannot tell the difference
# between consuming WinRT APIs versus authoring WinRT within static
# libraries as such this warning is always given by the linker. Since
# consuming WinRT APIs within a library is legitimate but authoring
# WinRT APis is not allowed, this warning is disabled to ignore the
# legitimate consumption of WinRT APIs within static library builds.
arflags = [ "/IGNORE:4264" ]

if (target_winuwp_version == "10") {
defines += [ "WIN10=_WIN32_WINNT_WIN10" ]
} else if (target_winuwp_version == "8.1") {
defines += [ "WIN8_1=_WIN32_WINNT_WINBLUE" ]
} else if (target_winuwp_version == "8.0") {
defines += [ "WIN8=_WIN32_WINNT_WIN8" ]
}
} else {
# When not targeting Windows Runtime, make sure the WINAPI family is set
# to desktop.
defines += [ "WINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP" ]
}
}

# Sets the default Windows build version. This is separated because some
Expand All @@ -253,24 +318,47 @@ config("winver") {

# Linker flags for Windows SDK setup, this is applied only to EXEs and DLLs.
config("sdk_link") {
assert(current_cpu == "x64" || current_cpu == "x86" || current_cpu == "arm" ||
current_cpu == "arm64",
"Only supports x64, x86, arm and arm64 CPUs")
if (current_cpu == "x64") {
ldflags = [ "/MACHINE:X64" ]
lib_dirs = [
"$windows_sdk_path\Lib\winv6.3\um\x64",
"$visual_studio_path\VC\lib\amd64",
"$visual_studio_path\VC\atlmfc\lib\amd64",
]
} else {
} else if (current_cpu == "x86") {
ldflags = [
"/MACHINE:X86",
"/SAFESEH", # Not compatible with x64 so use only for x86.
"/largeaddressaware",
]
lib_dirs = [
"$windows_sdk_path\Lib\winv6.3\um\x86",
"$visual_studio_path\VC\lib",
"$visual_studio_path\VC\atlmfc\lib",
]
} else if (current_cpu == "arm") {
ldflags = [ "/MACHINE:ARM" ]
} else if (current_cpu == "arm64") {
ldflags = [ "/MACHINE:ARM64" ]
}

vcvars_toolchain_data = exec_script("../../toolchain/win/setup_toolchain.py",
[
visual_studio_path,
windows_sdk_path,
visual_studio_runtime_dirs,
current_os,
current_cpu,
"none",
goma_disabled,
],
"scope")

vc_lib_path = vcvars_toolchain_data.vc_lib_path
if (defined(vcvars_toolchain_data.vc_lib_atlmfc_path)) {
vc_lib_atlmfc_path = vcvars_toolchain_data.vc_lib_atlmfc_path
}
vc_lib_um_path = vcvars_toolchain_data.vc_lib_um_path

lib_dirs = [
"$vc_lib_um_path",
"$vc_lib_path",
]
if (defined(vc_lib_atlmfc_path)) {
lib_dirs += [ "$vc_lib_atlmfc_path" ]
}
}

Expand Down Expand Up @@ -328,8 +416,10 @@ config("default_crt") {
# exceptions on.
configs = [ ":dynamic_crt" ]
} else {
if (current_os != "win") {
# WindowsRT: use the dynamic CRT.
if (current_os == "winuwp") {
# https://blogs.msdn.microsoft.com/vcblog/2014/06/10/the-great-c-runtime-crt-refactoring/
# contains a details explanation of what is happening with the Windows
# CRT in Visual Studio releases related to Windows store applications.
configs = [ ":dynamic_crt" ]
} else {
# Desktop Windows: static CRT.
Expand Down Expand Up @@ -458,21 +548,6 @@ config("nominmax") {
defines = [ "NOMINMAX" ]
}

# Target WinRT ----------------------------------------------------------------

# When targeting Windows Runtime, certain compiler/linker flags are necessary.

config("target_winrt") {
defines = [
"WINRT",
"WINAPI_FAMILY=WINAPI_FAMILY_PC_APP",
]
cflags_cc = [
"/ZW",
"/EHsc",
]
}

# Generating order files -------------------------------------------------------

config("default_cygprofile_instrumentation") {
Expand Down
Loading

0 comments on commit c568657

Please sign in to comment.