-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Allow Neutrino QNX SDK dependent values for PTHREAD_MUTEX_INITIALIZER #4192
base: main
Are you sure you want to change the base?
Allow Neutrino QNX SDK dependent values for PTHREAD_MUTEX_INITIALIZER #4192
Conversation
…al QNX C toolchain
@flba-eb We had discussed this but it was not clear for me as to why we cannot define the values for these consts under a cfg flag for each of the variants. cfg_if! {
if #[cfg(target_env= "nto71")] {
pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
__u: 0x80000000,
__owner: 0xffffffff,
};
}
else if #[cfg(target_env = "nto80")] {
pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
__u: _NTO_SYNC_NONRECURSIVE,
__owner: _NTO_SYNC_MUTEX_FREE,
};
}
else {
//...
}
} |
Well, basically this is what the change does, but it uses conditional compilation switches set by I would prefer to determine the actual value in the build.rs script and use it in the libc code, but this does not work:
|
IMHO this is still not a scalable solution as the other structs will have different number and named elements and hence users will need to extend the parser to more elements. I'd prefer that the consts/structs are divided into modules specific files like. unix>nto>
├── aarch64.rs
├── mod.rs
├── neutrino.rs
├── nto7071
│ └── mod.rs
├── nto80
│ └── mod.rs
└── x86_64.rs
|
I don't want to determine all values at compile time (in build.rs). Only when necessary, e.g. between different "7.1" versions. |
In that case i agree :) |
I don't think we can go with this approach: this isn't robust against
Could you elaborate this a bit - do you mean that e.g. within the There is some recent discussion on breaking changes within a target string, if this applies here then it would be good if you could comment on that thread https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/How.20to.20handle.20breaking.20changes.20in.20libc.201.2E0 |
It can be even more subtle than that. In one project, we have a project specific version like I am fully aware that my "parsing" approach is error-prone, and I've considered calling the C preprocessor instead and parsing it's output. However, I've decided against that because:
I will comment there. |
As an alternative option, #include <pthread.h>
pthread_mutex_t _PTHREAD_MUTEX_INITIALIZER = PTHREAD_MUTEX_INITIALIZER;
Then |
Description
This change tries to determine the value of a constant at compile time of libc:
build.rs
reads and "parses" the content of the C header filepthread.h
. "Parse" means that it checks for the usage of other constants, which is sufficient for all observed cases.Background:
In Neutrino QNX, some "constant" values get changed between releases of the toolchain, including in minor patch-versions. Whenever you get a new "QNX toolchain" (SDP), C and C++ developers know that they must recompile everything.
So far, I've only observed three variations, but there could be more that I'm not aware of. This is why I don't want to add and maintain a possibly long list of compiler targets, this would not work well.
Using this patch requires the environment variable
QNX_TARGET
which is always the case when compiling for QNX (required by the linker).Conceptionally this change is similar to what FreeBSD is doing, but reads header file instead of running an external process (
freebsd-version
).CC and todo list
CC: @jonathanpallant @japaric @gh-tr @AkhilTThomas
libc-test/semver
have been updated: 👎 unfortunately impossible*LAST
or*MAX
areincluded (see #3131)
cd libc-test && cargo test --target mytarget
);especially relevant for platforms that may not be checked in CI