My plan was to do something like:
- Run the "collection" part of
header-translator (e.g. main.rs::parse_sdk) for each platform
- Compare the output against each other:
- For each framework, if it exists on one platform but not the others, add it to the list of frameworks, but with appropriate
availability attribute that will end up adding a cfg attribute on it
- For each file, --||--
- On each platform, put all statements into some sort of
HashMap with "top-level" information (name of stmt, which generics a class has, and so on (but not which methods a class has implemented))
- Use this to figure out which statements are on which some platforms
- Add that to the final output, with relevant
cfg attributes (ideally in the same order as the input file)
- Similarly for each method in classes/protocols/categories
- Output the combined result
The result is that we would only have to distribute one crate, and that crate would have the correct cfg attributes, which is very useful for the documentation on docs.rs (since it could directly show us which things are available on which platforms).
As an example, let's take NSPointerArray: On this, there are five methods on macOS, and three on iOS, pointerArrayWithStrongObjects and pointerArrayWithWeakObjects are only available on macOS (gated behind #if TARGET_OS_OSX). So the result we'd like is that these two got a #[cfg(target_os = "macos")] on them.
All of this is the ideal solution; before we get there though, we're going to be doing a bunch of hacks, #600 contains an example of one of these.
My plan was to do something like:
header-translator(e.g.main.rs::parse_sdk) for each platformavailabilityattribute that will end up adding acfgattribute on itHashMapwith "top-level" information (name of stmt, which generics a class has, and so on (but not which methods a class has implemented))cfgattributes (ideally in the same order as the input file)The result is that we would only have to distribute one crate, and that crate would have the correct
cfgattributes, which is very useful for the documentation on docs.rs (since it could directly show us which things are available on which platforms).As an example, let's take
NSPointerArray: On this, there are five methods on macOS, and three on iOS,pointerArrayWithStrongObjectsandpointerArrayWithWeakObjectsare only available on macOS (gated behind#if TARGET_OS_OSX). So the result we'd like is that these two got a#[cfg(target_os = "macos")]on them.All of this is the ideal solution; before we get there though, we're going to be doing a bunch of hacks, #600 contains an example of one of these.