Skip to content

Commit

Permalink
test: test for platform independent dars (digital-asset#10535)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Robin Krom authored Aug 17, 2021
1 parent 3822a8c commit 0c18785
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ci/build-unix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions ci/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
42 changes: 42 additions & 0 deletions ci/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions ci/publish-platform-independence-dar.yml
Original file line number Diff line number Diff line change
@@ -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}}

10 changes: 9 additions & 1 deletion compiler/damlc/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 = [],
)
41 changes: 41 additions & 0 deletions compiler/damlc/tests/PlatformIndependence.daml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions dev-env/bin/unzip
1 change: 1 addition & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
12 changes: 10 additions & 2 deletions rules_daml/daml.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"],
),
},
)

Expand All @@ -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,
Expand Down Expand Up @@ -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"],
Expand Down

0 comments on commit 0c18785

Please sign in to comment.