Commit 8927f28f authored by Thad House's avatar Thad House Committed by V8 LUCI CQ

[bazel] Support Windows builds in Bazel

Extend bazel build to support windows in addition to linux and mac.

Bug: v8:11234
Change-Id: I264f8dd8a33e221890a408d504a94ce2bc9cc19f
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3265064Reviewed-by: 's avatarVictor Gomes <victorgomes@chromium.org>
Commit-Queue: Victor Gomes <victorgomes@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77896}
parent b295d0b0
...@@ -322,6 +322,14 @@ v8_config( ...@@ -322,6 +322,14 @@ v8_config(
"V8_HAVE_TARGET_OS", "V8_HAVE_TARGET_OS",
"V8_TARGET_OS_MACOSX", "V8_TARGET_OS_MACOSX",
], ],
"@config//:is_windows": [
"V8_HAVE_TARGET_OS",
"V8_TARGET_OS_WIN",
"UNICODE",
"_UNICODE",
"_CRT_RAND_S",
"_WIN32_WINNT=0x0602",
],
}) + select({ }) + select({
":is_v8_enable_pointer_compression": [ ":is_v8_enable_pointer_compression": [
"V8_COMPRESS_POINTERS", "V8_COMPRESS_POINTERS",
...@@ -615,6 +623,11 @@ filegroup( ...@@ -615,6 +623,11 @@ filegroup(
"src/base/debug/stack_trace_posix.cc", "src/base/debug/stack_trace_posix.cc",
"src/base/platform/platform-macos.cc", "src/base/platform/platform-macos.cc",
], ],
"@config//:is_windows": [
"src/base/win32-headers.h",
"src/base/debug/stack_trace_win.cc",
"src/base/platform/platform-win32.cc",
],
}), }),
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )
...@@ -1196,6 +1209,7 @@ filegroup( ...@@ -1196,6 +1209,7 @@ filegroup(
"src/execution/isolate-utils-inl.h", "src/execution/isolate-utils-inl.h",
"src/snapshot/embedded/platform-embedded-file-writer-base.h", "src/snapshot/embedded/platform-embedded-file-writer-base.h",
"src/snapshot/embedded/embedded-file-writer.h", "src/snapshot/embedded/embedded-file-writer.h",
"src/execution/encoded-c-signature.h",
"src/execution/isolate.cc", "src/execution/isolate.cc",
"src/execution/isolate.h", "src/execution/isolate.h",
"src/execution/local-isolate-inl.h", "src/execution/local-isolate-inl.h",
...@@ -2163,7 +2177,7 @@ filegroup( ...@@ -2163,7 +2177,7 @@ filegroup(
], ],
}) + select({ }) + select({
# Only for x64 builds and for arm64 with x64 host simulator. # Only for x64 builds and for arm64 with x64 host simulator.
"@config//:is_x64": [ "@config//:is_posix_64bit": [
"src/trap-handler/handler-inside-posix.cc", "src/trap-handler/handler-inside-posix.cc",
"src/trap-handler/handler-outside-posix.cc", "src/trap-handler/handler-outside-posix.cc",
], ],
...@@ -2174,6 +2188,22 @@ filegroup( ...@@ -2174,6 +2188,22 @@ filegroup(
"src/trap-handler/handler-outside-simulator.cc", "src/trap-handler/handler-outside-simulator.cc",
], ],
"//conditions:default": [], "//conditions:default": [],
}) + select({
"@config//:is_windows": [
"src/trap-handler/handler-inside-win.cc",
"src/trap-handler/handler-outside-win.cc",
"src/trap-handler/handler-inside-win.h",
# Needed on windows to work around https://github.com/bazelbuild/bazel/issues/6337
"third_party/zlib/zlib.h",
"third_party/zlib/zconf.h",
],
"//conditions:default": [],
}) + select({
"@config//:is_windows_64bit": [
"src/diagnostics/unwinding-info-win64.cc",
"src/diagnostics/unwinding-info-win64.h",
],
"//conditions:default": [],
}) + select({ }) + select({
":is_v8_enable_webassembly": [ ":is_v8_enable_webassembly": [
"src/asmjs/asm-js.cc", "src/asmjs/asm-js.cc",
...@@ -2770,10 +2800,13 @@ filegroup( ...@@ -2770,10 +2800,13 @@ filegroup(
# Note these cannot be v8_target_is_* selects because these contain # Note these cannot be v8_target_is_* selects because these contain
# inline assembly that runs inside the executable. Since these are # inline assembly that runs inside the executable. Since these are
# linked directly into mksnapshot, they must use the actual target cpu. # linked directly into mksnapshot, they must use the actual target cpu.
"@config//:is_ia32": ["src/heap/base/asm/ia32/push_registers_asm.cc"], "@config//:is_inline_asm_ia32": ["src/heap/base/asm/ia32/push_registers_asm.cc"],
"@config//:is_x64": ["src/heap/base/asm/x64/push_registers_asm.cc"], "@config//:is_inline_asm_x64": ["src/heap/base/asm/x64/push_registers_asm.cc"],
"@config//:is_arm": ["src/heap/base/asm/arm/push_registers_asm.cc"], "@config//:is_inline_asm_arm": ["src/heap/base/asm/arm/push_registers_asm.cc"],
"@config//:is_arm64": ["src/heap/base/asm/arm64/push_registers_asm.cc"], "@config//:is_inline_asm_arm64": ["src/heap/base/asm/arm64/push_registers_asm.cc"],
"@config//:is_msvc_asm_ia32": ["src/heap/base/asm/ia32/push_registers_masm.S"],
"@config//:is_msvc_asm_x64": ["src/heap/base/asm/x64/push_registers_masm.S"],
"@config//:is_msvc_asm_arm64": ["src/heap/base/asm/arm64/push_registers_masm.S"],
}), }),
) )
...@@ -3038,6 +3071,7 @@ genrule( ...@@ -3038,6 +3071,7 @@ genrule(
"src/inspector/protocol/Schema.h", "src/inspector/protocol/Schema.h",
], ],
cmd = "bazel/generate-inspector-files.sh $(@D)", cmd = "bazel/generate-inspector-files.sh $(@D)",
cmd_bat = "bazel\\generate-inspector-files.cmd $(@D)",
local = 1, local = 1,
message = "Generating inspector files", message = "Generating inspector files",
) )
...@@ -3076,6 +3110,7 @@ genrule( ...@@ -3076,6 +3110,7 @@ genrule(
srcs = [], srcs = [],
outs = ["builtins-generated/bytecodes-builtins-list.h"], outs = ["builtins-generated/bytecodes-builtins-list.h"],
cmd = "$(location :bytecode_builtins_list_generator) $@", cmd = "$(location :bytecode_builtins_list_generator) $@",
cmd_bat = "$(location :bytecode_builtins_list_generator) $@",
tools = [":bytecode_builtins_list_generator"], tools = [":bytecode_builtins_list_generator"],
) )
...@@ -3084,6 +3119,7 @@ genrule( ...@@ -3084,6 +3119,7 @@ genrule(
srcs = [], srcs = [],
outs = ["src/regexp/special-case.cc"], outs = ["src/regexp/special-case.cc"],
cmd = "$(location :regexp_special_case_generator) $@", cmd = "$(location :regexp_special_case_generator) $@",
cmd_bat = "$(location :regexp_special_case_generator) $@",
tools = [":regexp_special_case_generator"], tools = [":regexp_special_case_generator"],
) )
...@@ -3149,7 +3185,10 @@ cc_library( ...@@ -3149,7 +3185,10 @@ cc_library(
srcs = [ srcs = [
":torque_base_files", ":torque_base_files",
], ],
copts = ["-fexceptions"], copts = select({
"@config//:is_posix": [ "-fexceptions" ],
"//conditions:default": [],
}),
features = ["-use_header_modules"], features = ["-use_header_modules"],
deps = [ deps = [
":torque_base_headers", ":torque_base_headers",
...@@ -3253,7 +3292,10 @@ v8_binary( ...@@ -3253,7 +3292,10 @@ v8_binary(
"src/torque/torque.cc", "src/torque/torque.cc",
":torque_base_files", ":torque_base_files",
], ],
copts = ["-fexceptions"], copts = select({
"@config//:is_posix": [ "-fexceptions" ],
"//conditions:default": [],
}),
features = ["-use_header_modules"], features = ["-use_header_modules"],
linkopts = select({ linkopts = select({
"@config//:is_android": ["-llog"], "@config//:is_android": ["-llog"],
...@@ -3270,7 +3312,7 @@ v8_binary( ...@@ -3270,7 +3312,7 @@ v8_binary(
"@config//:is_android": ["-llog"], "@config//:is_android": ["-llog"],
"//conditions:default": [], "//conditions:default": [],
}), }),
noicu_deps = [":noicu/v8_libshared"], noicu_deps = [":v8_libshared_noicu"],
) )
v8_binary( v8_binary(
......
...@@ -26,14 +26,29 @@ cc_library( ...@@ -26,14 +26,29 @@ cc_library(
"U_ENABLE_RESOURCE_TRACING=0", "U_ENABLE_RESOURCE_TRACING=0",
"UNISTR_FROM_STRING_EXPLICIT=", "UNISTR_FROM_STRING_EXPLICIT=",
"UNISTR_FROM_CHAR_EXPLICIT=", "UNISTR_FROM_CHAR_EXPLICIT=",
] + select({
"@platforms//os:windows": [
"U_STATIC_IMPLEMENTATION",
"UNICODE",
"_UNICODE",
], ],
copts = [ "//conditions:default": [],
}),
copts = select({
"@platforms//os:windows": [
"/wd4005", # Macro redefinition.
"/wd4068", # Unknown pragmas.
"/wd4267", # Conversion from size_t on 64-bits.
"/utf-8", # ICU source files are in UTF-8.
],
"//conditions:default": [
"-Wno-unused-function", "-Wno-unused-function",
"-Wno-parentheses", "-Wno-parentheses",
"-Wno-unused-function", "-Wno-unused-function",
"-Wno-unused-variable", "-Wno-unused-variable",
"-Wno-deprecated-declarations", "-Wno-deprecated-declarations",
], ],
}),
includes = [ includes = [
"source/common", "source/common",
"source/i18n", "source/i18n",
...@@ -49,9 +64,25 @@ cc_library( ...@@ -49,9 +64,25 @@ cc_library(
"source/i18n/**/*.h", "source/i18n/**/*.h",
"source/i18n/**/*.cpp" "source/i18n/**/*.cpp"
]), ]),
copts = select({
"@platforms//os:windows": [
"/wd4005", # Macro redefinition.
"/wd4068", # Unknown pragmas.
"/wd4267", # Conversion from size_t on 64-bits.
"/utf-8", # ICU source files are in UTF-8.
],
"//conditions:default": [],
}),
defines = [ defines = [
"U_I18N_IMPLEMENTATION", "U_I18N_IMPLEMENTATION",
] + select({
"@platforms//os:windows": [
"U_STATIC_IMPLEMENTATION",
"UNICODE",
"_UNICODE",
], ],
"//conditions:default": [],
}),
deps = [ ":icuuc" ], deps = [ ":icuuc" ],
alwayslink = 1, alwayslink = 1,
) )
...@@ -65,6 +96,25 @@ cc_library( ...@@ -65,6 +96,25 @@ cc_library(
srcs = [ srcs = [
"source/stubdata/stubdata.cpp", "source/stubdata/stubdata.cpp",
], ],
copts = select({
"@platforms//os:windows": [
"/wd4005", # Macro redefinition.
"/wd4068", # Unknown pragmas.
"/wd4267", # Conversion from size_t on 64-bits.
"/utf-8", # ICU source files are in UTF-8.
],
"//conditions:default": [],
}),
defines = [
"U_I18N_IMPLEMENTATION",
] + select({
"@platforms//os:windows": [
"U_STATIC_IMPLEMENTATION",
"UNICODE",
"_UNICODE",
],
"//conditions:default": [],
}),
include_prefix = "third_party/icu", include_prefix = "third_party/icu",
deps = [ deps = [
":icuuc", ":icuuc",
......
...@@ -45,8 +45,12 @@ cc_library( ...@@ -45,8 +45,12 @@ cc_library(
include_prefix = "third_party/zlib", include_prefix = "third_party/zlib",
defines = [ defines = [
"CHROMIUM_ZLIB_NO_CHROMECONF", "CHROMIUM_ZLIB_NO_CHROMECONF",
"HAVE_HIDDEN",
"CPU_NO_SIMD", "CPU_NO_SIMD",
] + select({
"@platforms//os:windows": [],
"//conditions:default": [
"HAVE_HIDDEN",
], ],
}),
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )
...@@ -99,6 +99,28 @@ config_setting( ...@@ -99,6 +99,28 @@ config_setting(
constraint_values = ["@platforms//os:macos"], constraint_values = ["@platforms//os:macos"],
) )
config_setting(
name = "is_windows",
constraint_values = ["@platforms//os:windows"],
)
selects.config_setting_group(
name = "is_64bit",
match_any = [
":v8_target_arm64",
":is_x64",
":is_arm64",
],
)
selects.config_setting_group(
name = "is_windows_64bit",
match_all = [
":is_64bit",
":is_windows",
],
)
selects.config_setting_group( selects.config_setting_group(
name = "is_posix", name = "is_posix",
match_any = [ match_any = [
...@@ -107,3 +129,46 @@ selects.config_setting_group( ...@@ -107,3 +129,46 @@ selects.config_setting_group(
":is_macos", ":is_macos",
], ],
) )
selects.config_setting_group(
name = "is_posix_64bit",
match_all = [
":is_posix",
":is_x64",
]
)
selects.config_setting_group(
name = "is_inline_asm_x64",
match_all = [":is_posix", ":is_x64"],
)
selects.config_setting_group(
name = "is_inline_asm_ia32",
match_all = [":is_posix", ":is_ia32"],
)
selects.config_setting_group(
name = "is_inline_asm_arm64",
match_all = [":is_posix", ":is_arm64"],
)
selects.config_setting_group(
name = "is_inline_asm_arm",
match_all = [":is_posix", ":is_arm"],
)
selects.config_setting_group(
name = "is_msvc_asm_x64",
match_all = [":is_windows", ":is_x64"],
)
selects.config_setting_group(
name = "is_msvc_asm_ia32",
match_all = [":is_windows", ":is_ia32"],
)
selects.config_setting_group(
name = "is_msvc_asm_arm64",
match_all = [":is_windows", ":is_arm64"],
)
...@@ -88,7 +88,17 @@ v8_config = rule( ...@@ -88,7 +88,17 @@ v8_config = rule(
def _default_args(): def _default_args():
return struct( return struct(
deps = [":define_flags"], deps = [":define_flags"],
copts = [ defines = select({
"@v8//bazel/config:is_windows": [
"UNICODE",
"_UNICODE",
"_CRT_RAND_S",
"_WIN32_WINNT=0x0602", # Override bazel default to Windows 8
],
"//conditions:default": [],
}),
copts = select({
"@v8//bazel/config:is_posix": [
"-fPIC", "-fPIC",
"-Werror", "-Werror",
"-Wextra", "-Wextra",
...@@ -101,12 +111,17 @@ def _default_args(): ...@@ -101,12 +111,17 @@ def _default_args():
"-std=c++17", "-std=c++17",
"-isystem .", "-isystem .",
], ],
"//conditions:default": [],
}),
includes = ["include"], includes = ["include"],
linkopts = [ linkopts = select({
"-pthread", "@v8//bazel/config:is_windows": [
] + select({ "Winmm.lib",
"@config//:is_macos": [], "DbgHelp.lib",
"//conditions:default": ["-Wl,--no-as-needed -ldl"], "Advapi32.lib",
],
"@v8//bazel/config:is_macos": ["-pthread"],
"//conditions:default": ["-Wl,--no-as-needed -ldl -pthread"],
}) + select({ }) + select({
":should_add_rdynamic": ["-rdynamic"], ":should_add_rdynamic": ["-rdynamic"],
"//conditions:default": [], "//conditions:default": [],
...@@ -184,7 +199,7 @@ def v8_library( ...@@ -184,7 +199,7 @@ def v8_library(
default = _default_args() default = _default_args()
if _should_emit_noicu_and_icu(noicu_srcs, noicu_deps, icu_srcs, icu_deps): if _should_emit_noicu_and_icu(noicu_srcs, noicu_deps, icu_srcs, icu_deps):
native.cc_library( native.cc_library(
name = "noicu/" + name, name = name + "_noicu",
srcs = srcs + noicu_srcs, srcs = srcs + noicu_srcs,
deps = deps + noicu_deps + default.deps, deps = deps + noicu_deps + default.deps,
includes = includes + default.includes, includes = includes + default.includes,
...@@ -193,8 +208,15 @@ def v8_library( ...@@ -193,8 +208,15 @@ def v8_library(
alwayslink = 1, alwayslink = 1,
**kwargs **kwargs
) )
# Alias target used because of cc_library bug in bazel on windows
# https://github.com/bazelbuild/bazel/issues/14237
# TODO(victorgomes): Remove alias once bug is fixed
native.alias(
name = "noicu/" + name,
actual = name + "_noicu",
)
native.cc_library( native.cc_library(
name = "icu/" + name, name = name + "_icu",
srcs = srcs + icu_srcs, srcs = srcs + icu_srcs,
deps = deps + icu_deps + default.deps, deps = deps + icu_deps + default.deps,
includes = includes + default.includes, includes = includes + default.includes,
...@@ -203,6 +225,13 @@ def v8_library( ...@@ -203,6 +225,13 @@ def v8_library(
alwayslink = 1, alwayslink = 1,
**kwargs **kwargs
) )
# Alias target used because of cc_library bug in bazel on windows
# https://github.com/bazelbuild/bazel/issues/14237
# TODO(victorgomes): Remove alias once bug is fixed
native.alias(
name = "icu/" + name,
actual = name + "_icu",
)
else: else:
native.cc_library( native.cc_library(
name = name, name = name,
......
REM Copyright 2021 the V8 project authors. All rights reserved.
REM Use of this source code is governed by a BSD-style license that can be
REM found in the LICENSE file.
set BAZEL_OUT=%1
REM Bazel nukes all env vars, and we need the following for gn to work
set DEPOT_TOOLS_WIN_TOOLCHAIN=0
set ProgramFiles(x86)=C:\Program Files (x86)
set windir=C:\Windows
REM Create a default GN output folder
cmd.exe /S /E:ON /V:ON /D /c gn gen out/inspector
REM Generate inspector files
cmd.exe /S /E:ON /V:ON /D /c autoninja -C out/inspector gen/src/inspector/protocol/Forward.h
REM Create directories in bazel output folder
MKDIR -p %BAZEL_OUT%\include\inspector
MKDIR -p %BAZEL_OUT%\src\inspector\protocol
REM Copy generated files to bazel output folder
COPY out\inspector\gen\include\inspector\* %BAZEL_OUT%\include\inspector\
COPY out\inspector\gen\src\inspector\protocol\* %BAZEL_OUT%\src\inspector\protocol\
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment