From 18f9d051c8c7c703ffaa1e677f6e3b9f4b34dcef Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 19 Feb 2026 18:03:17 +0300 Subject: [PATCH 1/9] Delete `gleam@@compile.erl` after compilation --- compiler-cli/src/beam_compiler.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/compiler-cli/src/beam_compiler.rs b/compiler-cli/src/beam_compiler.rs index 79ef4e49de5..a2f54215bc5 100644 --- a/compiler-cli/src/beam_compiler.rs +++ b/compiler-cli/src/beam_compiler.rs @@ -66,6 +66,11 @@ impl BeamCompiler { let mut buf = String::new(); let mut accumulated_modules: Vec = Vec::new(); while let (Ok(_), Ok(None)) = (inner.stdout.read_line(&mut buf), inner.process.try_wait()) { + let escript_path = get_escript_path(out); + + // Delete unnecessary after compilation escript file + io.delete_file(&escript_path)?; + match buf.trim() { "gleam-compile-result-ok" => { // Return Ok with the accumulated modules @@ -103,9 +108,7 @@ impl BeamCompiler { io: &IO, out: &Utf8Path, ) -> Result { - let escript_path = out - .join(paths::ARTEFACT_DIRECTORY_NAME) - .join("gleam@@compile.erl"); + let escript_path = get_escript_path(out); let escript_source = std::include_str!("../templates/gleam@@compile.erl"); io.write(&escript_path, escript_source)?; @@ -152,3 +155,8 @@ impl Drop for BeamCompiler { fn escape_path>(path: T) -> String { path.as_ref().replace("\\", "\\\\") } + +fn get_escript_path(out: &Utf8Path) -> Utf8PathBuf { + out.join(paths::ARTEFACT_DIRECTORY_NAME) + .join("gleam@@compile.erl") +} From b7f15573baa6129d39fedc4727c03dba1bf39729 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 19 Feb 2026 18:23:49 +0300 Subject: [PATCH 2/9] test: write integration test + add it to makefiles --- test/delete_escript_after_compilation/.gitignore | 1 + test/delete_escript_after_compilation/Makefile | 10 ++++++++++ test/delete_escript_after_compilation/gleam.toml | 4 ++++ test/delete_escript_after_compilation/manifest.toml | 7 +++++++ .../src/delete_escript_after_compilation.gleam | 3 +++ 5 files changed, 25 insertions(+) create mode 100644 test/delete_escript_after_compilation/.gitignore create mode 100644 test/delete_escript_after_compilation/Makefile create mode 100644 test/delete_escript_after_compilation/gleam.toml create mode 100644 test/delete_escript_after_compilation/manifest.toml create mode 100644 test/delete_escript_after_compilation/src/delete_escript_after_compilation.gleam diff --git a/test/delete_escript_after_compilation/.gitignore b/test/delete_escript_after_compilation/.gitignore new file mode 100644 index 00000000000..796b96d1c40 --- /dev/null +++ b/test/delete_escript_after_compilation/.gitignore @@ -0,0 +1 @@ +/build diff --git a/test/delete_escript_after_compilation/Makefile b/test/delete_escript_after_compilation/Makefile new file mode 100644 index 00000000000..196687054b4 --- /dev/null +++ b/test/delete_escript_after_compilation/Makefile @@ -0,0 +1,10 @@ +# TODO: migrate to Rust shell commands, possibly ./compiler-cli/src/fs/tests.rs +test: + # clean build directory && build the project + cargo run clean && cargo run build + + # fail if file exists + @if find build -name "gleam@@compile.erl" | grep -q .; then \ + echo "Error: gleam@@compile.erl file(s) still exist after build"; \ + exit 1; \ + fi diff --git a/test/delete_escript_after_compilation/gleam.toml b/test/delete_escript_after_compilation/gleam.toml new file mode 100644 index 00000000000..d5f7adc95ed --- /dev/null +++ b/test/delete_escript_after_compilation/gleam.toml @@ -0,0 +1,4 @@ +name = "delete_escript_after_compilation" +version = "1.0.0" +description = "Test project to delete escript compile file after compilation" +licences = ["Apache-2.0"] diff --git a/test/delete_escript_after_compilation/manifest.toml b/test/delete_escript_after_compilation/manifest.toml new file mode 100644 index 00000000000..c5d779a3f81 --- /dev/null +++ b/test/delete_escript_after_compilation/manifest.toml @@ -0,0 +1,7 @@ +# This file was generated by Gleam +# You typically do not need to edit this file + +packages = [ +] + +[requirements] diff --git a/test/delete_escript_after_compilation/src/delete_escript_after_compilation.gleam b/test/delete_escript_after_compilation/src/delete_escript_after_compilation.gleam new file mode 100644 index 00000000000..86ee73c178c --- /dev/null +++ b/test/delete_escript_after_compilation/src/delete_escript_after_compilation.gleam @@ -0,0 +1,3 @@ +pub fn something() { + "Just a thing to export" +} From 9d481b9796fac304c3af7eb1032863b84f16f2e5 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 19 Feb 2026 18:31:09 +0300 Subject: [PATCH 3/9] ci: run newly craeted test as well Forgot to commit it --- .github/workflows/ci.yaml | 6 +++++- Makefile | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 312bd695be8..96b88fb3093 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -481,7 +481,11 @@ jobs: run: make test working-directory: ./test/hextarball - - name: test/running_modules + - name: Test deletion of escript compile file after compilation + run: make test + working-directory: ./test/delete_escript_after_compilation + + - name: Test running modules run: make test-all working-directory: ./test/running_modules diff --git a/Makefile b/Makefile index 7f4ff229114..a3b5624862b 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,7 @@ test: ## Run the compiler unit tests cd test/project_javascript && cargo run clean && cargo run check && cargo run test cd test/project_deno && cargo run clean && cargo run check && cargo run test cd test/hextarball && make test + cd test/delete_escript_after_compilation && make test cd test/running_modules && make test cd test/subdir_ffi && make @@ -59,6 +60,10 @@ test-watch: ## Run compiler tests when files change export-hex-tarball-test: ## Run `gleam export hex-tarball` and verify it is created cd test/hextarball && make test +.PHONY: export-hex-tarball-test +export-hex-tarball-test: ## Build project and check that escript compile file is deleted + cd test/delete_escript_after_compilation && make test + .PHONY: benchmark benchmark: ## Run the benchmarks cd benchmark/list && make From 0450814b72c449dbd3ded3529871c16ccbda6e9b Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 26 Feb 2026 06:58:49 +0300 Subject: [PATCH 4/9] chore: clarify comment --- compiler-cli/src/beam_compiler.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler-cli/src/beam_compiler.rs b/compiler-cli/src/beam_compiler.rs index a2f54215bc5..6526444aa71 100644 --- a/compiler-cli/src/beam_compiler.rs +++ b/compiler-cli/src/beam_compiler.rs @@ -68,7 +68,7 @@ impl BeamCompiler { while let (Ok(_), Ok(None)) = (inner.stdout.read_line(&mut buf), inner.process.try_wait()) { let escript_path = get_escript_path(out); - // Delete unnecessary after compilation escript file + // Delete escript file, which is unnecessary after compilation io.delete_file(&escript_path)?; match buf.trim() { @@ -96,7 +96,7 @@ impl BeamCompiler { buf.clear() } - // if we get here, stdout got closed before we got an "ok" or "err". + // If we get here, stdout got closed before we got an "ok" or "err". Err(Error::ShellCommand { program: "escript".into(), reason: ShellCommandFailureReason::Unknown, From 999ff01b65cb30ccb9bdd013a36786ba6a30c79a Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 26 Feb 2026 07:30:12 +0300 Subject: [PATCH 5/9] test: use `test.sh` convention for integration test --- .github/workflows/ci.yaml | 2 +- Makefile | 5 ---- test/delete_escript_after_compilation/test.sh | 26 +++++++++++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 test/delete_escript_after_compilation/test.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 96b88fb3093..33d75e903d7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -482,7 +482,7 @@ jobs: working-directory: ./test/hextarball - name: Test deletion of escript compile file after compilation - run: make test + run: ./test.sh working-directory: ./test/delete_escript_after_compilation - name: Test running modules diff --git a/Makefile b/Makefile index a3b5624862b..7f4ff229114 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,6 @@ test: ## Run the compiler unit tests cd test/project_javascript && cargo run clean && cargo run check && cargo run test cd test/project_deno && cargo run clean && cargo run check && cargo run test cd test/hextarball && make test - cd test/delete_escript_after_compilation && make test cd test/running_modules && make test cd test/subdir_ffi && make @@ -60,10 +59,6 @@ test-watch: ## Run compiler tests when files change export-hex-tarball-test: ## Run `gleam export hex-tarball` and verify it is created cd test/hextarball && make test -.PHONY: export-hex-tarball-test -export-hex-tarball-test: ## Build project and check that escript compile file is deleted - cd test/delete_escript_after_compilation && make test - .PHONY: benchmark benchmark: ## Run the benchmarks cd benchmark/list && make diff --git a/test/delete_escript_after_compilation/test.sh b/test/delete_escript_after_compilation/test.sh new file mode 100644 index 00000000000..58c14b8258c --- /dev/null +++ b/test/delete_escript_after_compilation/test.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +set -eu + +GLEAM_COMMAND=${GLEAM_COMMAND:-"cargo run --quiet --"} + +g() { + echo "Running: $GLEAM_COMMAND $@" + $GLEAM_COMMAND "$@" +} + +echo Resetting the build directory to get to a known state +rm -rf build + +echo Building the project +g build + +echo Searching for leftover gleam@@compile.erl files +if find build -name "gleam@@compile.erl" | grep -q .; then + echo "ERROR: gleam@@compile.erl file(s) still exist after build" + exit 1 +fi + +echo +echo None found! Success! +echo From 1171d53d5d4a1100015288cbaffd4438d1a6c4e1 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 26 Feb 2026 07:31:18 +0300 Subject: [PATCH 6/9] refactor: move function to get `escript` path to the `paths` module --- compiler-cli/src/beam_compiler.rs | 9 ++------- compiler-core/src/paths.rs | 4 ++++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/compiler-cli/src/beam_compiler.rs b/compiler-cli/src/beam_compiler.rs index 6526444aa71..f6d58b25161 100644 --- a/compiler-cli/src/beam_compiler.rs +++ b/compiler-cli/src/beam_compiler.rs @@ -66,7 +66,7 @@ impl BeamCompiler { let mut buf = String::new(); let mut accumulated_modules: Vec = Vec::new(); while let (Ok(_), Ok(None)) = (inner.stdout.read_line(&mut buf), inner.process.try_wait()) { - let escript_path = get_escript_path(out); + let escript_path = paths::compilation_escript_path(out); // Delete escript file, which is unnecessary after compilation io.delete_file(&escript_path)?; @@ -108,7 +108,7 @@ impl BeamCompiler { io: &IO, out: &Utf8Path, ) -> Result { - let escript_path = get_escript_path(out); + let escript_path = paths::compilation_escript_path(out); let escript_source = std::include_str!("../templates/gleam@@compile.erl"); io.write(&escript_path, escript_source)?; @@ -155,8 +155,3 @@ impl Drop for BeamCompiler { fn escape_path>(path: T) -> String { path.as_ref().replace("\\", "\\\\") } - -fn get_escript_path(out: &Utf8Path) -> Utf8PathBuf { - out.join(paths::ARTEFACT_DIRECTORY_NAME) - .join("gleam@@compile.erl") -} diff --git a/compiler-core/src/paths.rs b/compiler-core/src/paths.rs index ad66dbecb48..d74024b1ed0 100644 --- a/compiler-core/src/paths.rs +++ b/compiler-core/src/paths.rs @@ -133,6 +133,10 @@ impl ProjectPaths { } } +pub fn compilation_escript_path(out: &Utf8Path) -> Utf8PathBuf { + out.join(ARTEFACT_DIRECTORY_NAME).join("gleam@@compile.erl") +} + pub fn global_package_cache_package_tarball(checksum: &Base16Checksum) -> Utf8PathBuf { global_packages_cache().join(format!("{}.tar", checksum.to_string())) } From 358e0c108eec01e3afa9604d12b894f14304f142 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 26 Feb 2026 07:44:17 +0300 Subject: [PATCH 7/9] chore(test): remove unused Makefile --- test/delete_escript_after_compilation/Makefile | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 test/delete_escript_after_compilation/Makefile diff --git a/test/delete_escript_after_compilation/Makefile b/test/delete_escript_after_compilation/Makefile deleted file mode 100644 index 196687054b4..00000000000 --- a/test/delete_escript_after_compilation/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -# TODO: migrate to Rust shell commands, possibly ./compiler-cli/src/fs/tests.rs -test: - # clean build directory && build the project - cargo run clean && cargo run build - - # fail if file exists - @if find build -name "gleam@@compile.erl" | grep -q .; then \ - echo "Error: gleam@@compile.erl file(s) still exist after build"; \ - exit 1; \ - fi From 7366cba4fc2644d28ea9d115e9a95fea977622ea Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 26 Feb 2026 07:57:09 +0300 Subject: [PATCH 8/9] chore: make script executable --- test/delete_escript_after_compilation/test.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 test/delete_escript_after_compilation/test.sh diff --git a/test/delete_escript_after_compilation/test.sh b/test/delete_escript_after_compilation/test.sh old mode 100644 new mode 100755 From 18062c175d72bce84e50d14bdb6f241813eb5a9e Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 27 Feb 2026 10:56:02 +0300 Subject: [PATCH 9/9] chore: changelog entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78b35b9839f..2d41d9ea065 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,10 @@ an empty README. ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) +- The build tool now deletes `escript` file after compilation, which is + unnecessary once the build is completed. + ([Andrey Kozhev](https://github.com/ankddev)) + ### Language server - The language server now allows extracting the start of a pipeline into a