glfw: add shared option which builds glfw into it's own shared library #442
No reviewers
Labels
No labels
CI
all
basisu
blog
bug
build
contributor-friendly
core
correctness
deferred
dev
direct3d-headers
docs
driver-os-issue
duplicate
dxcompiler
editor
examples
experiment
feature-idea
feedback
flac
freetype
gamemode
gkurve
glfw
gpu
gpu-dawn
harfbuzz
help welcome
in-progress
infrastructure
invalid
libmach
linux-audio-headers
long-term
mach
mach.gfx
mach.math
mach.physics
mach.testing
model3d
needs-triage
object
opengl-headers
opus
os/linux
os/macos
os/wasm
os/windows
package-manager
priority
proposal
proposal-accepted
question
roadmap
slipped
stability
sysaudio
sysgpu
sysjs
validating-fix
vulkan-zig-generated
wayland-headers
website
wontfix
wrench
www
x11-headers
xcode-frameworks
zig-update
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
hexops/mach!442
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feature_glfw_shared"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This adds the
sharedoption, which builds GLFW into it's own shared library.The use case for this is as follows (in this setup, the exe loads the game dll at runtime using std.DynLib):
This way, both
gameandexelink with the shared library, so that there is one copy of the_glfwglobal state in the process. Static linking wouldn't work here, as the dll and exe would have separate copies of_glfw.A couple things I'm not sure about:
I opted to cache the shared library for each call (create it on the first
glfw.linkcall and re-used the instance across calls). The other option would be a separate call (ie.glfw.createSharedGlfw) to create the shared lib, and you'd pass that as the option instead of a bool. I'm happy to change over to that, but I was trying to keep the API simple.Specifying
zig-out/binas the output dir - this works in the simple case, but may break if that directory has been changed on the parent step. The intention is to place the dll next to whatever exe/dll is linking with it, but I'm not familiar enough with the build system to know how to get that automatically.By selecting this checkbox, I agree to license my contributions to this project under the license(s) described in the LICENSE file, and I have the right to do so or have received permission to do so by an employer or client I am producing work for whom has this right.
Could you leave this function signature as it was before, so that e.g. this does not break - and instead introduce a new private
fn testStepShared& just duplicate the code here to test the shared library approach?i think this is a good approach and should be applied to all sub-projects
not opposed to that, let's do it in another PR though.
@kcbanner I pushed a few changes / cleanups, give this a try and let me know if it still works for you?
I also removed the line that was writing the lib into the bin dir, instead opting for the natural Zig output location so we end up with e.g.: