-
Notifications
You must be signed in to change notification settings - Fork 245
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
Platform generic transpilation #305
Comments
My initial experimentation on this indicates that working around the host preprocessor expansion might even be sufficient to transpile on generic platforms. Since I've started using a C compiler with the right target platform in The downside of this approach so far is that I'm using the actual platform C compiler and not clang with suitable flags -- which means that under some circumstances, GCC idiom winds up there and I get errors like "Type conversion not implemented for TagTypeUnknown expecting 3" (At least I think that's what's happening there). Eventually, I think that if all arguments are passed around right (and I'm honestly not quite sure whether they aren't already), clang could work from the data already in compile_commands.json and produce output suitable for any platform, provided it's specified the right way in the compile commands. |
Further experimentation has shown that expanding preprocessor is only really necessary when using a C compiler different from clang -- that then has its own path discovery, and eventually finds the platform-specific definitions for variously sized integers that clang does not find. Where clang is used, I see no real difference in the results between using preprocessed and original data. (Function sequence differs, and preprocessing loses the data C2Rust would need to Would it be correct to change the FAQ entry to
? (That I'm using a non-clang C compiler is probably a niche problem for general C2Rust applications; most other projects probably just work with clang). |
To cross-compile with clang, you need at least the following:
For C2Rust, you get 1+2 above automatically from |
Those three I got, and they work for me. If there's really nothing more to it (and frankly it looks to me that way by now), I think the FAQ should be updated to say something different than "not supported at the moment". Another suggestion for text (given I don't like the above that much any more):
|
This ensures that the typedefs that lead to types like uint64_t are aligned with the target code -- otherwise, odd expansions are pulled in that lead to a uint64_t being defined as `unsigned long`. (Fortunately, such errors show at compile time as RIOT bit-shifts such numbers by hard-coded large sizes). Workaround-For: immunant/c2rust#305
The FAQ are explicit about not supporting cross-transpilation, but I'd like to use that and work on fixing it (primarily to get rust-lang/rust-bindgen#1344 working); I'd appreciate a bit of high-level review before I get head-on into it.
According to the FAQ entry, the preprocessor is run first, and that's what's keeping transpilation from working. With the right flags supplied to the preprocessor, that should not be too much trouble. (After all, flags are already supplied for platform dependent stuff, like any defines the program may use to determine endianness and such).
Looks to me that the more difficult step will be getting the types right, ie. putting i32 or i64 where C has its
int
orlong
. The cty crate may be of some help there.The text was updated successfully, but these errors were encountered: