Skip to content

Conversation

@csegarragonz
Copy link
Contributor

@csegarragonz csegarragonz commented Oct 24, 2022

In this PR I move all the variables needed to cross-compile C and C++ to WASM to a single Python file faasmtools/build.py. All other files now read the values defined in this file. This change removes duplication of highly sensitive variables like the linker or compiler flags.

I have decided to define all variables in a python file because we wrap calls to the compiler in python scripts anyway, which makes it easy to add the required variables.

The mechanism I have chosen to share variables between the python script and other files are environment variables. For example, a file like WasiToolchain.cmake now relies on a certain number of environment variables to be defined. Not having a self-contained *.cmake file to include could make it less straight-forward to cross-compile a library outside of faasm/cpp, as you'd have to remember to prepend the env. vars before calling cmake, but works seamlessly in the scenario where we hold all the code to cross-compile libraries in faasm/cpp (as we have been doing with FFmpeg, ImageMagick, and TensorFlow, and I am planning to port LAMMPs and LULESH in the future as well).

Another argument in favour of having all supported cross-compiled libraries in faasm/cpp is that this way it is easier to catch regressions, where a change in the toolchain breaks something that was building before. This, together with a minimal test in faasm/faasm, should ensure that we don't drop support to things we already support (even if the submodules rot away).

In the process, I fix some formatting misalignments.

Closes #6

@csegarragonz csegarragonz self-assigned this Oct 24, 2022
get_serialised_cmake_env_vars(),
"cmake",
"-GNinja",
"-DFAASM_BUILD_TYPE={}".format(build_type),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already set by the toolchain file

@csegarragonz csegarragonz marked this pull request as ready for review October 26, 2022 09:53
}


def get_dict_as_cmake_vars(env_dict):
Copy link
Contributor Author

@csegarragonz csegarragonz Oct 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Faasm, we can pass the FAASM_RUNTIME_ENV_DICT variables as CMake CACHE variables, which is preferrable than env. variables. Unfortunately, CACHE variables are not always read/loaded properly in toolchain files so in faasm/cpp we revert to using env. variables.

Copy link
Collaborator

@Shillaker Shillaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice this looks good.

Re. the stand-alone CMake toolchain file, I had thought that it would be nice to template it from the Python code, rather than have it rely on env vars, but this is definitely not in scope atm.

@csegarragonz csegarragonz merged commit 8f955ef into main Oct 31, 2022
@csegarragonz csegarragonz deleted the build-unique branch October 31, 2022 08:53
@csegarragonz csegarragonz mentioned this pull request Jan 31, 2023
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Template CMakeLists, Makefile.inc etc.

3 participants