Skip to content

Commit

Permalink
Define Github actions pipeline for Windows
Browse files Browse the repository at this point in the history
- 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 protocolbuffers/protobuf#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
  • Loading branch information
aherrmann committed Feb 23, 2021
1 parent d7e341b commit 542eba5
Show file tree
Hide file tree
Showing 24 changed files with 161 additions and 37 deletions.
3 changes: 3 additions & 0 deletions .bazelrc
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/workflow.yaml
Expand Up @@ -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
Expand All @@ -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 <<EOF
common --config=ci
Expand All @@ -90,6 +93,7 @@ jobs:
password ${{ secrets.GITHUB_TOKEN }}
EOF
- name: Build & test
shell: bash
run: |
export PATH=$HOME/bazel:$PATH
[[ ${{ matrix.os }} == macos ]] && export BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
Expand Down
8 changes: 4 additions & 4 deletions WORKSPACE
Expand Up @@ -90,7 +90,7 @@ stack_snapshot(
],
setup_deps = {"polysemy": ["cabal-doctest"]},
snapshot = test_stack_snapshot,
stack_snapshot_json = "//:stackage_snapshot.json",
stack_snapshot_json = "//:stackage_snapshot.json" if not is_windows else None,
tools = [
# This is not required, as `stack_snapshot` would build alex
# automatically, however it is used as a test for user provided
Expand All @@ -106,14 +106,14 @@ stack_snapshot(
extra_deps = {"zlib": ["//tests:zlib"]},
packages = ["zlib"],
snapshot = test_stack_snapshot,
stack_snapshot_json = "//:stackage-zlib-snapshot.json",
stack_snapshot_json = "//:stackage-zlib-snapshot.json" if not is_windows else None,
)

stack_snapshot(
name = "stackage-pinning-test",
local_snapshot = "//:stackage-pinning-test.yaml",
packages = ["hspec"],
stack_snapshot_json = "//:stackage-pinning-test_snapshot.json",
stack_snapshot_json = "//:stackage-pinning-test_snapshot.json" if not is_windows else None,
)

stack_snapshot(
Expand All @@ -126,7 +126,7 @@ stack_snapshot(
haddock = False,
local_snapshot = "//:ghcide-stack-snapshot.yaml",
packages = ["ghcide"],
stack_snapshot_json = "//:ghcide-snapshot.json",
stack_snapshot_json = "//:ghcide-snapshot.json" if not is_windows else None,
)

load(
Expand Down
13 changes: 13 additions & 0 deletions haskell/ghc_bindist.bzl
Expand Up @@ -311,6 +311,19 @@ def _ghc_bindist_impl(ctx):
execute_or_fail_loudly(ctx, ["rm", "mingw/x86_64-w64-mingw32/lib/libpthread.dll.a"])
execute_or_fail_loudly(ctx, ["rm", "mingw/x86_64-w64-mingw32/lib/libwinpthread.dll.a"])

# Similarly causes loading issues with template Haskell. E.g.
#
# ghc.exe: panic! (the 'impossible' happened)
# (GHC version 8.6.5 for x86_64-unknown-mingw32):
# loadArchive "C:\\Users\\runneradmin\\_bazel_runneradmin\\minshlu6\\external\\rules_haskell_ghc_windows_amd64\\mingw\\lib\\libz.dll.a": failed
#
# Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
#
# ghc.exe: Could not load `zlib1.dll'. Reason: addDLL: zlib1.dll or dependencies not loaded. (Win32 error 126)
#
# on //tests/haddock:haddock-lib-b.
execute_or_fail_loudly(ctx, ["rm", "mingw/lib/libz.dll.a"])

# We apply some patches, if needed.
patch(ctx)

Expand Down
3 changes: 3 additions & 0 deletions haskell/haddock.bzl
Expand Up @@ -142,6 +142,9 @@ def _haskell_doc_aspect_impl(target, ctx):

# TODO(mboes): we should be able to instantiate this template only
# once per toolchain instance, rather than here.
# TODO(aherrmann): Convert to a standalone sh_binary.
# Executable shell script files don't work on Windows.
# This fails with `%1 is not a valid Win32 application.`.
haddock_wrapper = ctx.actions.declare_file("haddock_wrapper-{}".format(hs.name))
ctx.actions.expand_template(
template = ctx.file._haddock_wrapper_tpl,
Expand Down
6 changes: 3 additions & 3 deletions haskell/repositories.bzl
Expand Up @@ -63,10 +63,10 @@ def rules_haskell_dependencies():
maybe(
http_archive,
name = "com_google_protobuf",
sha256 = "d0f5f605d0d656007ce6c8b5a82df3037e1d8fe8b121ed42e536f569dec16113",
strip_prefix = "protobuf-3.14.0",
sha256 = "f18a40816260a9a3190a94efb0fc26270b244a2436681602f0a944739095d632",
strip_prefix = "protobuf-3.15.1",
urls = [
"https://github.com/google/protobuf/archive/v3.14.0.tar.gz",
"https://github.com/google/protobuf/archive/v3.15.1.tar.gz",
],
)

Expand Down
1 change: 1 addition & 0 deletions start
Expand Up @@ -330,6 +330,7 @@ build:ci --jobs=2
build:ci --verbose_failures
common:ci --color=no
test:ci --test_output=errors
build:ci-windows --crosstool_top=@rules_haskell_ghc_windows_amd64//:cc_toolchain
$(insert_if_equal $mode "nix" '
# This project uses a GHC provisioned via nix.
Expand Down
59 changes: 41 additions & 18 deletions tests/BUILD.bazel
@@ -1,5 +1,6 @@
load(":inline_tests.bzl", "sh_inline_test")
load("@bazel_tools//tools/build_rules:test_rules.bzl", "rule_test")
load("@os_info//:os_info.bzl", "is_windows")
load("//tests:rule_test_exe.bzl", "rule_test_exe")
load(
"//haskell:c2hs.bzl",
Expand Down Expand Up @@ -103,36 +104,36 @@ rule_test_exe(
rule = "//tests/binary-custom-main",
)

rule_test(
rule_test_exe(
name = "test-binary-with-lib",
size = "small",
generates = ["binary-with-lib"],
rule = "//tests/binary-with-lib",
)

rule_test(
rule_test_exe(
name = "test-binary-with-prebuilt",
size = "small",
generates = ["binary-with-prebuilt"],
rule = "//tests/binary-with-prebuilt",
)

rule_test(
rule_test_exe(
name = "test-binary-with-main",
size = "small",
generates = ["binary-with-main"],
rule = "//tests/binary-with-main",
)

rule_test(
rule_test_exe(
name = "test-binary-with-sysdeps",
size = "small",
generates = ["binary-with-sysdeps"],
rule = "//tests/binary-with-sysdeps",
)

sh_test(
name = "test-binary-with-data",
name = "test-binary-with-data{}".format(".exe" if is_windows else ""),
size = "small",
srcs = ["//tests/binary-with-data"],
args = ["$(location //tests/binary-with-data:bin1)"],
Expand Down Expand Up @@ -177,7 +178,6 @@ rule_test(
"libHStestsZSlibrary-depsZSlibrary-deps.a",
],
":fastbuild_windows": [
"libHStestsZSlibrary-depsZSlibrary-deps-ghc{}.dll".format(test_ghc_version),
"libHStestsZSlibrary-depsZSlibrary-deps.a",
],
"//conditions:default": [
Expand All @@ -188,7 +188,7 @@ rule_test(
rule = "//tests/library-deps",
)

rule_test(
rule_test_exe(
name = "test-hsc",
size = "small",
generates = ["hsc"],
Expand All @@ -198,8 +198,23 @@ rule_test(
rule_test(
name = "test-haddock",
size = "small",
generates =
[
generates = select({
# Windows uses an older Stackage snapshot until we can update GHC.
":fastbuild_windows": [
"haddock/array-0.5.3.0",
"haddock/base-4.12.0.0",
"haddock/deepseq-1.4.4.0",
"haddock/ghc-boot-th-8.6.5",
"haddock/ghc-prim-0.5.3",
"haddock/index",
"haddock/integer-gmp-1.0.2.0",
"haddock/pretty-1.1.3.6",
"haddock/template-haskell-2.14.0.0",
"haddock/testsZShaddockZShaddock-lib-a",
"haddock/testsZShaddockZShaddock-lib-b",
"haddock/testsZShaddockZShaddock-lib-deep",
],
"//conditions:default": [
"haddock/array-0.5.4.0",
"haddock/base-4.13.0.0",
"haddock/deepseq-1.4.4.0",
Expand All @@ -213,6 +228,7 @@ rule_test(
"haddock/testsZShaddockZShaddock-lib-b",
"haddock/testsZShaddockZShaddock-lib-deep",
],
}),
rule = "//tests/haddock",
)

Expand All @@ -225,21 +241,21 @@ rule_test(
rule = "//tests/haskell_doctest:doctest-lib",
)

rule_test(
rule_test_exe(
name = "test-haskell_test",
size = "small",
generates = ["haskell_test"],
rule = "//tests/haskell_test:haskell_test",
)

rule_test(
rule_test_exe(
name = "test-java_classpath",
size = "small",
generates = ["java_classpath"],
rule = "//tests/java_classpath",
)

rule_test(
rule_test_exe(
name = "test-cc_haskell_import-cc-link",
size = "small",
generates = ["cc-bin"],
Expand Down Expand Up @@ -273,30 +289,34 @@ set -e
# Fails if executable was linked without -threaded flag.
$1 +RTS -N
""",
tags = [
# On Windows this needs to use rlocation to determine the runtime location of the binary.
"dont_test_on_windows",
],
)

rule_test(
rule_test_exe(
name = "test-lhs",
size = "small",
generates = ["lhs-bin"],
rule = "//tests/lhs:lhs-bin",
)

rule_test(
rule_test_exe(
name = "test-hs-boot",
size = "small",
generates = ["hs-boot"],
rule = "//tests/hs-boot:hs-boot",
)

rule_test(
rule_test_exe(
name = "test-textual-hdrs",
size = "small",
generates = ["textual-hdrs"],
rule = "//tests/textual-hdrs:textual-hdrs",
)

rule_test(
rule_test_exe(
name = "test-two-libs",
size = "small",
generates = ["two-libs"],
Expand Down Expand Up @@ -398,7 +418,10 @@ haskell_library(

haskell_doc(
name = "toto",
tags = ["requires_lz4"],
tags = [
"dont_test_on_windows",
"requires_lz4",
],
deps = [":utils"],
)

Expand All @@ -412,7 +435,7 @@ haskell_repl(
)

sh_test(
name = "ghcide-smoke-test",
name = "ghcide-smoke-test{}".format(".exe" if is_windows else ""),
srcs = ["@ghcide-exe//ghcide"],
args = ["--version"],
tags = [
Expand Down
4 changes: 4 additions & 0 deletions tests/binary-linkstatic-flag/BUILD.bazel
Expand Up @@ -55,6 +55,7 @@ dynamic_libraries_in_runfiles_test(
":c-lib",
"//tests/hackage:base",
],
tags = ["dont_test_on_windows"],
target_under_test = ":binary-dynamic",
)

Expand Down Expand Up @@ -88,6 +89,7 @@ sh_inline_test(
exit 1
fi
""",
tags = ["dont_test_on_windows"],
)

# Ensure that linkstatic=False only links to dynamic library targets.
Expand Down Expand Up @@ -121,10 +123,12 @@ sh_inline_test(
exit 1
fi
""",
tags = ["dont_test_on_windows"],
)

test_suite(
name = "binary-linkstatic-flag",
tags = ["dont_test_on_windows"],
tests = [
":test-binary-dynamic-symbols",
":test-binary-static-symbols",
Expand Down
3 changes: 3 additions & 0 deletions tests/c2hs/BUILD.bazel
Expand Up @@ -13,6 +13,7 @@ c2hs_library(
tags = [
# See https://github.com/tweag/rules_haskell/issues/1486
"dont_test_on_darwin_with_bindist",
"dont_test_on_windows",
],
deps = ["//tests:zlib"],
)
Expand All @@ -23,6 +24,7 @@ c2hs_library(
tags = [
# See https://github.com/tweag/rules_haskell/issues/1486
"dont_test_on_darwin_with_bindist",
"dont_test_on_windows",
],
deps = [":foo"],
)
Expand All @@ -37,6 +39,7 @@ haskell_library(
tags = [
# See https://github.com/tweag/rules_haskell/issues/1486
"dont_test_on_darwin_with_bindist",
"dont_test_on_windows",
],
deps = ["//tests/hackage:base"],
)
1 change: 1 addition & 0 deletions tests/c2hs/repo/BUILD.bazel
Expand Up @@ -8,6 +8,7 @@ c2hs_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 = ["@rules_haskell//tests:zlib"],
Expand Down
4 changes: 4 additions & 0 deletions tests/failing-repros/isystem-issue/BUILD.bazel
Expand Up @@ -23,5 +23,9 @@ haskell_binary(
should_fail(
name = "isystem-issue",
exitcode = 1,
tags = [
# On Windows this needs to use rlocation to determine the runtime location of the binary.
"dont_test_on_windows",
],
target = ":bin",
)

0 comments on commit 542eba5

Please sign in to comment.