Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake changes to generate code #175

Closed
aregtech opened this issue Jun 26, 2023 · 14 comments · Fixed by #333
Closed

CMake changes to generate code #175

aregtech opened this issue Jun 26, 2023 · 14 comments · Fixed by #333
Assignees
Labels
C++ cmake enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed improvement

Comments

@aregtech
Copy link
Owner

Description:
The projects, which use Service Interface document file (files with extension .siml) contain generated codes, which are manually integrated in the projects by CMakeLists.txt files. Since these files are generated and the sources are kind of fixed, it makes sense to modify the CMakeLists.txt file to generate and compile files during build.

Required:

  1. Modify the CMake to generate and build static libraries from Service Interface document files. Something like addServiceInterface(myproject, myproject/HelloWordl.siml), where the myproject is the name of the project and static library and myproject/HelloWordl.siml is the relative path to the Service Interface document.
  2. There should be possibility to link the static library with the target binary, something like linkProject(target, myproject).
  3. Modify the CMake build to add an option that will only generate files and create MSVC project files.

Note:
The description might be not really clear. Please start the discussion here and ask questions to @aregtech before starting modifying.

@aregtech aregtech added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers improvement labels Jun 26, 2023
@aregtech aregtech self-assigned this Jan 24, 2024
@aregtech aregtech moved this to In Progress in AREG IoT SDK (areg sdk) Jan 24, 2024
@aregtech
Copy link
Owner Author

aregtech commented Feb 9, 2024

@biwiki , can you please help? Of course if you have time. I'm a little stuck making changes in Makefile.

The situation is following: In the branch 175-cmake-changes-to-generate-code I've made changes that code generator generates files in the ./product/generate directory and automatically includes in the build. To do this, I've defined function addServiceInterfaceEx for cmake build. It triggers code generator, creates list of sources and either creates new static library (if does not exist) or adds the sources to the existing target (static library). The examples 10 - 24 contain call of addServiceInterface (simplified version of addServiceInterfaceEx). For example, this call. Or here, where the first call of addServcieInterface generates codes of PowerManager.siml and sets static library 16_generated and the second call of addServiceInterface generates codes of TrafficController.siml and adds generated sources to the existing target 16_generated static library.

Now the similar thing I'd like to have in Makefile, where it would run code generator and create static library. I tried to implement, but my knowledge and experience is not enough. I would appreciate very much help. If you feel that it might be too complicated, please let me know. Maybe I temporary disable make build.

Many thanks in advance and best regards.

@biwiki
Copy link
Collaborator

biwiki commented Feb 12, 2024

@aregtech sure, I will look into this when I can have time

@aregtech
Copy link
Owner Author

@biwiki , sounds great!
Just for your information. Right now I have disabled (removed) Makefile", but created [a tag](https://github.com/aregtech/areg-sdk/tags) on master branch. This is the latest version to compile with make`. Let me know if you need any help from me.

@biwiki
Copy link
Collaborator

biwiki commented Feb 12, 2024

Ohh it can be a right thing, maintaining 2 different build systems within the same sourcebase can make things complicated

@aregtech
Copy link
Owner Author

If you see it's getting too complicated, we can escape and deprecate the build with make. Simply, for a long time it was working fine ☺️

@biwiki
Copy link
Collaborator

biwiki commented Feb 13, 2024

Great to hear that you like the Makefile, but I would say that it is time to deprecate that old build system

Code generation with Java can also be a problem. I am not sure if this is documented somewhere but I can understand that users need to install correct Java version a long with other dependencies in order to use the tool
I am myself hitting this error with default Java on Ubuntu 22..04

==============================================================================
Generating class defined in HelloService.siml to generated/src ....
==============================================================================
Error: LinkageError occurred while loading main class com.aregtech.CMFMain
        java.lang.UnsupportedClassVersionError: com/aregtech/CMFMain has been compiled by a more recent version of the Java Runtime (class file version 58.0), this version of the Java Runtime only recognizes class file versions up to 55.0

IMO, If this would not take too much efforts, then the code generation tool should be converted (and open) to Python. In embedded domain, there should be more chances that users have knowledge on Python and would be able to resolve dependency issues if there is any with it.

@aregtech
Copy link
Owner Author

@biwiki , thank you for your feedback. I appreciate that.

  1. make build: OK. I don't mind to deprecate build with make. Indeed it is not easy to support.
  2. Java: good idea. What do you think, is it better to create new repository for code generator or include sources in areg-sdk/tools and build JAR if the codegen.jar does not exist? BTW, which version of Java do you have? In principle, I don't use modern features of Java classes and could compile with older versions.
  3. Python: well, in principle, it is a good idea, but my knowledge of Python are not so good to write a code generator :)

@biwiki
Copy link
Collaborator

biwiki commented Feb 13, 2024

This is Java version on my machine

$ java --version
openjdk 11.0.21 2023-10-17
OpenJDK Runtime Environment (build 11.0.21+9-post-Ubuntu-0ubuntu122.04)
OpenJDK 64-Bit Server VM (build 11.0.21+9-post-Ubuntu-0ubuntu122.04, mixed mode, sharing)

Since we are embedding code generator into the build flow, this can stop users from compiling the library.

I am not against using Java :-) But due to this I just dont know how to proceed
I personally have seen quite a lot of code generators written in Python, and we didn't hit the same issue as this.

@aregtech
Copy link
Owner Author

I compiled jar with jdk21.
I think, it is not a problem if compile with the lower version.
What is your suggestion, to switch to Python? It would be additional effort

@biwiki
Copy link
Collaborator

biwiki commented Feb 13, 2024

yeah it can take huge effort to convert to Python, sorry but it is upto you to decide

@aregtech
Copy link
Owner Author

@biwiki,

I've made new build of code generator, compiled with jre1.8 (jre8)

openjdk version "1.8.0_392"
OpenJDK Runtime Environment (build 1.8.0_392-8u392-ga-1~22.04-b08)
OpenJDK 64-Bit Server VM (build 25.392-b08, mixed mode)

The codes are in the branch feature/175-cmake-changes-to-generate-code
Tested with jre8, jre11 and jre21 (jre8 and jre11 under Ubuntu). It worked for me.
Can you please check and confirm whether it works for you as well?
Please pay attention that the Makefile does not exist anymore.

  • There are not submodules anymore (fetching googletest is compile with tests)
  • The codes are generated during configuration (created if file does not exist or updated).

@aregtech
Copy link
Owner Author

Hi @biwiki

I also let the action workflow to run with JRE 11, it generates and compiles fine. Have a look the logs here. Check the runs ending with -test like this one and here is the JRE setup. Theoretically, you also should not have a problem.

@aregtech aregtech linked a pull request Feb 14, 2024 that will close this issue
@biwiki
Copy link
Collaborator

biwiki commented Feb 14, 2024

thanks, yes I can run the code generator on my Linux box now

@aregtech
Copy link
Owner Author

Great!
Thank you for your feedback.
Then I'll merge changes to master.

@aregtech aregtech moved this from Done to Reviewed in AREG IoT SDK (areg sdk) Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ cmake enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed improvement
Projects
Status: Reviewed
Development

Successfully merging a pull request may close this issue.

2 participants