Fix Windows CPP issues (#2991)

The issue was actually not really related to CPP but to the lack of
sandboxing on Windows. That resulted in us overwriting Prelude.hi from
the 1.dev rule with the Prelude.hi from the 1.6 rule in some cases
which caused the error we were seeing.

fixes #2983
This commit is contained in:
Moritz Kiefer 2019-09-24 15:42:48 +02:00 committed by mergify[bot]
parent afabb584c8
commit 78e51090df
3 changed files with 13 additions and 6 deletions

View File

@ -16,7 +16,7 @@ import DA.Internal.LF as X hiding (Pair(..), TextMap, unpackPair)
-- Windows so for now we always expose this
-- and crash at runtime if you use fromAnyTemplate/toAnyTemplate
-- with older LF versions.
#if 1
#ifdef DAML_ANY_TEMPLATE
import DA.Internal.Template as X
#else
import DA.Internal.Template as X hiding (fromAnyTemplate, toAnyTemplate)

View File

@ -146,6 +146,7 @@ cmdCompile numProcessors =
<$> inputFileOpt
<*> outputFileOpt
<*> optionsParser numProcessors (EnableScenarioService False) optPackageName
<*> optional (strOption $ long "iface-dir" <> metavar "IFACE_DIR" <> help "Directory for interface files")
cmdLint :: Int -> Mod CommandFields Command
cmdLint numProcessors =
@ -367,14 +368,14 @@ execIde telemetry (Debug debug) enableScenarioService ghcOpts mbProfileDir = Com
getDamlIdeState opts mbScenarioService loggerH sendMsg vfs (clientSupportsProgress caps)
execCompile :: FilePath -> FilePath -> Options -> Command
execCompile inputFile outputFile opts =
execCompile :: FilePath -> FilePath -> Options -> Maybe FilePath -> Command
execCompile inputFile outputFile opts mbIfaceDir =
Command Compile effect
where
effect = withProjectRoot' (ProjectOpts Nothing (ProjectCheck "" False)) $ \relativize -> do
loggerH <- getLogger opts "compile"
inputFile <- toNormalizedFilePath <$> relativize inputFile
opts' <- mkOptions opts
opts' <- mkOptions opts { optIfaceDir = mbIfaceDir }
withDamlIdeState opts' loggerH diagnosticsLogger $ \ide -> do
setFilesOfInterest ide (Set.singleton inputFile)
runAction ide $ do

View File

@ -105,21 +105,27 @@ def _daml_package_rule_impl(ctx):
tools = [ctx.executable.damlc_bootstrap, ctx.executable.cpp],
progress_message = "Compiling " + name + ".daml to daml-lf " + ctx.attr.daml_lf_version,
command = """
set -eoux pipefail
set -eou pipefail
PKG_NAME=`cat {pkg_name_version_file}`
# We use a temp directory here to avoid issues due to the lack of sandboxing
# on Windows.
IFACE_DIR=$(mktemp -d)
# Compile the dalf file
{damlc_bootstrap} compile \
--package-name $PKG_NAME \
--package-db {package_db_dir} \
--write-iface \
--iface-dir $IFACE_DIR \
--target {daml_lf_version} \
--cpp {cpp} \
-o {dalf_file} \
{main}
cp -a {pkg_root}/* {iface_dir}
cp -a .daml/interfaces/{pkg_root}/* {iface_dir}
cp -a $IFACE_DIR/{pkg_root}/* {iface_dir}
rm -rf $IFACE_DIR
""".format(
main = modules[ctx.attr.main],
pkg_name_version_file = pkg_name_version.path,