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 upkr as a library from C/C++ #9

Open
fgenesis opened this issue Mar 6, 2023 · 2 comments
Open

Using upkr as a library from C/C++ #9

fgenesis opened this issue Mar 6, 2023 · 2 comments

Comments

@fgenesis
Copy link

fgenesis commented Mar 6, 2023

Hey, first up, I don't know much about the state of the rust ecosystem or rust in general so sorry if this is a dumb question.
I'd like to integrate upkr into a resource packer thingy i'm currently throwing together, which is written in C++.
Now rust is supposedly C ABI compatible but it seems not possible to transpile rust to C. After reading up on the subject, LLVM's C backend is dead, so compiling upkr to a LLVM bitcode file and translating that to C don't seem like a good option. I've tried compiling as wasm (with the intention to wasm2c later) but that didn't work either.

How would I go about integrating upkr as a library? Best would be a .c/.h file to simply compile in, alternatively a DLL with some callable exports.

(I've done that with exomizer a while back, which doesn't compile as C++, but at least it's C, so writing a wrapper was simple enough)

Thanks!

@exoticorn
Copy link
Owner

Transpiling rust to C isn't really feasible. (Technically it is possible to make the route through wasm and wasm2c work, but it's not trivial and not really worth the effort.)

Rust code can be compiled to a DLL or static .lib to link it into a C/C++ program, however I'd still need to manually create a C-compatible API for upkr. I can probably quickly build a small simple version of that with simple compression/decompression support. Do you have some Idea what you'd need from that api? Would something like:

int upkr_compress(void* output_buffer, size_t output_buffer_size, void* input_buffer, size_t input_size, int compression_level);
int upkr_decompress(void* output_buffer, size_t output_buffer_size, void* input_buffer, size_t input_size);

be enough for your usecase? (If you need a variant of the compression format, like --z80, you could build a version of the library with that hard-coded in.)

@exoticorn
Copy link
Owner

I added a basic c_library example. It only includes two simple functions to compress/uncompress with the default config but would be fairly easy to extend if you need more:

795e6c3

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