Skip to content
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

Add bindings for target_env = "libnx" #1829

Closed
wants to merge 9 commits into from

Conversation

leo60228
Copy link
Contributor

This target is added by rust-lang/rust#74567. This was originally generated through rust-bindgen, then cleaned up by hand.

@rust-highfive
Copy link

r? @JohnTitor

(rust_highfive has picked a reviewer for you, use r? to override)

@leo60228
Copy link
Contributor Author

I fixed most of the style issues, but the item ordering seems like it could be really annoying to fix by hand. Is there anything that automates this?

@leo60228
Copy link
Contributor Author

I wrote this tool to sort the items:

use quote::ToTokens;
use std::env;
use std::fs;
use syn::Item;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let code = fs::read_to_string(env::args().nth(1).unwrap())?;
    let mut file = syn::parse_file(&code)?;
    let (foreign, mut items): (Vec<_>, Vec<_>) = file
        .items
        .iter()
        .cloned()
        .partition(|x| matches!(x, Item::ForeignMod(_)));
    let mut foreign_iter = foreign.into_iter().map(|x| {
        if let Item::ForeignMod(x) = x {
            x
        } else {
            unreachable!()
        }
    });
    let mut foreign_mod = foreign_iter.next().unwrap();
    foreign_mod.items.extend(foreign_iter.flat_map(|x| x.items));
    items.push(Item::ForeignMod(foreign_mod));
    file.items = items;
    file.items.sort_by_key(|x| match x {
        Item::Use(_) => 1,
        Item::Type(_) => 2,
        Item::Struct(_) => 3,
        Item::Union(_) => 3,
        Item::Enum(_) => 3,
        Item::Const(_) => 4,
        Item::Static(_) => 4,
        Item::Fn(_) => 5,
        Item::ForeignMod(_) => 6,
        _ => 7,
    });
    println!("{}", file.into_token_stream().to_string());
    Ok(())
}

@leo60228
Copy link
Contributor Author

leo60228 commented Jul 21, 2020

CI failure seems to be spurious (looks like something's broken in the latest cargo-xbuild release).

@JohnTitor
Copy link
Member

CI failure seems to be spurious (looks like something's broken in the latest cargo-xbuild release).

It's due to rust-lang/rust#74577.

@leo60228 leo60228 changed the title Add bindings for target_env = "devkita64" Add bindings for target_env = "libnx" Jul 21, 2020
@JohnTitor
Copy link
Member

JohnTitor commented Jul 22, 2020

@leo60228 Could I hold off this until rust-lang/rust#74567 gets an approval from the team, and naming and other matters are stabilized? (At least we should wait for fixing nightly though.)

@bors
Copy link
Contributor

bors commented Feb 13, 2021

☔ The latest upstream changes (presumably #1975) made this pull request unmergeable. Please resolve the merge conflicts.

@JohnTitor
Copy link
Member

Looks like the above PR was closed due to inactivity. I'm going to close this as well but feel free to re-open once you get some time to work on. Thanks!

@JohnTitor JohnTitor closed this Mar 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants