From 6cf3a5276ffed65b171fc3f63d3e3f5ea4928dbc Mon Sep 17 00:00:00 2001 From: Robin Krom Date: Fri, 8 Nov 2019 16:32:30 +0100 Subject: [PATCH] language: introduce data-imports (#3399) * language: introduce data-imports Right now the user experience for importing dalfs and dars from different sdks is quiet confusing. This PR tries to solve this. We add an additional field `data-imports` to daml.yaml. These imports can come from different SDK's and we will generate interface files containing the data types and their Template instances. This also simplifies the migration command, as it now always imports the respective packages as `data-imports`. --- .../daml-compiler/src/DA/Daml/Compiler/Dar.hs | 1 + .../src/DA/Daml/Compiler/Upgrade.hs | 12 +- .../daml-opts-types/DA/Daml/Options/Types.hs | 3 - compiler/damlc/lib/DA/Cli/Damlc.hs | 253 +++++++++--------- compiler/damlc/lib/DA/Cli/Options.hs | 8 - .../daml-helper/src/DA/Daml/Helper/Main.hs | 2 +- .../daml-helper/src/DA/Daml/Helper/Run.hs | 7 +- .../src/DA/Daml/Assistant/IntegrationTests.hs | 7 +- docs/source/daml/reference/packages.rst | 25 +- templates/migrate/daml.yaml.template | 3 +- unreleased.rst | 3 + 11 files changed, 171 insertions(+), 153 deletions(-) diff --git a/compiler/damlc/daml-compiler/src/DA/Daml/Compiler/Dar.hs b/compiler/damlc/daml-compiler/src/DA/Daml/Compiler/Dar.hs index 83cf73213eba..801afc106b0e 100644 --- a/compiler/damlc/daml-compiler/src/DA/Daml/Compiler/Dar.hs +++ b/compiler/damlc/daml-compiler/src/DA/Daml/Compiler/Dar.hs @@ -88,6 +88,7 @@ data PackageConfigFields = PackageConfigFields , pExposedModules :: Maybe [String] , pVersion :: Maybe String , pDependencies :: [String] + , pDataDependencies :: [String] , pSdkVersion :: String , cliOpts :: Maybe [String] } diff --git a/compiler/damlc/daml-compiler/src/DA/Daml/Compiler/Upgrade.hs b/compiler/damlc/daml-compiler/src/DA/Daml/Compiler/Upgrade.hs index 3ef92be93c3a..5938e1a70689 100644 --- a/compiler/damlc/daml-compiler/src/DA/Daml/Compiler/Upgrade.hs +++ b/compiler/damlc/daml-compiler/src/DA/Daml/Compiler/Upgrade.hs @@ -53,13 +53,11 @@ data Env = Env newtype DiffSdkVers = DiffSdkVers Bool -- | Generate non-consuming choices to upgrade all templates defined in the module. -generateUpgradeModule :: DiffSdkVers -> [String] -> String -> String -> String -> String -generateUpgradeModule (DiffSdkVers diffSdks) templateNames modName qualA qualB = +generateUpgradeModule :: [String] -> String -> String -> String -> String +generateUpgradeModule templateNames modName qualA qualB = unlines $ header ++ concatMap upgradeTemplates templateNames where - header - | diffSdks = header0 ++ header1 ++ header2 - | otherwise = header0 ++ header2 + header = header0 ++ header1 ++ header2 -- If we compile with packages from a single sdk version, the instances modules will not be -- there and hence we can not include header1. header0 = @@ -69,8 +67,8 @@ generateUpgradeModule (DiffSdkVers diffSdks) templateNames modName qualA qualB = , "import " <> modName <> qualB <> " qualified as B" ] header1 = - [ "import " <> modName <> "Instances()" - , "import " <> modName <> "Instances()" + [ "import " <> modName <> qualA <> "Instances()" + , "import " <> modName <> qualB <> "Instances()" ] header2 = [ "import DA.Upgrade" diff --git a/compiler/damlc/daml-opts/daml-opts-types/DA/Daml/Options/Types.hs b/compiler/damlc/daml-opts/daml-opts-types/DA/Daml/Options/Types.hs index 7c478bdae5f4..7420d3b5ee50 100644 --- a/compiler/damlc/daml-opts/daml-opts-types/DA/Daml/Options/Types.hs +++ b/compiler/damlc/daml-opts/daml-opts-types/DA/Daml/Options/Types.hs @@ -63,8 +63,6 @@ data Options = Options -- ^ Information about dlint usage. , optIsGenerated :: Bool -- ^ Whether we're compiling generated code. Then we allow internal imports. - , optAllowDifferentSdks :: Bool - -- ^ Whether we're allowing imports from packages compiled with different SDK's. , optDflagCheck :: Bool -- ^ Whether to check dflags. In some cases we want to turn this check of. For example when -- migrating or running the daml doc test. @@ -169,7 +167,6 @@ defaultOptions mbVersion = , optSkipScenarioValidation = SkipScenarioValidation False , optDlintUsage = DlintDisabled , optIsGenerated = False - , optAllowDifferentSdks = False , optDflagCheck = True , optCoreLinting = False , optHaddock = Haddock False diff --git a/compiler/damlc/lib/DA/Cli/Damlc.hs b/compiler/damlc/lib/DA/Cli/Damlc.hs index a9f6978f9e98..b76334c65dce 100644 --- a/compiler/damlc/lib/DA/Cli/Damlc.hs +++ b/compiler/damlc/lib/DA/Cli/Damlc.hs @@ -464,9 +464,10 @@ parseProjectConfig project = do version <- queryProjectConfigRequired ["version"] project dependencies <- queryProjectConfigRequired ["dependencies"] project + dataDeps <- fromMaybe [] <$> queryProjectConfig ["data-dependencies"] project sdkVersion <- queryProjectConfigRequired ["sdk-version"] project cliOpts <- queryProjectConfig ["build-options"] project - Right $ PackageConfigFields name main exposedModules version dependencies sdkVersion cliOpts + Right $ PackageConfigFields name main exposedModules version dependencies dataDeps sdkVersion cliOpts -- | We assume that this is only called within `withProjectRoot`. withPackageConfig :: (PackageConfigFields -> IO a) -> IO a @@ -495,12 +496,12 @@ initPackageDb opts (InitPkgDb shouldInit) = case parseProjectConfig project of Left err -> throwIO err Right PackageConfigFields {..} -> do - createProjectPackageDb opts pDependencies + createProjectPackageDb opts pSdkVersion pDependencies pDataDependencies -- | Create the project package database containing the given dar packages. createProjectPackageDb :: - Options -> [FilePath] -> IO () -createProjectPackageDb opts fps = do + Options -> String -> [FilePath] -> [FilePath] -> IO () +createProjectPackageDb opts thisSdkVer deps0 dataDeps = do let dbPath = projectPackageDatabase (lfVersionString $ optDamlLfVersion opts) let -- Since we reinitialize the whole package db anyway, @@ -524,111 +525,114 @@ createProjectPackageDb opts fps = do | otherwise = pure fp in mapM expand - fps0 <- handleSdkPackages $ filter (`notElem` basePackages) fps - let (fpDars, fpDalfs) = partition ((== ".dar") . takeExtension) fps0 - dars <- mapM extractDar fpDars - let uniqSdkVersions = nubSort $ map edSdkVersions dars - if | (length uniqSdkVersions > 1 && optAllowDifferentSdks opts) || not (null fpDalfs) - -> do - let dalfs = concatMap edDalfs dars - -- when we compile packages with different sdk versions or with dalf dependencies, we - -- need to generate the interface files - let dalfsFromDars = - [ ( dropExtension $ takeFileName $ ZipArchive.eRelativePath e - , BSL.toStrict $ ZipArchive.fromEntry e) - | e <- dalfs - ] - dalfsFromFps <- - forM fpDalfs $ \fp -> do - bs <- B.readFile fp - pure (dropExtension $ takeFileName fp, bs) - let allDalfs = dalfsFromDars ++ dalfsFromFps - pkgs <- - forM allDalfs $ \(name, dalf) -> do - (pkgId, package) <- - either (fail . DA.Pretty.renderPretty) pure $ - Archive.decodeArchive dalf - pure (pkgId, package, dalf, stringToUnitId name) - -- mapping from package id's to unit id's. if the same package is imported with - -- different unit id's, we would loose a unit id here. - let pkgMap = - MS.fromList - [(pkgId, unitId) | (pkgId, _pkg, _bs, unitId) <- pkgs] - -- order the packages in topological order - let (depGraph, vertexToNode, _keyToVertex) = - graphFromEdges $ do - (pkgId, dalf, bs, unitId) <- pkgs - let pkgRefs = - [ pid - | LF.PRImport pid <- toListOf packageRefs dalf - ] - let getUid = getUnitId unitId pkgMap - let src = generateSrcPkgFromLf getUid pkgId dalf - let templInstSrc = - generateTemplateInstancesPkgFromLf - getUid - pkgId - dalf - pure - ( (src, templInstSrc, unitId, dalf, bs) - , pkgId - , pkgRefs) - let pkgIdsTopoSorted = reverse $ topSort depGraph - dbPathAbs <- makeAbsolute dbPath - projectPackageDatabaseAbs <- makeAbsolute projectPackageDatabase - forM_ pkgIdsTopoSorted $ \vertex -> do - let ((src, templInstSrc, uid, dalf, bs), pkgId, _) = - vertexToNode vertex - when (uid /= primUnitId) $ do - let unitIdStr = unitIdString uid - let instancesUnitIdStr = "instances-" <> unitIdStr - let pkgIdStr = T.unpack $ LF.unPackageId pkgId - let (pkgName, mbPkgVersion) = - fromMaybe (unitIdStr, Nothing) $ do - (uId, ver) <- stripInfixEnd "-" unitIdStr - guard $ all (`elem` '.' : ['0' .. '9']) ver - Just (uId, Just ver) - let deps = - [ unitIdString uId <.> "dalf" - | ((_src, _templSrc, uId, _dalf, _bs), pId, _) <- - map vertexToNode $ reachable depGraph vertex - , pkgId /= pId - ] - let workDir = dbPath unitIdStr <> "-" <> pkgIdStr - createDirectoryIfMissing True workDir - -- write the dalf package - B.writeFile (workDir unitIdStr <.> "dalf") bs - generateAndInstallIfaceFiles - dalf - src - opts - workDir - dbPath - projectPackageDatabase - unitIdStr - pkgIdStr - pkgName - mbPkgVersion - deps - - unless (null templInstSrc) $ - generateAndInstallInstancesPkg - templInstSrc - opts - dbPathAbs - projectPackageDatabaseAbs - unitIdStr - instancesUnitIdStr - pkgName - mbPkgVersion - deps - - | length uniqSdkVersions <= 1 -> forM_ dars $ - \ExtractedDar{..} -> installDar dbPath edConfFiles edDalfs edSrcs - | otherwise -> + deps <- handleSdkPackages $ filter (`notElem` basePackages) deps0 + depsExtracted <- mapM extractDar deps + let uniqSdkVersions = nubSort $ filter (/= "0.0.0") $ thisSdkVer : map edSdkVersions depsExtracted + -- we filter the 0.0.0 version because otherwise integration tests fail that import SDK packages + unless (length uniqSdkVersions <= 1) $ fail $ "Package dependencies from different SDK versions: " ++ intercalate ", " uniqSdkVersions + + -- deal with data imports first + let (fpDars, fpDalfs) = partition ((== ".dar") . takeExtension) dataDeps + dars <- mapM extractDar fpDars + let dalfs = concatMap edDalfs dars + -- when we compile packages with different sdk versions or with dalf dependencies, we + -- need to generate the interface files + let dalfsFromDars = + [ ( dropExtension $ takeFileName $ ZipArchive.eRelativePath e + , BSL.toStrict $ ZipArchive.fromEntry e) + | e <- dalfs + ] + dalfsFromFps <- + forM fpDalfs $ \fp -> do + bs <- B.readFile fp + pure (dropExtension $ takeFileName fp, bs) + let allDalfs = dalfsFromDars ++ dalfsFromFps + pkgs <- + forM allDalfs $ \(name, dalf) -> do + (pkgId, package) <- + either (fail . DA.Pretty.renderPretty) pure $ + Archive.decodeArchive dalf + pure (pkgId, package, dalf, stringToUnitId name) + -- mapping from package id's to unit id's. if the same package is imported with + -- different unit id's, we would loose a unit id here. + let pkgMap = + MS.fromList + [(pkgId, unitId) | (pkgId, _pkg, _bs, unitId) <- pkgs] + -- order the packages in topological order + let (depGraph, vertexToNode, _keyToVertex) = + graphFromEdges $ do + (pkgId, dalf, bs, unitId) <- pkgs + let pkgRefs = + [ pid + | LF.PRImport pid <- toListOf packageRefs dalf + ] + let getUid = getUnitId unitId pkgMap + let src = generateSrcPkgFromLf getUid pkgId dalf + let templInstSrc = + generateTemplateInstancesPkgFromLf + getUid + pkgId + dalf + pure + ( (src, templInstSrc, unitId, dalf, bs) + , pkgId + , pkgRefs) + let pkgIdsTopoSorted = reverse $ topSort depGraph + dbPathAbs <- makeAbsolute dbPath + projectPackageDatabaseAbs <- makeAbsolute projectPackageDatabase + forM_ pkgIdsTopoSorted $ \vertex -> do + let ((src, templInstSrc, uid, dalf, bs), pkgId, _) = + vertexToNode vertex + when (uid /= primUnitId) $ do + let unitIdStr = unitIdString uid + let instancesUnitIdStr = "instances-" <> unitIdStr + let pkgIdStr = T.unpack $ LF.unPackageId pkgId + let (pkgName, mbPkgVersion) = + fromMaybe (unitIdStr, Nothing) $ do + (uId, ver) <- stripInfixEnd "-" unitIdStr + guard $ all (`elem` '.' : ['0' .. '9']) ver + Just (uId, Just ver) + let deps = + [ unitIdString uId <.> "dalf" + | ((_src, _templSrc, uId, _dalf, _bs), pId, _) <- + map vertexToNode $ reachable depGraph vertex + , pkgId /= pId + ] + let workDir = dbPath unitIdStr <> "-" <> pkgIdStr + createDirectoryIfMissing True workDir + -- write the dalf package + B.writeFile (workDir unitIdStr <.> "dalf") bs + generateAndInstallIfaceFiles + dalf + src + opts + workDir + dbPath + projectPackageDatabase + unitIdStr + pkgIdStr + pkgName + mbPkgVersion + deps + + unless (null templInstSrc) $ + generateAndInstallInstancesPkg + templInstSrc + opts + dbPathAbs + projectPackageDatabaseAbs + unitIdStr + instancesUnitIdStr + pkgName + mbPkgVersion + deps + + -- finally install the dependecies + forM_ depsExtracted $ + \ExtractedDar{..} -> installDar dbPath edConfFiles edDalfs edSrcs where -- generate interface files and install them in the package database generateAndInstallIfaceFiles :: @@ -677,6 +681,7 @@ createProjectPackageDb opts fps = do , pExposedModules = Nothing , pVersion = mbPkgVersion , pDependencies = deps + , pDataDependencies = [] , pSdkVersion = "unknown" , cliOpts = Nothing } @@ -718,6 +723,7 @@ createProjectPackageDb opts fps = do , pExposedModules = Nothing , pVersion = mbPkgVersion , pDependencies = (unitIdStr <.> "dalf") : deps + , pDataDependencies = [] , pSdkVersion = sdkVersion , cliOpts = Nothing } @@ -923,6 +929,7 @@ execPackage projectOpts filePath opts mbOutFile dalfInput = , pExposedModules = Nothing , pVersion = Nothing , pDependencies = [] + , pDataDependencies = [] , pSdkVersion = "" , cliOpts = Nothing } @@ -1024,7 +1031,7 @@ execMigrate projectOpts inFile1_ inFile2_ mbDir = withProjectRoot' projectOpts $ \_relativize -> do -- get the package name and the lf-package - [(pkgName1, _pkgId1, lfPkg1, sdkVer1), (pkgName2, _pkgId2, lfPkg2, sdkVer2)] <- + [(pkgName1, _pkgId1, lfPkg1), (pkgName2, _pkgId2, lfPkg2)] <- forM [inFile1, inFile2] $ \inFile -> do bytes <- B.readFile inFile let dar = ZipArchive.toArchive $ BSL.fromStrict bytes @@ -1033,37 +1040,30 @@ execMigrate projectOpts inFile1_ inFile2_ mbDir = let pkgName = takeBaseName $ mainDalfPath dalfManifest mainDalfEntry <- getEntry (mainDalfPath dalfManifest) dar (mainPkgId, mainLfPkg) <- decode $ BSL.toStrict $ ZipArchive.fromEntry mainDalfEntry - pure (pkgName, mainPkgId, mainLfPkg, sdkVersion dalfManifest) + pure (pkgName, mainPkgId, mainLfPkg) -- generate upgrade modules and instances modules let eqModNames = (NM.names $ LF.packageModules lfPkg1) `intersect` (NM.names $ LF.packageModules lfPkg2) - thisSdkVer <- getSdkVersion - let differentSdks = (length $ nubSort [sdkVer1, sdkVer2, thisSdkVer]) /= 1 let eqModNamesStr = map (T.unpack . LF.moduleNameString) eqModNames - let buildOptions0 = - [ "--allow-different-sdks" - , "'--package=" <> show ("instances-" <> pkgName1 - , [(m', m' ++ "A") - | m <- eqModNamesStr, let m' = m <> "Instances" + let buildOptions = + ["'--package=" <> show ("instances-" <> pkgName1 + , [(m', m'') + | m <- eqModNamesStr + , let m' = m <> "Instances" + , let m'' = m <> "AInstances" ] ) <> "'" , "'--package=" <> show ("instances-" <> pkgName2 - , [(m', m' ++ "B") - | m <- eqModNamesStr, let m' = m <> "Instances" + , [(m', m'') + | m <- eqModNamesStr + , let m' = m <> "Instances" + , let m'' = m <> "BInstances" ] ) <> "'" - ] - let buildOptions1 = - [ "'--package=" <> show (pkgName1, [(m, m ++ "A") | m <- eqModNamesStr]) <> "'" + , "'--package=" <> show (pkgName1, [(m, m ++ "A") | m <- eqModNamesStr]) <> "'" , "'--package=" <> show (pkgName2, [(m, m ++ "B") | m <- eqModNamesStr]) <> "'" ] - let buildOptions - | differentSdks = buildOptions0 ++ buildOptions1 - | otherwise = buildOptions1 - --If we have different sdks we need to allow this with the flag --allow-different-sdks and - --also import the created instances modules with aliases (their names clash). If not, we - --only need aliases for the modules of the two imported packages. forM_ eqModNames $ \m@(LF.ModuleName modName) -> do let upgradeModPath = (joinPath $ fromMaybe "" mbDir : map T.unpack modName) <> @@ -1074,7 +1074,6 @@ execMigrate projectOpts inFile1_ inFile2_ mbDir = getModule m lfPkg1 let generatedUpgradeMod = generateUpgradeModule - (DiffSdkVers differentSdks) templateNames (T.unpack $ LF.moduleNameString m) "A" diff --git a/compiler/damlc/lib/DA/Cli/Options.hs b/compiler/damlc/lib/DA/Cli/Options.hs index 1004adf53a6e..bee9bee5e3c8 100644 --- a/compiler/damlc/lib/DA/Cli/Options.hs +++ b/compiler/damlc/lib/DA/Cli/Options.hs @@ -411,7 +411,6 @@ optionsParser numProcessors enableScenarioService parsePkgName = Options <*> pure (optSkipScenarioValidation $ defaultOptions Nothing) <*> dlintUsageOpt <*> optIsGenerated - <*> optAllowDifferentSdks <*> optNoDflagCheck <*> pure False <*> pure (Haddock False) @@ -497,13 +496,6 @@ optionsParser numProcessors enableScenarioService parsePkgName = Options <> help "Set path to CPP." <> internal - optAllowDifferentSdks :: Parser Bool - optAllowDifferentSdks = - switch $ - help "Allow the import of packages compiled with different SDKs." <> - long "allow-different-sdks" <> - internal - optGhcCustomOptions :: Parser [String] optGhcCustomOptions = fmap concat $ many $ diff --git a/daml-assistant/daml-helper/src/DA/Daml/Helper/Main.hs b/daml-assistant/daml-helper/src/DA/Daml/Helper/Main.hs index cc3e1373f8e4..407e12788eab 100644 --- a/daml-assistant/daml-helper/src/DA/Daml/Helper/Main.hs +++ b/daml-assistant/daml-helper/src/DA/Daml/Helper/Main.hs @@ -217,7 +217,7 @@ commandParser = subparser $ fold runCommand :: Command -> IO () runCommand DamlStudio {..} = runDamlStudio replaceExtension remainingArguments runCommand RunJar {..} = runJar jarPath mbLogbackConfig remainingArguments -runCommand New {..} = runNew targetFolder templateNameM [] +runCommand New {..} = runNew targetFolder templateNameM [] [] runCommand Migrate {..} = runMigrate targetFolder pkgPathFrom pkgPathTo runCommand Init {..} = runInit targetFolderM runCommand ListTemplates = runListTemplates diff --git a/daml-assistant/daml-helper/src/DA/Daml/Helper/Run.hs b/daml-assistant/daml-helper/src/DA/Daml/Helper/Run.hs index c76f9ce2d8e1..39670fd40540 100644 --- a/daml-assistant/daml-helper/src/DA/Daml/Helper/Run.hs +++ b/daml-assistant/daml-helper/src/DA/Daml/Helper/Run.hs @@ -525,8 +525,8 @@ runInit targetFolderM = do -- * Creation of a project in existing folder (suggest daml init instead). -- * Creation of a project inside another project. -- -runNew :: FilePath -> Maybe String -> [String] -> IO () -runNew targetFolder templateNameM pkgDeps = do +runNew :: FilePath -> Maybe String -> [String] -> [String] -> IO () +runNew targetFolder templateNameM pkgDeps dataDeps = do templatesFolder <- getTemplatesFolder let templateName = fromMaybe defaultProjectTemplate templateNameM templateFolder = templatesFolder templateName @@ -606,6 +606,7 @@ runNew targetFolder templateNameM pkgDeps = do let config = replace "__VERSION__" sdkVersion . replace "__PROJECT_NAME__" projectName . replace "__DEPENDENCIES__" (unlines [" - " <> dep | dep <- pkgDeps]) + . replace "__DATA_DEPENDENCIES__" (unlines [" - " <> dep | dep <- dataDeps]) $ configTemplate writeFileUTF8 configPath config removeFile configTemplatePath @@ -622,7 +623,7 @@ runMigrate targetFolder pkgPath1 pkgPath2 pkgPath1Abs <- makeAbsolute pkgPath1 pkgPath2Abs <- makeAbsolute pkgPath2 -- Create a new project - runNew targetFolder (Just "migrate") [pkgPath1Abs, pkgPath2Abs] + runNew targetFolder (Just "migrate") [] [pkgPath1Abs, pkgPath2Abs] -- Call damlc to create the upgrade source files. procConfig <- toAssistantCommand diff --git a/daml-assistant/integration-tests/src/DA/Daml/Assistant/IntegrationTests.hs b/daml-assistant/integration-tests/src/DA/Daml/Assistant/IntegrationTests.hs index fd3e25b88ac1..5e34a1d0072d 100644 --- a/daml-assistant/integration-tests/src/DA/Daml/Assistant/IntegrationTests.hs +++ b/daml-assistant/integration-tests/src/DA/Daml/Assistant/IntegrationTests.hs @@ -414,7 +414,8 @@ packagingTests = testGroup "packaging" , "name: proj" , "version: 0.1.0" , "source: ." - , "dependencies: [daml-prim, daml-stdlib, simple-dalf-0.0.0.dalf]" + , "dependencies: [daml-prim, daml-stdlib]" + , "data-dependencies: [simple-dalf-0.0.0.dalf]" , "build-options:" , "- --generated-src" ] @@ -422,7 +423,7 @@ packagingTests = testGroup "packaging" [ "daml 1.2" , "module A where" , "import qualified Module" - , "import qualified ModuleInstances" + , "import qualified ModuleInstances()" , "import DA.Internal.Template (toAnyTemplate, fromAnyTemplate)" , "newTemplate : Party -> Party -> Module.Template" , "newTemplate p1 p2 = Module.Template with Module.this = p1, Module.arg = p2" @@ -631,6 +632,8 @@ packagingTests = testGroup "packaging" , "module Main where" , "import MainA qualified as A" , "import MainB qualified as B" + , "import MainAInstances()" + , "import MainBInstances()" , "import MainAGenInstances()" , "import MainBGenInstances()" , "import DA.Upgrade" diff --git a/docs/source/daml/reference/packages.rst b/docs/source/daml/reference/packages.rst index 5896cad17afd..2e89667dfde3 100644 --- a/docs/source/daml/reference/packages.rst +++ b/docs/source/daml/reference/packages.rst @@ -37,7 +37,7 @@ DAML package management. To import a package ``Bar`` in project ``Foo``, add the dependencies: - daml-prim - daml-stdlib - - /home/johndoe/bar/.daml/dist/bar.dar + - /home/johndoe/bar/.daml/dist/bar-1.0.0.dar The import path needs to be the relative or absolute path pointing to the created DAML archive of the ``bar`` project. The archive can reside anywhere on the local file system. Note that the SDK @@ -53,3 +53,26 @@ Some.Module``. Note that all modules of package ``foo`` that should be available as imports of other packages need to be exposed by adding them to the ``exposed-modules`` stanza of the `daml.yaml` file. If the ``exposed-modules`` stanza is omitted, all modules of the project are exposed by default. + +Importing archives compiled with different SDK's +************************************************ + +All DAML archive dependencies of a project need to be compiled with the same SDK as the project +itself. However, it is possible to import templates and data types of an archive compiled with an +older SDK, by listing them under the ``data-dependencies`` stanza: + +.. code-block:: yaml + + sdk-version: 0.0.0 + name: foo + source: daml + version: 1.0.0 + exposed-modules: + - Some.Module + - Some.Other.Module + dependencies: + - daml-prim + - daml-stdlib + - /home/johndoe/bar/.daml/dist/bar.dar + data-dependencies: + - /home/jondoe/bar-0.0.0/.daml/dist/bar-0.0.0.dar diff --git a/templates/migrate/daml.yaml.template b/templates/migrate/daml.yaml.template index cc61de4d0a2f..b1f68d2d48ec 100644 --- a/templates/migrate/daml.yaml.template +++ b/templates/migrate/daml.yaml.template @@ -8,4 +8,5 @@ version: 0.0.1 dependencies: - daml-prim - daml-stdlib -__DEPENDENCIES__ +data-dependencies: +__DATA_DEPENDENCIES__ diff --git a/unreleased.rst b/unreleased.rst index a1eff1d5dab7..dd1a652a573f 100644 --- a/unreleased.rst +++ b/unreleased.rst @@ -18,6 +18,9 @@ HEAD — ongoing - [DAML Compiler] Support for incremental builds in ``daml build`` using the ``--incremental=yes`` flag. This is still experimental and disabled by default but will become enabled by default in the future. On large codebases, this can significantly improve compile times and reduce memory usage. +- [DAML Compiler] Support for data dependencies on packages compiled with an older SDK + (experimental). To import data dependencies, list the packages under the ``data-dependencies`` + stanza in the project's daml.yaml file. - [JSON API - Experimental] Fix to support Archive choice. See issue #3219 - [Sandbox] Add the option to start the sandbox with JWT based authentication. See `issue #3363 `__. - [Sandbox] Fixed a bug in the SQL backend that caused the database to be flooded with requests when streaming out transactions.