From 0c1878530b5341e52f1eb5f107ce109ce5953f19 Mon Sep 17 00:00:00 2001 From: Robin Krom Date: Tue, 17 Aug 2021 18:59:12 +0200 Subject: [PATCH] test: test for platform independent dars (#10535) We add a CI test to check that dars don't depend on the underlying operating system where the dar is build. CHANGELOG_BEGIN CHANGELOG_END --- ci/build-unix.yml | 4 ++ ci/build-windows.yml | 4 ++ ci/build.yml | 42 +++++++++++++++++++ ci/publish-platform-independence-dar.yml | 12 ++++++ compiler/damlc/tests/BUILD.bazel | 10 ++++- .../damlc/tests/PlatformIndependence.daml | 41 ++++++++++++++++++ dev-env/bin/unzip | 1 + nix/default.nix | 1 + rules_daml/daml.bzl | 12 +++++- 9 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 ci/publish-platform-independence-dar.yml create mode 100644 compiler/damlc/tests/PlatformIndependence.daml create mode 120000 dev-env/bin/unzip diff --git a/ci/build-unix.yml b/ci/build-unix.yml index 9e1ff66c9d..542ef6921f 100644 --- a/ci/build-unix.yml +++ b/ci/build-unix.yml @@ -38,6 +38,10 @@ steps: DAML_SDK_RELEASE_VERSION: ${{parameters.release_tag}} DAML_SCALA_VERSION: ${{parameters.scala_version}} + - template: publish-platform-independence-dar.yml + parameters: + platform: '${{parameters.name}}' + - task: PublishBuildArtifacts@1 condition: succeededOrFailed() continueOnError: true diff --git a/ci/build-windows.yml b/ci/build-windows.yml index 10e2dcb619..7d9b615260 100644 --- a/ci/build-windows.yml +++ b/ci/build-windows.yml @@ -32,6 +32,10 @@ steps: # number). SKIP_TESTS: ${{parameters.skip_tests}} + - template: publish-platform-independence-dar.yml + parameters: + platform: 'windows' + - task: PublishBuildArtifacts@1 condition: failed() displayName: 'Publish the bazel test logs' diff --git a/ci/build.yml b/ci/build.yml index 1002a4a991..ef78ed8031 100644 --- a/ci/build.yml +++ b/ci/build.yml @@ -338,6 +338,48 @@ jobs: trigger_sha: '$(trigger_sha)' - template: report-end.yml +- job: platform_independence_test + dependsOn: + - Windows + - Linux + - macOS + pool: + name: 'ubuntu_20_04' + demands: assignment -equals default + steps: + - checkout: self + - bash: ci/dev-env-install.sh + displayName: 'Build/Install the Developer Environment' + - task: DownloadPipelineArtifact@2 + inputs: + artifactName: platform-independence-dar-linux + targetPath: $(Build.StagingDirectory)/platform-independence/linux/ + - task: DownloadPipelineArtifact@2 + inputs: + artifactName: platform-independence-dar-windows + targetPath: $(Build.StagingDirectory)/platform-independence/windows/ + - task: DownloadPipelineArtifact@2 + inputs: + artifactName: platform-independence-dar-macos + targetPath: $(Build.StagingDirectory)/platform-independence/macos/ + - bash: | + set -euo pipefail + eval "$(./dev-env/bin/dade-assist)" + + DIR1=$(mktemp -d) + DIR2=$(mktemp -d) + DIR3=$(mktemp -d) + trap "rm -rf $DIR1; rm -rf $DIR2; rm -rf $DIR3" EXIT + + unzip -d $DIR1 $(Build.StagingDirectory)/platform-independence/linux/platform-independence.dar + unzip -d $DIR2 $(Build.StagingDirectory)/platform-independence/windows/platform-independence.dar + unzip -d $DIR3 $(Build.StagingDirectory)/platform-independence/macos/platform-independence.dar + + # hie/hi files may differ. + diff -r --strip-trailing-cr -x '*.hie' -x '*.hi' $DIR1 $DIR2 + diff -r --strip-trailing-cr -x '*.hie' -x '*.hi' $DIR1 $DIR3 + displayName: 'Compare platform-independence dars of different platforms.' + - job: compatibility_ts_libs dependsOn: - da_ghc_lib diff --git a/ci/publish-platform-independence-dar.yml b/ci/publish-platform-independence-dar.yml new file mode 100644 index 0000000000..d7458d2930 --- /dev/null +++ b/ci/publish-platform-independence-dar.yml @@ -0,0 +1,12 @@ +# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +parameters: + platform: '' + +steps: + - task: PublishBuildArtifacts@1 + inputs: + pathtoPublish: bazel-bin/compiler/damlc/tests/platform-independence.dar + artifactName: platform-independence-dar-${{parameters.platform}} + diff --git a/compiler/damlc/tests/BUILD.bazel b/compiler/damlc/tests/BUILD.bazel index a0ee1cf6e9..04ecbd2cd3 100644 --- a/compiler/damlc/tests/BUILD.bazel +++ b/compiler/damlc/tests/BUILD.bazel @@ -4,7 +4,7 @@ load("//bazel_tools:haskell.bzl", "da_haskell_binary", "da_haskell_library", "da_haskell_test") load("@os_info//:os_info.bzl", "is_windows") load(":util.bzl", "damlc_compile_test") -load("//rules_daml:daml.bzl", "daml_compile") +load("//rules_daml:daml.bzl", "daml_compile", "daml_compile_with_dalf") load("@build_environment//:configuration.bzl", "sdk_version") load("//daml-lf/language:daml-lf.bzl", "COMPILER_LF_VERSIONS", "lf_version_configuration") load("//compiler/damlc:util.bzl", "ghc_pkg") @@ -991,3 +991,11 @@ da_haskell_binary( "//libs-haskell/da-hs-base", ], ) + +daml_compile_with_dalf( + name = "platform-independence", + srcs = glob(["PlatformIndependence.daml"]), + # don't turn warnings into errors, we have a missing pattern on purpose in + # PlatformIndependence.daml. + ghc_options = [], +) diff --git a/compiler/damlc/tests/PlatformIndependence.daml b/compiler/damlc/tests/PlatformIndependence.daml new file mode 100644 index 0000000000..b9c8ea5879 --- /dev/null +++ b/compiler/damlc/tests/PlatformIndependence.daml @@ -0,0 +1,41 @@ +-- Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module PlatformIndependence where + +import DA.Stack + +type AssetId = ContractId Asset + +data ADT + = Foo + | Bar + | Baz + +give : HasCallStack => Party -> Party -> Text -> Update (ContractId Asset) +give issuer owner name = do + let fs = [ srcLocFile srcLoc | (_t, srcLoc) <- getCallStack callStack] + trace (show fs) $ create Asset{..} + +incompletePattternMatch : ADT -> Update () +incompletePattternMatch adt = + case adt of + Foo -> pure () + Bar -> pure () + +template Asset + with + issuer : Party + owner : Party + name : Text + where + ensure name /= "" + signatory issuer + controller owner can + Give : AssetId + with + newOwner : Party + do + incompletePattternMatch Baz + create this with + owner = newOwner diff --git a/dev-env/bin/unzip b/dev-env/bin/unzip new file mode 120000 index 0000000000..943ba2d88c --- /dev/null +++ b/dev-env/bin/unzip @@ -0,0 +1 @@ +../lib/dade-exec-nix-tool \ No newline at end of file diff --git a/nix/default.nix b/nix/default.nix index 426be500fa..3cb13ae0dd 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -191,6 +191,7 @@ in rec { # Packaging tools patchelf = bazel_dependencies.patchelf; zip = bazel_dependencies.zip; + unzip = pkgs.unzip; openssl = pkgs.openssl.bin; tar = bazel_dependencies.gnutar; diff --git a/rules_daml/daml.bzl b/rules_daml/daml.bzl index 613fceb8da..93c01e4e42 100644 --- a/rules_daml/daml.bzl +++ b/rules_daml/daml.bzl @@ -19,13 +19,12 @@ _zipper = attr.label( cfg = "host", ) -ghc_opts = ["--ghc-option=-Werror"] - def _daml_configure_impl(ctx): project_name = ctx.attr.project_name project_version = ctx.attr.project_version daml_yaml = ctx.outputs.daml_yaml target = ctx.attr.target + ghc_opts = ctx.attr.ghc_options opts = ghc_opts + ["--target={}".format(target)] if target else ghc_opts ctx.actions.write( output = daml_yaml, @@ -62,6 +61,10 @@ _daml_configure = rule( "target": attr.string( doc = "DAML-LF version to output.", ), + "ghc_options": attr.string_list( + doc = "Options passed to GHC.", + default = ["--ghc-option=-Werror"], + ), }, ) @@ -84,6 +87,7 @@ def _daml_build_impl(ctx): input_dars = [file_of_target(k) for k in dar_dict.keys()] output_dar = ctx.outputs.dar posix = ctx.toolchains["@rules_sh//sh/posix:toolchain_type"] + ghc_opts = ctx.attr.ghc_options ctx.actions.run_shell( tools = [damlc], inputs = [daml_yaml] + srcs + input_dars, @@ -146,6 +150,10 @@ _daml_build = rule( mandatory = True, doc = "The generated DAR file.", ), + "ghc_options": attr.string_list( + doc = "Options passed to GHC.", + default = ["--ghc-option=-Werror"], + ), "_damlc": _damlc, }, toolchains = ["@rules_sh//sh/posix:toolchain_type"],