-
Notifications
You must be signed in to change notification settings - Fork 70
Unified toolchain variables #689
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
Conversation
4be17e9 to
c23ce45
Compare
…d populate it with cmake
7dc3176 to
b5e5d17
Compare
include/wasm/WasmCommon.h
Outdated
| @@ -0,0 +1,37 @@ | |||
| #pragma once | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is auto-generated by CMake from WasmCommon.h.in, I am not sure whether to track it or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usual practice for auto-generated files is to generate them in the build directory, and never modify the input source tree. It's especially useful when you set up multi-config builds which might need different versions of the same headers. I think faasm already breaks this rule with the current protobuf configuration (I did change that in my fork at some point), but it might be good to follow for future changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks for chipping in, was about to ask you at some point.
We could eventually change the protobuf headers as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow-up, I realised FAASM_INCLUDE_DIR points to CMAKE_LIST_DIR/include, should we eventually move to CMAKE_BINARY_DIR/include and copy the includes there?
I will now do it just for one file, but for the protobuf change for example.
Also, whilst we are at it, I personally prefer to have the project name at the begining of the path, so:
#include <faasm/wasm/WasmCommon.h>so we could copy CMAKE_LIST_DIR/include into CMAKE_BINARY_DIR/include/faasm/include what are your thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think both should be there: CMAKE_LIST_DIR/include first, and then CMAKE_BUILD_DIR/include second. That way the main source tree files take precedence, but you still get access to generated headers. It also means you can theoretically alias names and use #include_next to get an identically named header from the build tree if you want insert a hook/wrap the generated header in some extra code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eigenraven requesting a review from you as well see if i have overlooked something
fbb1072 to
63d136b
Compare
633c481 to
4497dbf
Compare
| # Faasm | ||
| ${FAASM_INCLUDE_DIR} | ||
| # Put the generated include directories after the source include | ||
| # directories so that the latter take precedence |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # directories so that the latter take precedence | |
| # directories so that the former take precedence |
| * values using CMake | ||
| */ | ||
|
|
||
| #define WASM_BYTES_PER_PAGE @FAASM_WASM_BYTES_PER_PAGE@ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a point to keeping bytes-per-page dynamic? Afaik this value is frozen at 64k in the wasm spec
src/wasm/CMakeLists.txt
Outdated
| ) | ||
|
|
||
| # Populate the variables defined for cross-compiling WASM | ||
| set(FAASM_WASM_BYTES_PER_PAGE $ENV{FAASM_WASM_BYTES_PER_PAGE}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have any particular reason to grab these from the environment? Usually you'd use cache variables for these sort of tunables, done with set(... CACHE type "docstring"), as they are less fragile if you accidentally call cmake from the wrong context
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal of this PR is to share this constant definitions with the CPP toolchain, and have them hard-coded only once across all the repos. IMO, even if they won't change, I'd rather have them hardcoded only once (if that doesn't add too much overhead). They are all hardcoded in faasm/cpp/faasmtools/build.py.
So, the way I thought of sharing variables between a python script (faasm/cpp/faasmtools/build.py) and CMake files was through environment variables. It feels a bit hacky, so if you have another alternative I'm happy to adopt it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If they're in a python dict, you should be able to also just pass them in to cmake during configuration time via the -D flags when they're cache variables
| set(FAASM_WASM_MAX_MEMORY $ENV{FAASM_WASM_MAX_MEMORY}) | ||
| set(FAASM_WASM_STACK_SIZE $ENV{FAASM_WASM_STACK_SIZE}) | ||
| set(FAASM_WASM_ZYGOTE_FUNC_NAME $ENV{FAASM_WASM_ZYGOTE_FUNC_NAME}) | ||
| # Shared variables with the cross-compilation toolchain |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eigenraven is this more or less what you had in mind? Also, is there any cleaner way to check if any is not set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and the conditions can probably just be if((NOT FAASM_WASM_BYTES_PER_PAGE) OR (NOT FAASM_WASM_CTORS_FUNC_NAME) ) etc. What you wrote is wrong, because you force expansion with ${}, so it would evaluate to NOT DEFINED CACHE{65536} - when passing variables "by reference" to cmake commands you always name them, without quotes or $-expansion.
Shillaker
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
In this PR we link the definition of WASM-related variables (like the maximum memroy size, or the maximum stack size) in
faasmtools/build.pyto the values in our headers, removing the duplication.Faasmtools defines the necessary runtime variables and aggregates them in a dictionary, which is then appended to the environment of the python process calling CMake. Then, CMake templates a template header file (
include/wasm/WasmCommon.h.in) intoinclude/wasm/WasmCommon.h, where all the variables shared across the three runtimes are stored.If there's a change in the environment variables in
faasm/cpp, then we have to runinv dev.cmakeagain (CMake won't pick up changes in the values of env. variables).For more background information see faasm/cpp#102