emscripten-core / emscripten-core/emscripten

Unnecessary imports for MINIMAL_RUNTIME

Open
#15,895 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

I am building the following code with `em++` and despite not using `canvas` or `webgl` and specifying `MINIMAL_RUNTIME`, for some reason the resulting wasm file wants to import the functions: `emscripten_set_canvas_element_size` and `emscripten_webgl_create_context`. Why are these functions being requested in code that makes no use of these features (especially when requesting a minimal runtime)?

**Code**
```c++
#include
#include
#include
#include
#include

int main() {
int a = 3; int b = 5;
std::mutex m;
int total = 0;
std::vector > vec_futures;
/* add a */
vec_futures.emplace_back(std::async(std::launch::async, [&m, &total, a] {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
m.lock();
total += a;
m.unlock();
}));
/* add b */
vec_futures.emplace_back(std::async(std::launch::async, [&m, &total, b] {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
m.lock();
total += b;
m.unlock();
}));
for(auto& future: vec_futures) {
future.wait();
}
std::cout << total << std::endl;
return 0;
}
```

**Command line**
```sh
em++ -pthread -fwasm-exceptions -s PTHREAD_POOL_SIZE=4 -s MINIMAL_RUNTIME=1 --minify 0 node.cpp -o node.html
```

**Version of emscripten/emsdk:**
```text
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.0.1 (5ebe1d421445fa9a4a02c1efc6d42bde3ac90da2)
clang version 14.0.0 (https://github.com/llvm/llvm-project d98dfb2baabb647a6ac4c4f4399999cfc44433db)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: path/to/emsdk/upstream/bin
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.