andyarvanitis / purescript-native

A native compiler backend for PureScript (via C++ or Golang)
http://purescript.org
Other
632 stars 40 forks source link

Support spago alternate entry point option #63

Open joprice opened 4 years ago

joprice commented 4 years ago

When providing an argument to the -m flag to spago run such as spago run -m Parser, I get following error

getModificationTime:getFileStatus: does not exist (No such file or directory)

This seems to do with how the module name "Main" is reserved https://github.com/andyarvanitis/purescript-native/pull/60/files#diff-bbb636505a367cfa1f620353cba3c3e3R452. Main is compiled in package main, while libraries intended to be imported and not run are compiled with a package named after the module path.

In order to use the same module as a library and make it runnable, it seems that modules that define a main of the right type should have a wrapper module generated with package main and a library module with the normal module path name. The main module can simply import the library package and call the main function in the package, so that the main function is still visible to consumers of the library as a normal main as it is in purescript js.

A workaround for this is to define multiple spago projects as described here https://github.com/purescript/spago#monorepo, one with the shared code, and one for each binary. This mirrors go's restriction of having one main per folder.