From 6f2ae838cdab65249efb8e96e8163ee325454b8b Mon Sep 17 00:00:00 2001 From: Fabian Hahn Date: Sun, 29 May 2022 17:35:18 +0100 Subject: [PATCH] added Windows target testing --- .build.yml | 1 + README.md | 10 ++++++++-- WORKSPACE | 4 +++- ci/test | 14 ++++++++++++-- test/c/BUILD | 24 +++++++++++++++++++++++- test/c/main_winver.c | 16 ++++++++++++++++ 6 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 test/c/main_winver.c diff --git a/.build.yml b/.build.yml index 6aeec50..c9cbfa0 100644 --- a/.build.yml +++ b/.build.yml @@ -5,6 +5,7 @@ packages: - qemu-user-static - binfmt-support - moreutils + - wine-binfmt sources: - https://git.sr.ht/~motiejus/bazel-zig-cc environment: diff --git a/README.md b/README.md index 4ae2016..31dd425 100644 --- a/README.md +++ b/README.md @@ -401,8 +401,9 @@ This repository is used on the following (host) platforms: - `windows_amd64`, a.k.a. `x64`. The tests are running (CId) on linux-amd64, and are assuming the kernel is -configured to run arm64 binaries. There are two reasonably convenient ways to -configure arm64 emulation: +configured to run `linux_arm64` and `windows_amd64` binaries. + +There are two reasonably convenient ways to configure `linux_arm64` emulation: 1. Install and configure [`binfmt_misc`][binfmt_misc]: ``` @@ -414,6 +415,11 @@ configure arm64 emulation: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes ``` +In order to install and configure `windows_amd64` emulation: +``` +apt install wine-binfmt +``` + ## Transient docker environment A standalone Docker environment to play with bazel-zig-cc: diff --git a/WORKSPACE b/WORKSPACE index eff4a8f..c1b3c0f 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -51,11 +51,13 @@ zig_toolchains() register_toolchains( # if no `--platform` is specified, these toolchains will be used for - # (linux,darwin)x(amd64,arm64) + # (linux,darwin,windows)x(amd64,arm64) "@zig_sdk//toolchain:linux_amd64_gnu.2.19", "@zig_sdk//toolchain:linux_arm64_gnu.2.28", "@zig_sdk//toolchain:darwin_amd64", "@zig_sdk//toolchain:darwin_arm64", + "@zig_sdk//toolchain:windows_amd64", + "@zig_sdk//toolchain:windows_arm64", # amd64 toolchains for libc-aware platforms: "@zig_sdk//libc_aware/toolchain:linux_amd64_gnu.2.19", diff --git a/ci/test b/ci/test index debdc0b..1ba6285 100755 --- a/ci/test +++ b/ci/test @@ -1,3 +1,13 @@ -#!/bin/sh +#!/bin/bash +set -euo pipefail -exec bazel test ... +bazel test ... + +# Windows tests +# Unfortunately wine-binfmt breaks within the bazel sandbox, so we disable it +# to run this test. +bazel test //test/c:winver_windows_amd64 \ + --spawn_strategy=standalone +# There is no no easy way to run windows_arm64 binaries on Linux, so we just +# cross compile one for testing. +bazel build //test/c:winver_windows_arm64 diff --git a/test/c/BUILD b/test/c/BUILD index 99e36c4..698c798 100644 --- a/test/c/BUILD +++ b/test/c/BUILD @@ -1,4 +1,4 @@ -load("@bazel-zig-cc//rules:platform.bzl", "platform_binary") +load("@bazel-zig-cc//rules:platform.bzl", "platform_binary", "platform_test") cc_binary( name = "which_libc", @@ -34,3 +34,25 @@ cc_binary( ("linux_arm64", "//platform:linux_arm64", "glibc_2.28"), ] ] + +cc_binary( + name = "winver", + srcs = ["main_winver.c"], + target_compatible_with = [ + "@platforms//os:windows", + ], +) + +platform_test( + name = "winver_windows_amd64", + src = "winver", + platform = "//platform:windows_amd64", + tags = ["manual"], +) + +platform_binary( + name = "winver_windows_arm64", + src = "winver", + platform = "//platform:windows_arm64", + tags = ["manual"], +) diff --git a/test/c/main_winver.c b/test/c/main_winver.c new file mode 100644 index 0000000..b5302af --- /dev/null +++ b/test/c/main_winver.c @@ -0,0 +1,16 @@ +#include +#include + +int main() { + DWORD version = GetVersion(); + DWORD majorVersion = (DWORD)(LOBYTE(LOWORD(version))); + DWORD minorVersion = (DWORD)(HIBYTE(LOWORD(version))); + + DWORD build = 0; + if (version < 0x80000000) { + build = (DWORD)(HIWORD(version)); + } + + printf("Running Windows version %d.%d (%d).\n", majorVersion, minorVersion, build); + return 0; +}