gleam-lang / gleam

⭐️ A friendly language for building type-safe, scalable systems!
https://gleam.run
Apache License 2.0
17.49k stars 726 forks source link

Compiler does not properly delete native FFI src code from build output if the src has been deleted #2740

Open Acepie opened 6 months ago

Acepie commented 6 months ago

See https://github.com/gleam-lang/gleam/issues/1970 for more context. If I create a method with FFI like the externals example from the tour and run the code in a new project

import gleam/io

// A type with no Gleam constructors
pub type DateTime

// An external function that creates an instance of the type
@external(javascript, "./my_package_ffi.mjs", "now")
fn now() -> DateTime

// The `now` function in `./my_package_ffi.mjs` looks like this:
// export function now() {
//   return new Date();
// }

pub fn main() {
  io.debug(now())
}

gleam run

Then it runs as expected. If I then delete ./my_package_ffi.mjs from the src directory and then do another run, it continues to run. Despite the original src no longer being present. Only after a gleam clean does the run fail with a module not found error like expected. This is the case with both erlang and javascript. I believe this is because the compiler is simply doing a raw copy of the src files that have changed but is not checking if there are build files that should not be present so the old copy is still present.

lpil commented 6 months ago

Aye. Duplicate of https://github.com/gleam-lang/gleam/issues/1970

lpil commented 1 month ago

Splitting it out to have generate the non-generated be different.