Skip to content

Commit 871f6d8

Browse files
committed
Add erlang.application_start_argument configuration
1 parent efe51ee commit 871f6d8

12 files changed

+100
-9
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,12 @@
226226

227227
([sobolevn](https://github.com/sobolevn))
228228

229+
- The `erlang.application_start_argument` parameter has been added to
230+
`gleam.toml`. This is a string containing an Erlang term that will be written
231+
into the package's Erlang `.app` file if `erlang.application_start_module`
232+
has been set, replacing the default argument of `[]`.
233+
([Louis Pilfold](https://github.com/lpil))
234+
229235
- Generated code for the JavaScript target now includes a public API which can
230236
be used for FFI interacting with Gleam custom types. For example, if you have
231237
this Gleam code:

compiler-cli/src/dependencies/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,7 @@ fn package_config(
11801180
links: vec![],
11811181
erlang: ErlangConfig {
11821182
application_start_module: None,
1183+
application_start_argument: None,
11831184
extra_applications: vec![],
11841185
},
11851186
javascript: JavaScriptConfig {

compiler-core/src/codegen.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,17 @@ impl<'a> ErlangApp<'a> {
104104

105105
let path = self.output_directory.join(format!("{}.app", &config.name));
106106

107-
let start_module = config
108-
.erlang
109-
.application_start_module
110-
.as_ref()
111-
.map(|module| tuple("mod", &format!("{{'{}', []}}", module_erlang_name(module))))
112-
.unwrap_or_default();
107+
let start_module = match config.erlang.application_start_module.as_ref() {
108+
None => "".into(),
109+
Some(module) => {
110+
let module = module_erlang_name(module);
111+
let argument = match config.erlang.application_start_argument.as_ref() {
112+
Some(argument) => argument.as_str(),
113+
None => "[]",
114+
};
115+
tuple("mod", &format!("{{'{module}', {argument}}}"))
116+
}
117+
};
113118

114119
let modules = modules
115120
.iter()

compiler-core/src/config.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,8 +708,16 @@ impl Default for PackageConfig {
708708

709709
#[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Default, Clone)]
710710
pub struct ErlangConfig {
711+
/// An module that can be set in the `.app` file as the entrypoint for a stateful application
712+
/// that defines a singleton supervision tree.
713+
/// Erlang syntax.
711714
#[serde(default)]
712715
pub application_start_module: Option<EcoString>,
716+
/// The argument for the start module start function. If not set then `[]` is used as the
717+
/// default argument.
718+
/// Erlang syntax.
719+
#[serde(default)]
720+
pub application_start_argument: Option<EcoString>,
713721
#[serde(default)]
714722
pub extra_applications: Vec<EcoString>,
715723
}

compiler-core/src/snapshots/gleam_core__config__barebones_package_config_to_json.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
source: compiler-core/src/config.rs
3-
assertion_line: 1116
3+
assertion_line: 1187
44
expression: output
55
snapshot_kind: text
66
---
@@ -27,6 +27,7 @@ version = "1.0.0"
2727
"links": [],
2828
"erlang": {
2929
"application_start_module": null,
30+
"application_start_argument": null,
3031
"extra_applications": []
3132
},
3233
"javascript": {

compiler-core/src/snapshots/gleam_core__config__package_config_to_json.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
source: compiler-core/src/config.rs
3-
assertion_line: 1106
3+
assertion_line: 1171
44
expression: output
55
snapshot_kind: text
66
---
@@ -90,6 +90,7 @@ allow_read = ["./database.sqlite"]
9090
],
9191
"erlang": {
9292
"application_start_module": "my_app/application",
93+
"application_start_argument": null,
9394
"extra_applications": [
9495
"inets",
9596
"ssl"

compiler-core/src/snapshots/gleam_core__docs__barebones_package_config_to_json.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ version = "1.0.0"
2828
"links": [],
2929
"erlang": {
3030
"application_start_module": null,
31+
"application_start_argument": null,
3132
"extra_applications": []
3233
},
3334
"javascript": {

compiler-core/src/snapshots/gleam_core__docs__package_config_to_json.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
source: compiler-core/src/docs.rs
3-
assertion_line: 765
3+
assertion_line: 769
44
expression: output
55
snapshot_kind: text
66
---
@@ -91,6 +91,7 @@ allow_read = ["./database.sqlite"]
9191
],
9292
"erlang": {
9393
"application_start_module": "my_app/application",
94+
"application_start_argument": null,
9495
"extra_applications": [
9596
"inets",
9697
"ssl"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This config file has a bunch of properties that will be entered into the
2+
# Erlang .app file
3+
4+
name = "my_erlang_application" # <-
5+
version = "0.1.0" # <-
6+
description = "It's very cool" # <-
7+
8+
target = "erlang"
9+
10+
[erlang]
11+
extra_applications = ["inets", "ssl"] # <-
12+
application_start_module = "my_erlang_application_sup" # <-
13+
application_start_argument = "[1, two]" # <-
14+
15+
[dependencies] # <-
16+
gleam_stdlib = "~> 1337.0"
17+
gleam_otp = "~> 1337.0"
18+
19+
[dev-dependencies] # <-
20+
midas = "~> 1337.0"
21+
simple_json = "~> 1337.0"
22+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)