Skip to content

Conversation

@novicearts
Copy link

This PR includes necessary changes to get the incbin header file working on emscripten platforms.

The changes made here are based on the following code snippet: https://github.com/dotnet/runtimelab/blob/889ad1337ac28740a97cc60fa6126654e59de73c/src/native/libs/System.Globalization.Native/icu_data_lib.c#L8-L18

I learned about this from discussing with folks on the WebAssembly discord server. Presently the .size marker holds a fixed size amount of 4 in the common macro, which may pose a problem for wasm64, but I believe should be fine for wasm32. Otherwise from tests on my machine I've experienced near identical behavior switching from PC to web targets of my code.

I tested this on a windows 8 machine using clang for both PC and Web. I dont have access to other machines/OSes to test the changes with. In the worst case scenario this cant be merged, I hope it serves as a useful reference for anyone else wanting to integrate with emscripten.

Signed-off-by: Novice Arts LLC <noviceartsstudios@gmail.com>
@graphitemaster
Copy link
Owner

Not sure this is the correct approach. It seems that the .size directive can be used in all other assemblers so I'm not sure why we shouldn't do it unconditionally. Otherwise it looks like a couple minor syntax changes for how it expects the labels to be tagged. I wonder if we can somehow reuse the evaluation of the size that is already done here to also set .size.

Also AS_STR(SIZE) seems to be undefined

@novicearts
Copy link
Author

novicearts commented May 27, 2025

I agree with your suggestion about the .size directive. if it can be done universally, that would be better, as that has less conditional code. I wasnt sure .size was universally available at first, which was why i opted to gate it behind the emscripten flag initially.

It seems like the big change is the section label, as that had new syntax I have not seen in any other assembler. As well, emscripten requires incbin to be restricted to the .data section, and it's a hard compiler error if a different one is used.

I can fix AS_STR(SIZE), as it's just the stringize preprocessor macro by any other name. though that being said depending on how integrating .size happens, this code might be eliminated entirely

@novicearts
Copy link
Author

novicearts commented May 27, 2025

so I double checked your suggestion about the .size directive, and it looks like it's not universally available in all assemblers. I suspect it's an emcc specific directive. These errors cropped up on my PC clang build when I tried using incbin with the .size directive specified. If it were an issue with using .size incorrectly, I think the error messages would be more specific. The same directive still compiles correctly in emscripten.

image

Signed-off-by: Novice Arts LLC <noviceartsstudios@gmail.com>
@forderud
Copy link

I'm working on a project that would potentially benefit from "incbin" WASM support. Any chance of getting WASM support merged in the near future?

forderud added a commit to forderud/QtWasm that referenced this pull request Oct 23, 2025
… as of 2025-10-23.

Add associated test code to verify WASM compatibility.
forderud added a commit to forderud/QtWasm that referenced this pull request Oct 23, 2025
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

Successfully merging this pull request may close these issues.

3 participants