lf-lang / lingua-franca

Intuitive concurrent programming in any language
https://www.lf-lang.org
Other
231 stars 62 forks source link

Deployment with "at" is broken #959

Open edwardalee opened 2 years ago

edwardalee commented 2 years ago

Using the at keyword to deploy federates currently gives a compile error. Example:

target C;
reactor Source(period:time(2 sec)) {
    output y:int;
    reaction(startup) -> y {=
        SET(y, 42);
    =}
}
reactor Destination {
    input x:int;
    reaction(x) {=
        printf("Received %d\n", x->value);
    =}
}
federated reactor Composition at wessel.eecs.berkeley.edu {
    s = new Source() at wessel.eecs.berkeley.edu;
    d = new Destination();
}

Code generator yields this:

/Users/eal/lingua-franca-master/git/lingua-franca/test/C/src-gen/Composition/d/core/platform/lf_linux_support.c:57:12: error: implicit declaration of function 'clock_nanosleep' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    return clock_nanosleep(_LF_CLOCK, 0, (const struct timespec*)&tp, (struct timespec*)&remaining);
           ^
Soroosh129 commented 2 years ago

I think this might have something to do with the fact that the code generator is assuming that the remote machines are Linux, but the code is being compiled on MacOS.

Was this error thrown during the compilation of Destination or Source?

edwardalee commented 2 years ago

The error occurs while compiling the Destination, which is supposed to run on the local Mac. So this looks like a bug in the platform support. It is assuming Linux for all federates. The full compile output is below:

-- Generating done
-- Build files have been written to: /Users/eal/lingua-franca-master/git/lingua-franca/test/C/src-gen/Composition/d/build
--- Current working directory: /Users/eal/lingua-franca-master/git/lingua-franca/test/C/src-gen/Composition/d/build
--- Executing command: bash --login -c cmake --build . --target install --parallel 16 --config Release
[ 33%] Building C object CMakeFiles/Composition_d.dir/core/platform/lf_macos_support.c.o
[ 33%] Building C object CMakeFiles/Composition_d.dir/Composition_d.c.o
[ 50%] Building C object CMakeFiles/Composition_d.dir/ctarget.c.o
[ 66%] Building C object CMakeFiles/Composition_d.dir/core/mixed_radix.c.o
[ 83%] Building C object CMakeFiles/Composition_d.dir/core/platform/lf_linux_support.c.o
/Users/eal/lingua-franca-master/git/lingua-franca/test/C/src-gen/Composition/d/core/platform/lf_linux_support.c:57:12: error: implicit declaration of function 'clock_nanosleep' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    return clock_nanosleep(_LF_CLOCK, 0, (const struct timespec*)&tp, (struct timespec*)&remaining);
           ^
/Users/eal/lingua-franca-master/git/lingua-franca/test/C/src-gen/Composition/d/core/platform/lf_linux_support.c:57:12: note: did you mean 'lf_nanosleep'?
/Users/eal/lingua-franca-master/git/lingua-franca/test/C/src-gen/Composition/d/core/platform/lf_linux_support.c:54:5: note: 'lf_nanosleep' declared here
int lf_nanosleep(instant_t requested_time) {
    ^
1 error generated.
gmake[2]: *** [CMakeFiles/Composition_d.dir/build.make:132: CMakeFiles/Composition_d.dir/core/platform/lf_linux_support.c.o] Error 1
gmake[2]: *** Se espera a que terminen otras tareas....
gmake[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/Composition_d.dir/all] Error 2
gmake: *** [Makefile:136: all] Error 2
ERROR: /Users/eal/lingua-franca-master/git/lingua-franca/test/C/src-gen/Composition/d/core/platform/lf_linux_support.c:57:12: error: implicit declaration of function 'clock_nanosleep' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    return clock_nanosleep(_LF_CLOCK, 0, (const struct timespec*)&tp, (struct timespec*)&remaining);
           ^
/Users/eal/lingua-franca-master/git/lingua-franca/test/C/src-gen/Composition/d/core/platform/lf_linux_support.c:57:12: note: did you mean 'lf_nanosleep'?
/Users/eal/lingua-franca-master/git/lingua-franca/test/C/src-gen/Composition/d/core/platform/lf_linux_support.c:54:5: note: 'lf_nanosleep' declared here
int lf_nanosleep(instant_t requested_time) {
    ^
1 error generated.
gmake[2]: *** [CMakeFiles/Composition_d.dir/build.make:132: CMakeFiles/Composition_d.dir/core/platform/lf_linux_support.c.o] Error 1
gmake[2]: *** Se espera a que terminen otras tareas....
gmake[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/Composition_d.dir/all] Error 2
gmake: *** [Makefile:136: all] Error 2
Soroosh129 commented 2 years ago

Okay, thank you for the additional details.

In case someone else gets to fixing this issue before I do, I would like to point out that the platform files are added automatically by CMake. This is done in this file. It is not yet clear to me why CMake thinks that the platform is "Linux" when it is clearly "Darwin".