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

Using sdl3-sys to provide SDL3 headers/library #14

Closed
loganmc10 opened this issue Jan 24, 2025 · 6 comments
Closed

Using sdl3-sys to provide SDL3 headers/library #14

loganmc10 opened this issue Jan 24, 2025 · 6 comments

Comments

@loganmc10
Copy link

Would it be possible to implement this features?

https://github.com/Rust-SDL2/rust-sdl2?tab=readme-ov-file#using-sdl2-sys-to-provide-sdl2-headerslibrary

Rust-SDL2/rust-sdl2#968

This would allow using SDL.h in C projects that are built along with the project

@maia-s
Copy link
Owner

maia-s commented Jan 24, 2025

You can get this via the sdl3-src crate. There's a constant SOURCE_DIR in the crate root that contains the location of the SDL source code as a string. The headers are in the include dir relative to that.

I could add this to sdl3-sys too, but it doesn't currently include the headers and only depends on sdl3-src if building from source, so it'd have to be behind a feature flag unless I duplicate the headers there.

@loganmc10
Copy link
Author

loganmc10 commented Jan 24, 2025

Yes, this works. I had to add sdl3-src as a build-dependency, and then I could add .include(std::path::PathBuf::from(sdl3_src::SOURCE_DIR).join("include")); to the c library that depends on it, thanks!

@maia-s
Copy link
Owner

maia-s commented Jan 24, 2025

Happy that works for you ^^

By the way, if you're using the build-from-source feature of sdl3-sys, it does set the environment variables DEP_SDL3_OUT_DIR and DEP_SDL3_CMAKE_DIR for use in build scripts (via cargo metadata). The former contains the output of the build and the latter has the cmake configuration dir, suitable for passing to cmake.

@loganmc10
Copy link
Author

Understood thanks.

Sorry I have one more question, I'm not sure if it is a bug or not. I get this failure on Windows:

running: "cmake" "--build" "D:\\a\\gopher64\\gopher64\\target\\x86_64-pc-windows-msvc\\release\\build\\sdl3-sys-1a476f94d9180711\\out\\build" "--target" "install" "--config" "Release" "--parallel" "4"
  MSBuild version 17.12.12+1cce77968 for .NET Framework

    SDL3_test.vcxproj -> D:\a\gopher64\gopher64\target\x86_64-pc-windows-msvc\release\build\sdl3-sys-1a476f94d9180711\out\build\Release\SDL3_test.lib
    SDL_uclibc.vcxproj -> D:\a\gopher64\gopher64\target\x86_64-pc-windows-msvc\release\build\sdl3-sys-1a476f94d9180711\out\build\Release\SDL_uclibc.lib
    SDL_gameinputjoystick.c
    SDL_gameinputjoystick.c
    SDL_sysmain_callbacks.c
    SDL_sysmain_callbacks.c
    Generating Code...
    Generating Code...
  C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\sdl3-src-3.2.0\SDL\src\joystick\gdk\SDL_gameinputjoystick.c(29,10): error C1083: Cannot open include file: 'gameinput.h': No such file or directory [D:\a\gopher64\gopher64\target\x86_64-pc-windows-msvc\release\build\sdl3-sys-1a476f94d9180711\out\build\SDL3-static.vcxproj]
    (compiling source file 'C:/Users/runneradmin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sdl3-src-3.2.0/SDL/src/joystick/gdk/SDL_gameinputjoystick.c')
    
  C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\sdl3-src-3.2.0\SDL\src\joystick\gdk\SDL_gameinputjoystick.c(29,10): error C1083: Cannot open include file: 'gameinput.h': No such file or directory [D:\a\gopher64\gopher64\target\x86_64-pc-windows-msvc\release\build\sdl3-sys-1a476f94d9180711\out\build\SDL3-shared.vcxproj]
    (compiling source file 'C:/Users/runneradmin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sdl3-src-3.2.0/SDL/src/joystick/gdk/SDL_gameinputjoystick.c')

Is the Microsoft GDK required to build SDL3? I didn't enable the target-gdk feature, so I assumed it wouldn't be required

@maia-s
Copy link
Owner

maia-s commented Jan 24, 2025

No, GDK isn't supposed to be required. SDL should detect if it's available when cmake is run and disable it if it isn't. The target-gdk feature only enables some function and type declarations in sdl3-sys and doesn't affect the build at all.

Does this also happen if you build SDL with cmake the normal way, or does it only happen when it's built through sdl3-sys?

@loganmc10
Copy link
Author

Sorry I think it is something wrong with the GitHub actions Windows runner (actions/runner-images#10980 (comment)). When I switched to the windows-2025 image the problem went away

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants