Commit f608c3ae authored by Mike Hommey's avatar Mike Hommey
Browse files

Bug 1817372 - Refactor checks for the MSVC abi that take the form of a...

Bug 1817372 - Refactor checks for the MSVC abi that take the form of a compiler check. r=firefox-build-system-reviewers,andi

We're soon going to introduce a new way to distinguish between the two
windows ABIs, so we factor out compiler checks that will need to be
adjusted to limit the amount of changes down the line.

Differential Revision: https://phabricator.services.mozilla.com/D170167
parent d4f69748
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -1509,6 +1509,23 @@ host_cxx_compiler = compiler(
    other_c_compiler=c_compiler,
)


@template
def windows_abi(host_or_target, c_compiler):
    @depends(host_or_target, c_compiler)
    def windows_abi(host_or_target, c_compiler):
        if host_or_target.os == "WINNT":
            if c_compiler.type == "clang-cl":
                return "msvc"
            return "mingw"

    return windows_abi


target_windows_abi = windows_abi(target, c_compiler)
host_windows_abi = windows_abi(host, host_c_compiler)


# Generic compiler-based conditions.
building_with_gcc = depends(c_compiler)(lambda info: info.type == "gcc")

+24 −18
Original line number Diff line number Diff line
@@ -31,15 +31,13 @@ def valid_windows_version(value):
option(env="WINDOWSSDKDIR", nargs=1, help="Directory containing the Windows SDK")


@depends("WINDOWSSDKDIR", "WINSYSROOT", c_compiler, host_c_compiler)
def windows_sdk_dir(value, winsysroot, compiler, host_compiler):
@depends("WINDOWSSDKDIR", "WINSYSROOT", target_windows_abi, host_windows_abi)
def windows_sdk_dir(value, winsysroot, target_windows_abi, host_windows_abi):
    if value:
        if winsysroot:
            die("WINDOWSSDKDIR and WINSYSROOT cannot be set together.")
        return value
    # Ideally, we'd actually check for host/target ABI being MSVC, but
    # that's waiting for bug 1617793.
    if compiler.type != "clang-cl" and host_compiler.type != "clang-cl":
    if target_windows_abi != "msvc" and host_windows_abi != "msvc":
        return ()

    if winsysroot:
@@ -86,17 +84,25 @@ def valid_windows_sdk_dir_result(value):


@depends(
    c_compiler, host_c_compiler, windows_sdk_dir, valid_windows_version, "WINDOWSSDKDIR"
    c_compiler,
    target_windows_abi,
    host_windows_abi,
    windows_sdk_dir,
    valid_windows_version,
    "WINDOWSSDKDIR",
)
@checking("for Windows SDK", valid_windows_sdk_dir_result)
@imports(_from="__builtin__", _import="Exception")
@imports(_from="textwrap", _import="dedent")
def valid_windows_sdk_dir(
    compiler, host_compiler, windows_sdk_dir, target_version, windows_sdk_dir_env
    compiler,
    target_windows_abi,
    host_windows_abi,
    windows_sdk_dir,
    target_version,
    windows_sdk_dir_env,
):
    # Ideally, we'd actually check for host/target ABI being MSVC, but
    # that's waiting for bug 1617793.
    if compiler.type != "clang-cl" and host_compiler.type != "clang-cl":
    if target_windows_abi != "msvc" and host_windows_abi != "msvc":
        return None
    if windows_sdk_dir_env:
        windows_sdk_dir_env = windows_sdk_dir_env[0]
@@ -171,14 +177,14 @@ def valid_ucrt_sdk_dir_result(value):
        return "%s in %s" % (value.version, quote(value.path))


@depends(windows_sdk_dir, "WINDOWSSDKDIR", c_compiler, host_c_compiler)
@depends(windows_sdk_dir, "WINDOWSSDKDIR", target_windows_abi, host_windows_abi)
@checking("for Universal CRT SDK", valid_ucrt_sdk_dir_result)
@imports("os")
@imports(_import="mozpack.path", _as="mozpath")
def valid_ucrt_sdk_dir(windows_sdk_dir, windows_sdk_dir_env, compiler, host_compiler):
    # Ideally, we'd actually check for host/target ABI being MSVC, but
    # that's waiting for bug 1617793.
    if compiler.type != "clang-cl" and host_compiler.type != "clang-cl":
def valid_ucrt_sdk_dir(
    windows_sdk_dir, windows_sdk_dir_env, target_windows_abi, host_windows_abi
):
    if target_windows_abi != "msvc" and host_windows_abi != "msvc":
        return None
    if windows_sdk_dir_env:
        windows_sdk_dir_env = windows_sdk_dir_env[0]
@@ -256,10 +262,10 @@ def valid_ucrt_sdk_dir(windows_sdk_dir, windows_sdk_dir_env, compiler, host_comp
    )


@depends(c_compiler, host_c_compiler, vc_toolchain_search_path)
@depends(target_windows_abi, host_windows_abi, vc_toolchain_search_path)
@imports("os")
def vc_path(c_compiler, host_c_compiler, vc_toolchain_search_path):
    if c_compiler.type != "clang-cl" and host_c_compiler.type != "clang-cl":
def vc_path(target_windows_abi, host_windows_abi, vc_toolchain_search_path):
    if target_windows_abi != "msvc" and host_windows_abi != "msvc":
        return

    # In clang-cl builds, we need the headers and libraries from an MSVC installation.
+6 −6
Original line number Diff line number Diff line
@@ -256,17 +256,17 @@ def so_version(value):
@template
def library_name_info_template(host_or_target):
    assert host_or_target in {host, target}
    compiler = {
        host: host_c_compiler,
        target: c_compiler,
    windows_abi = {
        host: host_windows_abi,
        target: target_windows_abi,
    }[host_or_target]

    @depends(host_or_target, compiler, so_version)
    def library_name_info_impl(host_or_target, compiler, so_version):
    @depends(host_or_target, windows_abi, so_version)
    def library_name_info_impl(host_or_target, windows_abi, so_version):
        if host_or_target.kernel == "WINNT":
            # There aren't artifacts for mingw builds, so it's OK that the
            # results are inaccurate in that case.
            if compiler and compiler.type != "clang-cl":
            if windows_abi and windows_abi != "msvc":
                return namespace(
                    dll=namespace(prefix="", suffix=".dll"),
                    lib=namespace(prefix="lib", suffix="a"),