diff --git a/adl/stdlib/adlc/packaging.adl b/adl/stdlib/adlc/packaging.adl new file mode 100644 index 00000000..f8e1846a --- /dev/null +++ b/adl/stdlib/adlc/packaging.adl @@ -0,0 +1,99 @@ +// This is based on Golang's modules and workspace. +// e.g. see https://go.dev/ref/mod#workspaces + +module adlc.packaging { + +/// Expected to live in a file named `adl.work.json` +struct AdlWorkspace { + /// Version + String adlc; + AdlPackageRefs use; +}; + +type AdlPackageRefs = Vector; + +struct AdlPackageRef { + /// must be a path to a directory directly under the folder containing the `adl.work.json` file. + String root; + Vector genOptions; +}; + +union GenOptions { + TypescriptGenOptions tsgen; +}; + + +struct TypescriptGenOptions { + ReferenceableScopeOption referenceable = "local"; + // Vector<> searchDir; + OutputOpts outputs; + Bool includeRuntime; + Nullable runtimeDir; + Bool generate_transitive; + Bool include_resolver; + TsStyle ts_style = "tsc"; + ModuleSrc modules; + Bool capitalize_branch_names_in_types; + Bool capitalize_type_names; +}; + +struct OutputOpts { + String outputDir; + Nullable manifest = null; +}; + +union TsStyle { + Void tsc; + Void deno; +}; + +union ModuleSrc { + Void all; + Vector modules; +}; + +union ReferenceableScopeOption { + /// Generated code will only be referred internal to the repo + Void local; + /// Generated code can be published via a package manager (e.g. npm) + Void remote; +}; + +/// Expected to live in a file named `adl.pkg.json` +struct AdlPackage { + PackageDirective pkg; + /// Version + String adlc; + Vector requires = []; + Vector excludes = []; + Vector replaces = []; + Vector retracts = []; +}; + +struct PackageDirective { + String path; + Nullable repo = null; +}; + +struct Require { + String path; + String version; + Bool indirect = false; +}; + +struct Exclude { + String path; + String version; +}; + +struct Replace { + String path; + Nullable version; +}; + +struct Retract { + String version; + Nullable comment = null; +}; + +}; \ No newline at end of file diff --git a/rust/compiler/genadl.sh b/rust/compiler/genadl.sh index bb54cec1..40fe4c49 100755 --- a/rust/compiler/genadl.sh +++ b/rust/compiler/genadl.sh @@ -14,7 +14,7 @@ adlc rust \ --runtime-module adlrt \ --include-rt \ --searchdir $ADL_STDLIB_DIR \ - $ADL_STDLIB_DIR/sys/adlast2.adl + $ADL_STDLIB_DIR/sys/adlast2.adl $ADL_STDLIB_DIR/adlc/packaging.adl ADL_DIR=../../adl diff --git a/rust/compiler/src/adlgen/adlc/mod.rs b/rust/compiler/src/adlgen/adlc/mod.rs index a1059337..74795cd9 100644 --- a/rust/compiler/src/adlgen/adlc/mod.rs +++ b/rust/compiler/src/adlgen/adlc/mod.rs @@ -1 +1,2 @@ -pub mod config; \ No newline at end of file +pub mod config; +pub mod packaging; \ No newline at end of file diff --git a/rust/compiler/src/adlgen/adlc/packaging.rs b/rust/compiler/src/adlgen/adlc/packaging.rs new file mode 100644 index 00000000..70e56e82 --- /dev/null +++ b/rust/compiler/src/adlgen/adlc/packaging.rs @@ -0,0 +1,314 @@ +// @generated from adl module adlc.packaging + +use serde::Deserialize; +use serde::Serialize; + +/** + * Expected to live in a file named `adl.work.json` + */ +#[derive(Clone,Debug,Deserialize,Eq,Hash,PartialEq,Serialize)] +pub struct AdlWorkspace { + /** + * Version + */ + pub adlc: String, + + #[serde(rename="use")] + pub r#use: AdlPackageRefs, +} + +impl AdlWorkspace { + pub fn new(adlc: String, r#use: AdlPackageRefs) -> AdlWorkspace { + AdlWorkspace { + adlc: adlc, + r#use: r#use, + } + } +} + +pub type AdlPackageRefs = Vec; + +#[derive(Clone,Debug,Deserialize,Eq,Hash,PartialEq,Serialize)] +pub struct AdlPackageRef { + /** + * must be a path to a directory directly under the folder containing the `adl.work.json` file. + */ + pub root: String, + + #[serde(rename="genOptions")] + pub gen_options: Vec, +} + +impl AdlPackageRef { + pub fn new(root: String, gen_options: Vec) -> AdlPackageRef { + AdlPackageRef { + root: root, + gen_options: gen_options, + } + } +} + +#[derive(Clone,Debug,Deserialize,Eq,Hash,PartialEq,Serialize)] +pub enum GenOptions { + #[serde(rename="tsgen")] + Tsgen(TypescriptGenOptions), +} + +#[derive(Clone,Debug,Deserialize,Eq,Hash,PartialEq,Serialize)] +pub struct TypescriptGenOptions { + #[serde(default="TypescriptGenOptions::def_referenceable")] + pub referenceable: ReferenceableScopeOption, + + pub outputs: OutputOpts, + + #[serde(rename="includeRuntime")] + pub include_runtime: bool, + + #[serde(rename="runtimeDir")] + pub runtime_dir: Option, + + pub generate_transitive: bool, + + pub include_resolver: bool, + + #[serde(default="TypescriptGenOptions::def_ts_style")] + pub ts_style: TsStyle, + + pub modules: ModuleSrc, + + pub capitalize_branch_names_in_types: bool, + + pub capitalize_type_names: bool, +} + +impl TypescriptGenOptions { + pub fn new(outputs: OutputOpts, include_runtime: bool, runtime_dir: Option, generate_transitive: bool, include_resolver: bool, modules: ModuleSrc, capitalize_branch_names_in_types: bool, capitalize_type_names: bool) -> TypescriptGenOptions { + TypescriptGenOptions { + referenceable: TypescriptGenOptions::def_referenceable(), + outputs: outputs, + include_runtime: include_runtime, + runtime_dir: runtime_dir, + generate_transitive: generate_transitive, + include_resolver: include_resolver, + ts_style: TypescriptGenOptions::def_ts_style(), + modules: modules, + capitalize_branch_names_in_types: capitalize_branch_names_in_types, + capitalize_type_names: capitalize_type_names, + } + } + + pub fn def_referenceable() -> ReferenceableScopeOption { + ReferenceableScopeOption::Local + } + + pub fn def_ts_style() -> TsStyle { + TsStyle::Tsc + } +} + +#[derive(Clone,Debug,Deserialize,Eq,Hash,PartialEq,Serialize)] +pub struct OutputOpts { + #[serde(rename="outputDir")] + pub output_dir: String, + + #[serde(default="OutputOpts::def_manifest")] + pub manifest: Option, +} + +impl OutputOpts { + pub fn new(output_dir: String) -> OutputOpts { + OutputOpts { + output_dir: output_dir, + manifest: OutputOpts::def_manifest(), + } + } + + pub fn def_manifest() -> Option { + None + } +} + +#[derive(Clone,Debug,Deserialize,Eq,Hash,PartialEq,Serialize)] +pub enum TsStyle { + #[serde(rename="tsc")] + Tsc, + + #[serde(rename="deno")] + Deno, +} + +#[derive(Clone,Debug,Deserialize,Eq,Hash,PartialEq,Serialize)] +pub enum ModuleSrc { + #[serde(rename="all")] + All, + + #[serde(rename="modules")] + Modules(Vec), +} + +#[derive(Clone,Debug,Deserialize,Eq,Hash,PartialEq,Serialize)] +pub enum ReferenceableScopeOption { + /** + * Generated code will only be referred internal to the repo + */ + #[serde(rename="local")] + Local, + + /** + * Generated code can be published via a package manager (e.g. npm) + */ + #[serde(rename="remote")] + Remote, +} + +/** + * Expected to live in a file named `adl.pkg.json` + */ +#[derive(Clone,Debug,Deserialize,Eq,Hash,PartialEq,Serialize)] +pub struct AdlPackage { + pub pkg: PackageDirective, + + /** + * Version + */ + pub adlc: String, + + #[serde(default="AdlPackage::def_requires")] + pub requires: Vec, + + #[serde(default="AdlPackage::def_excludes")] + pub excludes: Vec, + + #[serde(default="AdlPackage::def_replaces")] + pub replaces: Vec, + + #[serde(default="AdlPackage::def_retracts")] + pub retracts: Vec, +} + +impl AdlPackage { + pub fn new(pkg: PackageDirective, adlc: String) -> AdlPackage { + AdlPackage { + pkg: pkg, + adlc: adlc, + requires: AdlPackage::def_requires(), + excludes: AdlPackage::def_excludes(), + replaces: AdlPackage::def_replaces(), + retracts: AdlPackage::def_retracts(), + } + } + + pub fn def_requires() -> Vec { + vec![] + } + + pub fn def_excludes() -> Vec { + vec![] + } + + pub fn def_replaces() -> Vec { + vec![] + } + + pub fn def_retracts() -> Vec { + vec![] + } +} + +#[derive(Clone,Debug,Deserialize,Eq,Hash,PartialEq,Serialize)] +pub struct PackageDirective { + pub path: String, + + #[serde(default="PackageDirective::def_repo")] + pub repo: Option, +} + +impl PackageDirective { + pub fn new(path: String) -> PackageDirective { + PackageDirective { + path: path, + repo: PackageDirective::def_repo(), + } + } + + pub fn def_repo() -> Option { + None + } +} + +#[derive(Clone,Debug,Deserialize,Eq,Hash,PartialEq,Serialize)] +pub struct Require { + pub path: String, + + pub version: String, + + #[serde(default="Require::def_indirect")] + pub indirect: bool, +} + +impl Require { + pub fn new(path: String, version: String) -> Require { + Require { + path: path, + version: version, + indirect: Require::def_indirect(), + } + } + + pub fn def_indirect() -> bool { + false + } +} + +#[derive(Clone,Debug,Deserialize,Eq,Hash,PartialEq,Serialize)] +pub struct Exclude { + pub path: String, + + pub version: String, +} + +impl Exclude { + pub fn new(path: String, version: String) -> Exclude { + Exclude { + path: path, + version: version, + } + } +} + +#[derive(Clone,Debug,Deserialize,Eq,Hash,PartialEq,Serialize)] +pub struct Replace { + pub path: String, + + pub version: Option, +} + +impl Replace { + pub fn new(path: String, version: Option) -> Replace { + Replace { + path: path, + version: version, + } + } +} + +#[derive(Clone,Debug,Deserialize,Eq,Hash,PartialEq,Serialize)] +pub struct Retract { + pub version: String, + + #[serde(default="Retract::def_comment")] + pub comment: Option, +} + +impl Retract { + pub fn new(version: String) -> Retract { + Retract { + version: version, + comment: Retract::def_comment(), + } + } + + pub fn def_comment() -> Option { + None + } +} diff --git a/rust/compiler/src/adlgen_dev/testing_table.rs b/rust/compiler/src/adlgen_dev/testing_table.rs index 56017066..0b1e1631 100644 --- a/rust/compiler/src/adlgen_dev/testing_table.rs +++ b/rust/compiler/src/adlgen_dev/testing_table.rs @@ -12,6 +12,9 @@ pub struct TestFileMetaData { #[serde(default="TestFileMetaData::def_lib_paths")] pub lib_paths: Vec, + /** + * If null then 'build/adlc_out/$module_root' is used + */ #[serde(default="TestFileMetaData::def_output_dir")] pub output_dir: Option,