Initial tweaks to get MSVC working.
diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 0000000..09a8f71 --- /dev/null +++ b/WORKSPACE
@@ -0,0 +1,2 @@ +# Bazel extensions for pybind11 +workspace(name = "pybind11_bazel")
diff --git a/build_defs.bzl b/build_defs.bzl index 1e55548..cde1e93 100644 --- a/build_defs.bzl +++ b/build_defs.bzl
@@ -8,9 +8,12 @@ def register_extension_info(**kwargs): pass -PYBIND_COPTS = [ - "-fexceptions", -] +PYBIND_COPTS = select({ + "@pybind11//:msvc_compiler": [], + "//conditions:default": [ + "-fexceptions", + ], +}) PYBIND_FEATURES = [ "-use_header_modules", # Required for pybind11. @@ -38,9 +41,15 @@ native.cc_binary( name = name + ".so", - copts = copts + PYBIND_COPTS + ["-fvisibility=hidden"], + copts = copts + PYBIND_COPTS + select({ + "@pybind11//:msvc_compiler": [], + "//conditions:default": [ + "-fvisibility=hidden", + ], + }), features = features + PYBIND_FEATURES, linkopts = linkopts + select({ + "@pybind11//:msvc_compiler": [], "@pybind11//:osx": [], "//conditions:default": ["-Wl,-Bsymbolic"], }),
diff --git a/pybind11.BUILD b/pybind11.BUILD index 4d7d77a..15590aa 100644 --- a/pybind11.BUILD +++ b/pybind11.BUILD
@@ -7,13 +7,16 @@ exports_files(["LICENSE"]) -OPTIONS = [ - "-fexceptions", - # Useless warnings - "-Xclang-only=-Wno-undefined-inline", - "-Xclang-only=-Wno-pragma-once-outside-header", - "-Xgcc-only=-Wno-error", # no way to just disable the pragma-once warning in gcc -] +OPTIONS = select({ + ":msvc_compiler": [], + "//conditions:default": [ + "-fexceptions", + # Useless warnings + "-Xclang-only=-Wno-undefined-inline", + "-Xclang-only=-Wno-pragma-once-outside-header", + "-Xgcc-only=-Wno-error", # no way to just disable the pragma-once warning in gcc + ], +}) INCLUDES = [ "include/pybind11/*.h", @@ -48,6 +51,11 @@ ) config_setting( + name = "msvc_compiler", + flag_values = {"@bazel_tools//tools/cpp:compiler": "msvc-cl"}, +) + +config_setting( name = "osx", constraint_values = ["@platforms//os:osx"], )
diff --git a/python_configure.bzl b/python_configure.bzl index 2107022..7c8fa59 100644 --- a/python_configure.bzl +++ b/python_configure.bzl
@@ -161,6 +161,8 @@ python_bin = repository_ctx.os.environ.get(_PYTHON_BIN_PATH) if python_bin != None: + if _is_windows(repository_ctx): + python_bin = _norm_path(python_bin) return python_bin python_short_name = "python" + repository_ctx.attr.python_version @@ -179,6 +181,8 @@ """Gets the bash bin path.""" bash_bin = repository_ctx.os.environ.get(_BAZEL_SH) if bash_bin != None: + if _is_windows(repository_ctx): + bash_bin = _norm_path(bash_bin) return bash_bin else: bash_bin_path = repository_ctx.which("bash") @@ -196,6 +200,8 @@ """Gets the python lib path.""" python_lib = repository_ctx.os.environ.get(_PYTHON_LIB_PATH) if python_lib != None: + if _is_windows(repository_ctx): + python_lib = _norm_path(python_lib) return python_lib print_lib = ("<<END\n" + "from __future__ import print_function\n" + @@ -300,6 +306,8 @@ """ python_config = repository_ctx.os.environ.get(_PYTHON_CONFIG_BIN_PATH) if python_config != None: + if _is_windows(repository_ctx): + python_config = _norm_path(python_config) return python_config bin_dir = repository_ctx.path(python_bin).dirname