From 542eba595de18d078c67a1862e974b89effaf560 Mon Sep 17 00:00:00 2001 From: Andreas Herrmann Date: Mon, 22 Feb 2021 17:31:51 +0100 Subject: [PATCH] Define Github actions pipeline for Windows - Adds windows to the bindist pipeline os-matrix. - Specify bash as the shell for the pipeline actions. (Default on Windows would be powershell) - Extend start script to support Windows. - Add CI tag filters to disable unsupported tests on Windows. - A `sh_test`s name must have an extension matching that of `srcs`. ``` ERROR: D:/a/rules_haskell/rules_haskell/tests/BUILD.bazel:134:8: in sh_test rule //tests:test-binary-with-data: Source file is a Windows executable file, target name extension should match source file extension ``` - Use `rule_test_exe` instead of `rule_test` where appropriate. - Disable stack_snapshot lock files on Windows They were pinned on Linux and contain platform specific dependencies, e.g. `unix`. - Update protobuf to 3.15.1 This includes a fix for builds on Windows using mingw. See https://github.com/protocolbuffers/protobuf/pull/8286 - Skip c2hs tests on Windows - Disable tests requiring nm `nm` is not in default `PATH` in Windows. We could obtain it either via `$(NM)` make variable or directl from the `CcToolchainInfo`. - Skip solib test on Windows - Skip runfiles-tree test on Windows - Disable haddock tests on Windows The haddock wrapper needs to be converted to a `sh_binary`. - Skip cabal library test on Windows Bazel builds are not sandboxed on Windows. These tests fail because both Cabal files are visible in the same build actions. - Remove libz.dll.a in GHC bindist, similar to other .dll.a libs. - Disable haskell_import test on Windows - Skip test on Windows that needs rlocation These can be fixed later on by using rlocation instead of expecting files to be available under a hard-coded relative path. - Skip proto test on Windows --- .bazelrc | 3 + .github/workflows/workflow.yaml | 6 +- WORKSPACE | 8 +-- haskell/ghc_bindist.bzl | 13 ++++ haskell/haddock.bzl | 3 + haskell/repositories.bzl | 6 +- start | 1 + tests/BUILD.bazel | 59 +++++++++++++------ tests/binary-linkstatic-flag/BUILD.bazel | 4 ++ tests/c2hs/BUILD.bazel | 3 + tests/c2hs/repo/BUILD.bazel | 1 + .../failing-repros/isystem-issue/BUILD.bazel | 4 ++ tests/failing-repros/should_fail.bzl | 3 +- tests/haddock/BUILD.bazel | 12 +++- tests/haddock_protobuf/BUILD.bazel | 2 + tests/haskell_cabal_library/BUILD.bazel | 19 ++++++ tests/haskell_import/BUILD.bazel | 6 +- tests/haskell_proto_library/BUILD.bazel | 1 + tests/haskell_proto_simple/BUILD.bazel | 9 ++- tests/repl-targets/BUILD.bazel | 2 + tests/run-start-script.sh | 11 +++- tests/runfiles/BUILD.bazel | 17 ++++-- tests/solib_dir/BUILD.bazel | 3 + tests/version-macros/BUILD.bazel | 2 + 24 files changed, 161 insertions(+), 37 deletions(-) diff --git a/.bazelrc b/.bazelrc index 0d097d0b7..0c140fba1 100644 --- a/.bazelrc +++ b/.bazelrc @@ -41,6 +41,9 @@ build:macos-nixpkgs --test_tag_filters -dont_test_on_darwin build:macos-bindist --build_tag_filters -requires_nix,-dont_test_on_darwin,-dont_test_on_darwin_with_bindist,-requires_lz4,-requires_shellcheck,-requires_threaded_rts,-dont_test_with_bindist build:macos-bindist --test_tag_filters -requires_nix,-dont_test_on_darwin,-dont_test_on_darwin_with_bindist,-requires_lz4,-requires_shellcheck,-requires_threaded_rts,-dont_test_with_bindist +build:windows-bindist --build_tag_filters -requires_nix,-dont_test_on_windows,-requires_lz4,-requires_shellcheck,-requires_threaded_rts,-dont_test_with_bindist +build:windows-bindist --test_tag_filters -requires_nix,-dont_test_on_windows,-requires_lz4,-requires_shellcheck,-requires_threaded_rts,-dont_test_with_bindist + # CI Configuration # ---------------- common:ci --color=no diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml index 680ceb9e6..fc6f37602 100644 --- a/.github/workflows/workflow.yaml +++ b/.github/workflows/workflow.yaml @@ -59,7 +59,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu, macos] + os: [ubuntu, macos, windows] runs-on: ${{ matrix.os }}-latest steps: - uses: actions/checkout@v2 @@ -69,16 +69,19 @@ jobs: path: ~/repo-cache key: repo-cache-${{ runner.os }}-bindist-${{ env.cache-version }} - name: Install Bazel + shell: bash run: | BAZEL_DIR="$(.ci/fetch-bazel-bindist)" mv $BAZEL_DIR $HOME/bazel - name: Configure env: BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }} + shell: bash run: | case ${{ matrix.os }} in macos) BUILD_CONFIG=macos-bindist;; ubuntu) BUILD_CONFIG=linux-bindist;; + windows) BUILD_CONFIG=windows-bindist;; esac cat >.bazelrc.local <=0.6.0.0. On Windows we're stuck on 0.5.1.0 until we can update GHC. + "dont_test_on_windows", + ], deps = [ ":foo", ], @@ -25,6 +29,9 @@ haskell_proto_library( haskell_library( name = "hs-lib", srcs = ["Bar.hs"], + tags = [ + "dont_test_on_windows", + ], visibility = ["//visibility:public"], deps = [ ":foo_haskell", diff --git a/tests/repl-targets/BUILD.bazel b/tests/repl-targets/BUILD.bazel index 915f08406..09264e76a 100644 --- a/tests/repl-targets/BUILD.bazel +++ b/tests/repl-targets/BUILD.bazel @@ -25,6 +25,7 @@ c2hs_library( tags = [ # See https://github.com/tweag/rules_haskell/issues/1486 "dont_test_on_darwin_with_bindist", + "dont_test_on_windows", ], ) @@ -39,6 +40,7 @@ haskell_library( tags = [ # See https://github.com/tweag/rules_haskell/issues/1486 "dont_test_on_darwin_with_bindist", + "dont_test_on_windows", ], visibility = ["//visibility:public"], deps = [ diff --git a/tests/run-start-script.sh b/tests/run-start-script.sh index 2a4611268..f6053a2c2 100755 --- a/tests/run-start-script.sh +++ b/tests/run-start-script.sh @@ -25,8 +25,17 @@ cd $workdir # changes, then we need to adapt to those changes in the branch. # Which in turn means the start script should pull in those changes too. +case "$OSTYPE" in + cygwin|msys) + OSCONFIG=("--config=ci-windows") + ;; + *) + OSCONFIG=() + ;; +esac + NIX_PATH=nixpkgs="$pwd/nixpkgs/default.nix" \ bazel run \ - --config=ci \ + --config=ci "${OSCONFIG[@]}" \ --override_repository=rules_haskell="$pwd" \ //:example diff --git a/tests/runfiles/BUILD.bazel b/tests/runfiles/BUILD.bazel index 1ed7d5018..c6c44e42c 100644 --- a/tests/runfiles/BUILD.bazel +++ b/tests/runfiles/BUILD.bazel @@ -1,5 +1,6 @@ load("@rules_cc//cc:defs.bzl", "cc_binary") load("@rules_haskell//haskell:defs.bzl", "haskell_binary") +load("@os_info//:os_info.bzl", "is_windows") package(default_testonly = 1) @@ -22,8 +23,10 @@ cc_binary( deps = ["@bazel_tools//tools/cpp/runfiles"], ) +exe = ".exe" if is_windows else "" + sh_test( - name = "cc-foo", + name = "cc-foo{}".format(exe), srcs = ["cc-runner"], args = [ "foo", @@ -33,7 +36,7 @@ sh_test( ) sh_test( - name = "cc-bar", + name = "cc-bar{}".format(exe), srcs = ["cc-runner"], args = [ "bar", @@ -55,7 +58,7 @@ haskell_binary( ) sh_test( - name = "hs-foo", + name = "hs-foo{}".format(exe), srcs = ["hs-runner"], args = [ "foo", @@ -65,7 +68,7 @@ sh_test( ) sh_test( - name = "hs-bar", + name = "hs-bar{}".format(exe), srcs = ["hs-runner"], args = [ "bar", @@ -78,10 +81,14 @@ sh_test( # binary name. This test-case constructs a fresh runfiles tree next to the # `hs-runner` and tests that this runfiles tree is found. sh_test( - name = "runfiles-tree", + name = "runfiles-tree{}".format(exe), srcs = ["runfiles-tree.sh"], args = ["$(rootpath hs-runner)"], data = ["hs-runner"], + tags = [ + # TODO extend to use RUNFILES_MANIFEST_FILE on Windows. + "dont_test_on_windows", + ], deps = ["@bazel_tools//tools/bash/runfiles"], ) diff --git a/tests/solib_dir/BUILD.bazel b/tests/solib_dir/BUILD.bazel index e708e687e..9e052a49b 100644 --- a/tests/solib_dir/BUILD.bazel +++ b/tests/solib_dir/BUILD.bazel @@ -7,4 +7,7 @@ solib_test( "@rules_haskell//haskell/platforms:mingw32": True, "//conditions:default": False, }), + # Shell scripts as `DefaultInfo.executable` no longer work on Windows. + # Convert this test case to an analysis test. + tags = ["dont_test_on_windows"], ) diff --git a/tests/version-macros/BUILD.bazel b/tests/version-macros/BUILD.bazel index 25251bcfe..73d1fddd1 100644 --- a/tests/version-macros/BUILD.bazel +++ b/tests/version-macros/BUILD.bazel @@ -38,6 +38,7 @@ c2hs_library( tags = [ # See https://github.com/tweag/rules_haskell/issues/1486 "dont_test_on_darwin_with_bindist", + "dont_test_on_windows", ], version = "4.5.6.7", deps = [ @@ -56,6 +57,7 @@ haskell_test( tags = [ # See https://github.com/tweag/rules_haskell/issues/1486 "dont_test_on_darwin_with_bindist", + "dont_test_on_windows", ], version = "4.5.6.7", deps = [