emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.83k stars 3.31k forks source link

file_packager.py: REMOTE_PACKAGE_BASE does not work when data is not a the root #21289

Open lyrixx opened 9 months ago

lyrixx commented 9 months ago

Please include the following in your bug report:

I'm using emscripten/tools/file_packager.py and I noticed something strange, and I guess it's an error

https://github.com/emscripten-core/emscripten/blob/21f25339df9c6aa8c288297de73236e6aaa79582/tools/file_packager.py#L765-L770

As you can see, the var REMOTE_PACKAGE_BASE has value js_manipulation.escape_for_js_string(remote_package_name), which is equals to remote_package_name = os.path.basename(package_name)

If during the packing phase, I want to put the data in a subfolder, let's say build/php-web.data with the option --js-output=build/php-web.data.js, I got the following code:

var PACKAGE_NAME = 'build/php-web.data';
var REMOTE_PACKAGE_BASE = 'php-web.data';

And this looks wrong, because the data are in the build/ directory.


The full command to reproduce:

'python3' \
    '/emsdk/upstream/emscripten/tools/file_packager.py' \
        'build/php-web.data' \
        '--use-preload-cache' \
        '--lz4' \
        '--preload', '/src' \
        '--js-output=build/php-web.data.js' \
        '--no-node' \
        '--exclude' '*/.*' \
        '--export-name=createPhpModule'
sbc100 commented 9 months ago

In your case it would make sense if the PPACKAGE_NAME was relative to the output JS name?

Perhaps we can just use os.path.relpath to achieve that?

lyrixx commented 9 months ago

Perhaps we can just use os.path.relpath to achieve that?

yes 👍🏼 This is what I did. I rewrite it in my build process and work as expected. See https://lyrixx.github.io/jolitypo-playground/build/php-web.mjs

      var REMOTE_PACKAGE_BASE = '/jolitypo-playground/build/php-web.data';

Should I send a PR?

sbc100 commented 9 months ago

Yes please. Do you think this is the behavior that everybody will want?

lyrixx commented 9 months ago

I'm quite new to this wasm world ! But I think yes. Everyone want the correct path 😅