emscripten-core / emscripten-core/emscripten

--embed-file with `@` duplicates the root location (e.g. `/assets/assets` instead of `/assets`)

Open
#23,684 1 comment 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

**Version of emscripten/emsdk:**
```bash
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.3 (a9651ff57165f5710bb09a5fe52590fd6ddb72df)
clang version 21.0.0git (https:/github.com/llvm/llvm-project 6dc41a639334b913e762f65410fcd14a722b137f)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: $HOME/.../emsdk/upstream/bin
```

According to the [documentation](https://emscripten.org/docs/porting/files/packaging_files.html#modifying-file-locations-in-the-virtual-file-system), when embedding a subdirectory structure, it is possible to change the location in the virtual filesystem where the embeded files will appear by putting a `@` symbol at the appropriate place.

However, when this location is not the root, it seems to double, i.e. consider the following filesystem layout:
```
test.cpp
assets/test/asset_file.txt
```
When I build test.cpp with the following command:
```
em++ --embed-file $PWD/assets@/test test.cpp -o test_em.js
```
I would expect the virtual filesystem layout to contain
```
/test/asset_file.txt
```
In reality, it looks as follows:
```
/test/test/asset_file.txt
```
(i.e. the `/test` prefix is duplicated)

Similarly, when I build test.cpp with the following command:
```
em++ --embed-file $PWD/@assets/test test.cpp -o test_em.js
```
I get

```
/assets/test/assets/test/asset_file.txt
```
The `test.cpp` file is a very simple program which just does a `ls -R` on the `/` of the virtual FS:
```cpp
#include
#include
namespace fs = std::filesystem;
int main() {
for (const auto & entry : fs::recursive_directory_iterator("/")) {
std::cout << entry.path() << std::endl;
}
}
```

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.