Skip to content

Remove the need for crate-type = ["dylib"] #476

Description

@nazar-pc

Right now for shader crate to compile crate-type = ["dylib"] is needed to be specified in Cargo.toml.

This is annoying in case when a library is not just a shader, but also a regular dependency of other crates since this makes compiler generate extra libshader_crate.so shared objects in target/{release,debug}.

This can be worked around with cargo rustc --crate-type dylib when compiling normally, so maybe codegen backend or cargo-gpu could do something like that transparently and implicitly?

Feel free to move this into cargo-gpu repository if it makes more sense to be there. Has nothing to do with cargo-gpu.

Activity

  1. Firestar99 commented on Dec 4, 2025

    @Firestar99
    Member

    FYI declaring it as crate-type = ["lib", "dylib"] will make the CPU build link in the static lib instead of using the *.so, but will still needlessly build the *.so.

  2. Firestar99 commented on Dec 4, 2025

    @Firestar99
    Member

    I would love to remove that requirement!

    dylib being used so rarely has revealed some issues in the past as well, causing weird failures.

    On --crate-type dylib: while the cargo rustc cmd does have a --crate-type, cargo build or run or test do not. And we primarily rely on cargo build to build and link everything. So we'd either need cargo to add support for that, or figure out some other way to extract all the rlibs we need to link from cargo.

    Related: In RFC: link-time capabilities, I've suggested this:

    Changing link-time capabilities does not require a clean recompile, unlike the current spirv capabilities.

    This would also need some kind of custom linking, though the information retrieval from cargo on what needs to get linked would likely be separate from however any variations of linking we do internally.

  3. nazar-pc commented on Dec 4, 2025

    @nazar-pc
    ContributorAuthor

    FYI declaring it as crate-type = ["lib", "dylib"] will make the CPU build link in the static lib instead of using the *.so, but will still needlessly build the *.so.

    I know, that is exactly what I do right now.

    On --crate-type dylib: while the cargo rustc cmd does have a --crate-type, cargo build or run or test do not. And we primarily rely on cargo build to build and link everything. So we'd either need cargo to add support for that, or figure out some other way to extract all the rlibs we need to link from cargo.

    This is exactly why I thought about cargo-gpu: even if it is not possible to remove the requirement directly, cargo-gpu could still call cargo rustc internally and use that option.

  4. Firestar99 commented on Dec 4, 2025

    @Firestar99
    Member

    I thought this is gonna be hard. But after researching the differences between cargo build and cargo rustc, I noticed that they're pretty much the same. cargo rustc just allows you to pass some additional args to rustc, like --crate-type=dylib. So this is actually trivially easy: #477

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions