vita-rust / vitasdk-sys

vitasdk bindings to be used in rust
Other
10 stars 2 forks source link

New crate layout is confusing for previous users #20

Closed workingjubilee closed 9 months ago

workingjubilee commented 1 year ago

There probably should be a slightly more thorough migration guide to the new crate design, or more and more "modernized" examples of its use, especially in terms of features.

pheki commented 1 year ago

Hey! When I have more time I'll go back to this and improve the docs. For now I'll explain my plan and include a sketch migration guide (with rationale) in case it's of interest. See also: CHANGELOG.md

The plan

v0.3 Migration Guide

Breaking changes

There are basically 2 breaking changes:

  1. All items have moved to the crate root, so you need to import from the root instead:

Before:

use vitasdk_sys::{
    psp2::{
        display::sceDisplaySetFrameBuf,
        kernel::sysmem::{
            sceKernelAllocMemBlock, sceKernelFreeMemBlock, sceKernelGetMemBlockBase,
        },
    }, 
    psp2common::{
        display::{SceDisplayFrameBuf, SceDisplaySetBufSync::SCE_DISPLAY_SETBUF_NEXTFRAME},
        kernel::sysmem::SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW,
        types::SceUID,
    },
};

After:

use vitasdk_sys::{
    sceDisplaySetFrameBuf, sceKernelAllocMemBlock, sceKernelFreeMemBlock, sceKernelGetMemBlockBase,
    SceDisplayFrameBuf, SceUID, SCE_DISPLAY_SETBUF_NEXTFRAME,
    SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW,
};
  1. We used to automatically link to all stubs available and had no features. Now we have one feature per stub, with items gated on the feature. The job here is to basically go over every item (that fails to compile) on docs.rs/vitasdk-sys and check which feature is required.

Using the example above, by searching the docs for sceDisplaySetFrameBuf we find: Available on crate feature SceDisplay_stub only. Meaning you have to enable SceDisplay_stub for vitasdk-sys.

Considering all imports on the example above (1.), Cargo.toml would have:

[dependencies.vitasdk-sys]
version = "0.3.2"
features = [
    "SceSysmem_stub",
    "SceDisplay_stub",
]

Rationale

  1. Upstream (vita-headers) moves files all the time, which means breaking changes because of the tree structure. Using a flat structure is easier to use and also means there should be no more namespace changes.

  2. On 0.1 and 0.2 I had setup build.rs to always link to all vitasdk stubs (more than 200), except for a few with conflicting symbols. It was done that way mostly because I just wanted to get something out and I didn't know db.yml files existed (which allow us to "easily" trace which symbols depend on which stubs). @ZetaNumbers basically rewrote binding generation from scratch so you can now choose which stubs get included.