gracelang / minigrace

Self-hosting compiler for the Grace programming language
39 stars 22 forks source link

Build process fails when using concurrent make #162

Open nzentzis opened 8 years ago

nzentzis commented 8 years ago

From a clean copy of the repository, attempting to build the compiler using make -j N for any N>1 fails with the error:

make: *** No rule to make target 'l1/unixFilePath.gso', needed by 'xmodule.gct'.  Stop.
make: *** Waiting for unfinished jobs....
unixFilePath.grace[138:21-29]: Syntax error: unknown variable or method 'emptyList'. This may be a spelling mistake or an attempt to access a variable in another scope.
  137:     // by colons, into a List of items.  Ensures that each item ends with /
  138:     def locations = emptyList
---------------------------^^^^^^^^^
Makefile:286: recipe for target 'l1/unixFilePath.gct' failed
make: *** [l1/unixFilePath.gct] Error 

For comparison, when I force the build process to run synchronously using make -j 1, it compiles and tests fine. It seems like there's a missing dependency between build targets, but I'm not sure what exactly it is.

apblack commented 8 years ago

Thanks for listing this issue. Here is what's going on (as well as I understand it).

When a file x.grace is compiled with --target c, three files are produced: x.gct (containing the inter-module linkage tables), x.gcn (containing the statically-linkable object code), and x.gso (containing the dynamically-linkable object code). I've not been able to figure out how to teach make about this parallel build behaviour. The documentation that I have read suggests that one can use fake pattern rules to describe parallel build behaviour, but using gnu Make on the Mac, I could not get this to work.

If I add in all of the dependencies, then make starts building x.grace twice in two parallel threads, once because x.gcn is needed on one target, and a second time because x.gct is needed by a second target. This, of course, is disasterous, and results in file corruption.

If you can figure out how to tell make about the build behaviour, then we can probably add the missing dependencies without too much problem. Right now the Makefile contains dependencies on the .gct files only (IIRC), because building the .gct file will force the building of the .gso and .gcn files along the way.