lf-lang / lingua-franca

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

Target property: platform #330

Open soyerefsane opened 3 years ago

soyerefsane commented 3 years ago

In order to support baremetal execution, we need the cross-compiling (or rather cross code generation) feature. On top of that, this feature will enable cross-compiling for remote federates in federated execution. For example;

//cross code generated for baremetal platforms 
target C {
    platform: riscv-baremetal
}

or

//cross code generated for platforms that use a different OS than the host machine 
target C {
    platform: macos
}
lsk567 commented 3 years ago

This came up in our meeting. Seems like a good feature to have to enable bare-metal code generation.

edwardalee commented 3 years ago

One feature that would be useful is to disable compiling the generated code if the platform does not match the machine on which code generation is done. In example/C/Rhythm, we have some programs that run on Linux and some that run on Mac. Whichever machine you are on, some of these programs fail to compile and the IDE reports errors. It would be better if it just didn't compile the code that doesn't match. None of these will compile if you are on a Windows machine...

lsk567 commented 3 years ago

@edwardalee Okay, I think the subtlety here is to identify whether the user wants to do cross-codegen (generating source code for another platform) when dealing with platform-specific LF code. Having both platform and cross-codegen seems to solve the problem:

LF filename platform cross-codegen
riscv-app riscv-baremetal true
rhythm-linux linux false

When platform is specified, lfc can pull the corresponding support files from a specific platform folder, without detecting the current OS of the host machine first, which is the default behavior.

When cross-codegen is set to true, it means that "go ahead and codegen even if the host OS is different than the specified platform." If set to false, it means that "codegen only if the host OS matches the specified platform."

edwardalee commented 3 years ago

Fo cross compiling, why isn’t the build target property sufficient?

lsk567 commented 3 years ago

The build target property is not sufficient for "cross-code generation" (.lf to .c) because the user cannot choose the corresponding platform support files from the command line, but build is sufficient for "cross-compilation" (.c to bin).

The proposal is an attempt to fully embrace the platform abstraction in lfc.

lhstrh commented 3 years ago

I think it might be good to (re)evaluate this issue in light of @cmnrd's https://github.com/icyphy/lingua-franca/issues/329#issuecomment-919772230

I think it wouldn't be strange to limit cross-compiling capability to lfc and have it provide adequate support for that through CLI arguments. One might want to cross-compile a given program for various different platforms, and it would be somewhat odd to have to change the source code for that.

lhstrh commented 3 years ago

@cmnrd and @Soroosh129 suggested that cmake's cross compiling capability (in combination with @Soroosh129's platform abstraction) might be sufficient to achieve all the goals that the platform property was originally intended to. @efsanesoyer: perhaps you can work with them to figure out how to do this? I would start with an example.

The main concern here is that we should be careful not to entangle the target and the platform, or else we'd effectively be creating targets in an ad-hoc manner (i.e., a C target with some platform X is effectively a different target from C with some other platform Y).