Skip to content

Commit

Permalink
Added msvc toolchain
Browse files Browse the repository at this point in the history
  • Loading branch information
mbbill committed Sep 19, 2017
1 parent 071efc9 commit d718d52
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 47 deletions.
6 changes: 3 additions & 3 deletions BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# billming

group("main") {
deps = [
"//Source/JavaScriptCore:jsc",
]
deps = [
"//Source/JavaScriptCore:jsc",
]
}
14 changes: 14 additions & 0 deletions Source/POSIX_Win/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

group("posix_win") {
public_configs = [
":posix_win_headers",
]
deps = [
"//Source/POSIX_Win/pthreads:pthreads",
]
}
config("posix_win_headers") {
include_dirs = [
"include",
]
}
20 changes: 20 additions & 0 deletions Source/POSIX_Win/pthreads/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
shared_library("pthreads") {
sources = [
"src/pthread.c"
]
configs += [
":pthreads_config",
]
}

config("pthreads_config") {
defines = [
"PTW32_BUILD",
]
include_dirs = [
"src"
]
libs = [
"Ws2_32.lib",
]
}
5 changes: 5 additions & 0 deletions Source/WTF/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ static_library("wtf") {
"//Source/icu:icu",
"//Source/global_headers",
]
if (target_os == "win") {
deps += [
"//Source/POSIX_Win:posix_win",
]
}
}

config("wtf_config") {
Expand Down
5 changes: 5 additions & 0 deletions Source/icu/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@ config("icu_config") {
"U_I18N_IMPLEMENTATION",
"U_ATTRIBUTE_DEPRECATED=",
]
if (target_os == "win") {
defines += [
"_CRT_SECURE_NO_WARNINGS",
]
}
}

config("icu_include") {
Expand Down
65 changes: 44 additions & 21 deletions build/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,52 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

config("compiler_defaults") {
cflags = [
"-m32",
"-Oz",
"-s", "NO_EXIT_RUNTIME=1",
"-Wno-ignored-attributes", "-Wno-deprecated-register", "-Wno-nonportable-include-path",
#"-s ASSERTIONS=1 -g3",
#"-s WASM=1",
]
if (is_debug == false) {
defines = [
"NDEBUG",
if (target_os == "wasm") {
config("compiler_defaults") {
cflags = [
"-m32",
"-Oz",
"-s", "NO_EXIT_RUNTIME=1",
"-Wno-ignored-attributes", "-Wno-deprecated-register", "-Wno-nonportable-include-path",
#"-s ASSERTIONS=1 -g3",
#"-s WASM=1",
]
if (is_debug == false) {
defines = [
"NDEBUG",
]
}
cflags_cc = [
"-std=c++14",
]
}
config("executable_ldconfig") {
ldflags = [
"-Oz",
"-s", "NO_EXIT_RUNTIME=1",
"-s", "EXPORTED_FUNCTIONS=['_jsc_eval']",
]
}
cflags_cc = [
"-std=c++14",
]
}

config("executable_ldconfig") {
ldflags = [
"-Oz",
"-s", "NO_EXIT_RUNTIME=1",
"-s", "EXPORTED_FUNCTIONS=['_jsc_eval']",
]
if (target_os == "win") {
config("compiler_defaults") {
cflags = [
"/ZI",
"/W3",
"/Zc:wchar_t",
"/EHsc",
"/FS",
]
if (is_debug == false) {
defines = [
"NDEBUG",
]
}
cflags_cc = [
]
}
config("executable_ldconfig") {
}
}

12 changes: 7 additions & 5 deletions build/BUILDCONFIG.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ declare_args() {
}

if (target_os == "") {
target_os = host_os
}
if (target_cpu == "") {
target_cpu = host_cpu
target_os = "wasm"
}

# All binary targets will get this list of configs by default.
Expand All @@ -30,4 +27,9 @@ set_defaults("source_set") {
configs = _shared_binary_target_configs
}

set_default_toolchain("//build/toolchain:emcc")
if (target_os == "wasm") {
set_default_toolchain("//build/toolchain:emcc")
}
if (target_os == "win") {
set_default_toolchain("//build/toolchain:msvc")
}
110 changes: 92 additions & 18 deletions build/toolchain/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@

toolchain("emcc") {
if (host_os == "win") {
emcc_extension = ".bat"
emcc = "emcc.bat"
emcxx = "em++.bat"
emar = "emar.bat"
} else {
emcc_extension = ""
emcc = "emcc"
emcxx = "em++"
emar = "emar"
}

tool("cc") {
depfile = "{{output}}.d"
command = "emcc$emcc_extension -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
command = "$emcc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
depsformat = "gcc"
description = "CC {{output}}"
outputs = [
Expand All @@ -21,7 +25,7 @@ toolchain("emcc") {

tool("cxx") {
depfile = "{{output}}.d"
command = "em++$emcc_extension -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
command = "$emcxx-MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
depsformat = "gcc"
description = "CXX {{output}}"
outputs = [
Expand All @@ -31,7 +35,7 @@ toolchain("emcc") {

tool("alink") {
rspfile = "{{output}}.rsp"
command = "emar$emcc_extension rcs {{output}} @$rspfile"
command = "$emar rcs {{output}} @$rspfile"
description = "AR {{target_output_name}}{{output_extension}}"
rspfile_content = "{{inputs}}"
outputs = [
Expand All @@ -42,24 +46,14 @@ toolchain("emcc") {
}

tool("solink") {
soname = "{{target_output_name}}{{output_extension}}" # e.g. "libfoo.so".
soname = "{{target_output_name}}{{output_extension}}"
sofile = "{{output_dir}}/$soname"
rspfile = soname + ".rsp"

command = "em++$emcc_extension -shared {{ldflags}} -o $sofile -Wl,-soname=$soname @$rspfile"
command = "$emcxx -shared {{ldflags}} -o $sofile -Wl,-soname=$soname @$rspfile"
rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive {{libs}}"

description = "SOLINK $soname"

# Use this for {{output_extension}} expansions unless a target manually
# overrides it (in which case {{output_extension}} will be what the target
# specifies).
default_output_extension = ".so"

# Use this for {{output_dir}} expansions unless a target manually overrides
# it (in which case {{output_dir}} will be what the target specifies).
default_output_dir = "{{root_out_dir}}"

outputs = [
sofile,
]
Expand All @@ -71,7 +65,7 @@ toolchain("emcc") {
tool("link") {
outfile = "{{target_output_name}}{{output_extension}}"
rspfile = "$outfile.rsp"
command = "em++$emcc_extension {{ldflags}} -o $outfile -Wl,--start-group @$rspfile {{solibs}} -Wl,--end-group {{libs}}"
command = "$emcxx {{ldflags}} -o $outfile -Wl,--start-group @$rspfile {{solibs}} -Wl,--end-group {{libs}}"
description = "LINK $outfile"
default_output_dir = "{{root_out_dir}}"
rspfile_content = "{{inputs}}"
Expand All @@ -91,3 +85,83 @@ toolchain("emcc") {
description = "COPY {{source}} {{output}}"
}
}

toolchain("msvc") {
tool("cc") {
rspfile = "{{output}}.rsp"
pdbname = "{{target_out_dir}}/{{target_output_name}}_c.pdb"
command = "cl /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
depsformat = "msvc"
description = "CC {{output}}"
outputs = [
"{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
]
rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
}

tool("cxx") {
rspfile = "{{output}}.rsp"
pdbname = "{{target_out_dir}}/{{target_output_name}}_cc.pdb"
command = "cl /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
depsformat = "msvc"
description = "CXX {{output}}"
outputs = [
"{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
]
rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
}

tool("alink") {
rspfile = "{{output}}.rsp"
command = "lib /ltcg /nologo /out:{{output}} @$rspfile"
description = "LIB {{target_output_name}}{{output_extension}}"
rspfile_content = "{{inputs}}"
outputs = [
"{{target_out_dir}}/{{target_output_name}}{{output_extension}}",
]
default_output_extension = ".lib"
}

tool("solink") {
dllname = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
libname = "${dllname}.lib" # foo.dll.lib
rspfile = dllname + ".rsp"
command = "link /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:${dllname}.pdb @$rspfile"
rspfile_content = "{{libs}} {{solibs}} {{inputs}} {{ldflags}}"
description = "LINK(DLL) $dllname"
default_output_extension = ".dll"
outputs = [
dllname,
libname,
]
link_output = libname
depend_output = libname
runtime_link_output = dllname
# Since the above commands only updates the .lib file when it changes, ask
# Ninja to check if the timestamp actually changed to know if downstream
# dependencies should be recompiled.
restat = true
}

tool("link") {
rspfile = "{{output}}.rsp"
rspfile_content = "{{inputs}} {{libs}} {{solibs}} {{ldflags}}"
command = "link /nologo /OUT:{{output}} /PDB:{{output}}.pdb @$rspfile"
description = "LINK {{output}}"
default_output_dir = "{{root_out_dir}}"
default_output_extension = ".exe"
outputs = [
"{{output_dir}}/{{target_output_name}}{{output_extension}}",
]
}

tool("stamp") {
command = "touch {{output}}"
description = "STAMP {{output}}"
}

tool("copy") {
command = "cp -af {{source}} {{output}}"
description = "COPY {{source}} {{output}}"
}
}

0 comments on commit d718d52

Please sign in to comment.