Skip to content

Allow using the search path from -resource-dir with emcc -print-file-name#27082

Merged
sbc100 merged 6 commits into
emscripten-core:mainfrom
Diyou:emcc-relative-print-file-name
Jun 10, 2026
Merged

Allow using the search path from -resource-dir with emcc -print-file-name#27082
sbc100 merged 6 commits into
emscripten-core:mainfrom
Diyou:emcc-relative-print-file-name

Conversation

@Diyou

@Diyou Diyou commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

This allows emcc to change the search path when running it like: emcc -resource-dir=... -print-file-name=... which mimics the upstream clang behavior.

@sbc100

sbc100 commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Can you share the exact command line that cmake is using to ask for this path? I don't think this change should be necessary but perhaps I don't understand.

@sbc100

sbc100 commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

I think all we need to do here is make sure that libc++.modules.json is installed in the search dirs that emcc already uses.

$ emcc -print-search-dirs
programs: =/usr/local/google/home/sbc/dev/wasm/llvm-build/bin
libraries: =/usr/local/google/home/sbc/dev/wasm/emscripten/cache/sysroot/lib/wasm32-emscripten

If you install libc++.modules.json in ..emscripten/cache/sysroot/lib/wasm32-emscripten then it can be found by emcc -print-file-name.


$ emcc -print-file-name=foo.txt
foo.txt

$ touch /usr/local/google/home/sbc/dev/wasm/emscripten/cache/sysroot/lib/wasm32-emscripten/foo.txt

$ emcc -print-file-name=foo.txt
/usr/local/google/home/sbc/dev/wasm/emscripten/cache/sysroot/lib/wasm32-emscripten/foo.txt

Hopefully prevents the CI fail
@Diyou

Diyou commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

Can you share the exact command line that cmake is using to ask for this path?

It usually just runs em++ -print-file-name=libc++.modules.json which at the moment just prints the filename without the expected path.

execute_process(
    COMMAND
      "${CMAKE_CXX_COMPILER}"
      ${CMAKE_CXX_COMPILER_ID_ARG1}
      -print-file-name=libc++.modules.json
    ...

CMAKE_CXX_COMPILER_ID_ARG1 can be used here to add more flexibility.
Upstream clang allows something like
clang++ -resource-dir=<...> -print-file-name=libc++.modules.json

But yeah we probably should build and install the files properly anyways. Not too familiar with how system_libs.py works but I'm taking a look.

This reverts the initial changes in favor of -resource-dir
Comment thread emcc.py Outdated

resource_dir = [a for a in args if a.startswith(('-resource-dir=', '--resource-dir='))]
if resource_dir:
resource_dir = resource_dir[-1].split('=')[1]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this lines inside the if print_file_name block?

Then you can do something like this:

resource_dir_args = [a for a in args if a.startswith(('-resource-dir=', '--resource-dir='))]
if resource_dir_args:
    resource_dir = resource_dir_args[-1].split('=')[1]
else:
    resource_dir = cache.get_lib_dir(absolute=True)
fullpath = os.path.join(resource_dir, libname)

Comment thread test/test_other.py Outdated

@crossplatform
def test_print_file_name_with_resource_dir(self):
output = self.run_process([EMCC, '-print-file-name=emcc'], stdout=PIPE).stdout

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to emcc.py. The file emcc only exists on UNIX. On windows its called emcc.exe. But emcc.py always exists.

@Diyou Diyou force-pushed the emcc-relative-print-file-name branch from 68b261a to e0f8ab0 Compare June 10, 2026 16:44
@sbc100

sbc100 commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Can you update the PR title and description. This is really about adding support for -resource-dir I think?

Its not really specific to cmake and IIRC we don't want to be passing a custom -resource-dir in #27065 do we?

@Diyou Diyou changed the title Add logic to use a relative search path with emcc -print-file-name Allow using the search path from -resource-dir with emcc -print-file-name Jun 10, 2026
@Diyou

Diyou commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

IIRC we don't want to be passing a custom -resource-dir in #27065 do we?

Yeah but this can be used when testing until we have code to install the files propery

@sbc100 sbc100 merged commit cb6d2eb into emscripten-core:main Jun 10, 2026
34 of 36 checks passed
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

Successfully merging this pull request may close these issues.

2 participants