Skip to content

Commit

Permalink
feat: add motoko:compiler ICP custom section with version info (#3091)
Browse files Browse the repository at this point in the history
* version is report as UTF8 release or, if unavailable, git revision, matching moc --version.
* section defaults to private.
  • Loading branch information
crusso authored Jan 31, 2022
1 parent d1fef02 commit ba3aa39
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* motoko (`moc`)

* Emit new ICP metadata custom section 'motoko:compiler' with compiler release or revision in UTF8 (e.g. "0.6.21"). Default is `icp:private` (#3091).
* Generalized `import` supporting pattern matching and selective field imports (#3076).
* Fix: insert critical overflow checks preventing rare heap corruptions
in out-of-memory allocation and stable variable serialization (#3077).
Expand Down
2 changes: 1 addition & 1 deletion doc/modules/language-guide/pages/compiler-ref.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ You can use the following options with the `+moc+` command.

|`+--package <package-name> <package-path>+` |Specifies a package-name package-path pair, separated by a space.

|`+--public-metadata <name>+` |Emit icp custom section <name> (candid:args or candid:service or motoko:stable-types) as `public` (default is `private`)
|`+--public-metadata <name>+` |Emit icp custom section <name> (candid:args or candid:service or motoko:stable-types or motoko:compiler) as `public` (default is `private`)

|`+--print-deps+` |Prints the dependencies for a given source file.

Expand Down
3 changes: 3 additions & 0 deletions src/codegen/compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9091,6 +9091,9 @@ and conclude_module env start_fi_o =
motoko = {
labels = E.get_labs env;
stable_types = !(env.E.stable_types);
compiler = Some
(List.mem "motoko:compiler" !Flags.public_metadata_names,
Lib.Option.get Source_id.release Source_id.id)
};
candid = {
args = !(env.E.args);
Expand Down
3 changes: 2 additions & 1 deletion src/exes/moc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ let idl = ref false
let valid_metadata_names =
["candid:args";
"candid:service";
"motoko:stable-types"]
"motoko:stable-types";
"motoko:compiler"]

let argspec = [
"-c", Arg.Unit (set_mode Compile), " compile programs to WebAssembly";
Expand Down
2 changes: 2 additions & 0 deletions src/wasm-exts/customModule.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type dylink_section = {
type motoko_sections = {
labels : string list;
stable_types : (bool * string) option;
compiler : (bool * string) option;
}

type candid_sections = {
Expand All @@ -51,6 +52,7 @@ type candid_sections = {
let empty_motoko_sections = {
labels = [];
stable_types = None;
compiler = None;
}

let empty_candid_sections = {
Expand Down
3 changes: 2 additions & 1 deletion src/wasm-exts/customModuleDecode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,8 @@ let utf8 sec_end s =

let motoko_sections s =
let stable_types = icp_custom_section "motoko:stable-types" utf8 None s in
custom_section is_motoko motoko_section_content { empty_motoko_sections with stable_types} s
let compiler = icp_custom_section "motoko:compiler" utf8 None s in
custom_section is_motoko motoko_section_content { empty_motoko_sections with stable_types; compiler} s

(* Candid sections *)

Expand Down
1 change: 1 addition & 0 deletions src/wasm-exts/customModuleEncode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@ let encode (em : extended_module) =

let motoko_sections motoko =
icp_custom_section "motoko:stable-types" utf8 motoko.stable_types;
icp_custom_section "motoko:compiler" utf8 motoko.compiler;
custom_section "motoko" motoko_section_body motoko.labels (motoko.labels <> []) (* TODO: make an icp_section *)

let candid_sections candid =
Expand Down

0 comments on commit ba3aa39

Please sign in to comment.