I compiled Rust and got a “hello world” working.
However things got messy when I tried to port glutin to it.
For the record, I had tried your emscripten branch back in december, and glutin was working just fine. So all the problems here are either new or due to the fact that I built in release mode (most likely the latter). EDIT: I built rustc in release mode, not glutin.
Part of the code of glutin requires calling functions from the emscripten SDK. One of these functions is emscripten_GetProcAddress, defined like this:
extern {
pub fn emscripten_GetProcAddress(name: *const libc::c_char) -> *const libc::c_void;
}
And I call the function like this:
fn get_proc_address(&self, addr: &str) -> *const () {
let addr = CString::new(addr.as_bytes()).unwrap();
let addr = addr.as_ptr();
unsafe {
ffi::emscripten_GetProcAddress(addr as *const _) as *const _
}
}
But when I do so, emscripten reports in the console that it received some garbage data.
I initially thought that it was a problem with the ABI, however when I pass a static value (for example emscripten_GetProcAddress(b"hello world\0" as *const _)), it works (emscripten still complains that the name is wrong, but at least it’s no longer garbage). More importantly, it also works if I replace addr.as_ptr() with into_raw (which leaks the string).
Even if I manage to pass the correct strings to emscripten, things continue to be bad afterwards. For example
calling glGetString(GL_VERSION) returns the string A fantastic window!, which is a static string located in the app.
I don’t exactly know what happens, but it seems to be a low-levelish problem.