summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-09-04 16:27:53 +0200
committerLaurenz <laurmaedje@gmail.com>2023-09-04 16:29:57 +0200
commit2f672b4e2ebb040896c7a6af5104f72b075565e0 (patch)
tree21bc7f1a4b22a898fa1e8c23b09cd08051690a4b /crates
parent68a25f497ec9137fc2965aaeff5a49501ede552e (diff)
Allow packages to specify their minimum compiler version
Diffstat (limited to 'crates')
-rw-r--r--crates/typst-syntax/src/file.rs11
-rw-r--r--crates/typst/src/eval/mod.rs12
2 files changed, 23 insertions, 0 deletions
diff --git a/crates/typst-syntax/src/file.rs b/crates/typst-syntax/src/file.rs
index f5fa493b..8f07cc92 100644
--- a/crates/typst-syntax/src/file.rs
+++ b/crates/typst-syntax/src/file.rs
@@ -265,6 +265,17 @@ pub struct PackageVersion {
pub patch: u32,
}
+impl PackageVersion {
+ /// The current compiler version.
+ pub fn compiler() -> Self {
+ Self {
+ major: env!("CARGO_PKG_VERSION_MAJOR").parse().unwrap(),
+ minor: env!("CARGO_PKG_VERSION_MINOR").parse().unwrap(),
+ patch: env!("CARGO_PKG_VERSION_PATCH").parse().unwrap(),
+ }
+ }
+}
+
impl FromStr for PackageVersion {
type Err = EcoString;
diff --git a/crates/typst/src/eval/mod.rs b/crates/typst/src/eval/mod.rs
index 3f0e4577..fffedc9f 100644
--- a/crates/typst/src/eval/mod.rs
+++ b/crates/typst/src/eval/mod.rs
@@ -1920,6 +1920,16 @@ impl PackageManifest {
);
}
+ if let Some(compiler) = self.package.compiler {
+ let current = PackageVersion::compiler();
+ if current < compiler {
+ bail!(
+ "package requires typst {compiler} or newer \
+ (current version is {current})"
+ );
+ }
+ }
+
Ok(())
}
}
@@ -1935,6 +1945,8 @@ struct PackageInfo {
version: PackageVersion,
/// The path of the entrypoint into the package.
entrypoint: EcoString,
+ /// The minimum required compiler version for the package.
+ compiler: Option<PackageVersion>,
}
impl Eval for ast::LoopBreak<'_> {