Skip to content

Use CMAKE_SYSROOT instead of EMSCRIPTEN_SYSROOT#27083

Open
xinitrcn1 wants to merge 1 commit into
emscripten-core:mainfrom
xinitrcn1:patch-1
Open

Use CMAKE_SYSROOT instead of EMSCRIPTEN_SYSROOT#27083
xinitrcn1 wants to merge 1 commit into
emscripten-core:mainfrom
xinitrcn1:patch-1

Conversation

@xinitrcn1

Copy link
Copy Markdown

No description provided.


# You **should** use CMAKE_SYSROOT, the one below is kept for
# compat for whichever soul used that variable...
set(CMAKE_SYSROOT "${_emcache_output}/sysroot")

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.

I think the reason we don't do this is that emcc on it own already automatically includes the sysroot.

i.e. you never need to do emcc --sysroot=/path/to/emscripten/sysroot since emcc already knows exactly where its sysroot is. Its not something we expect user to pass.

I think we don't really want cmake to inject and additional --sysroot since it would be redundant.

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.

If we set the compiler to clang then it would make sense to pass things like --sysroot and --target=wasm32-unknown-emscripten, but when we use the emcc wrapper around clang they are not needed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'm aware emcc itself uses --sysroot..

HOWEVER
many projects use ${CMAKE_SYSROOT} for other miscellany purpouses, most notably:

  • pkg search
  • pkgconfig
  • find package
  • checks
  • unholy usages of "absolute paths" that depend on ${CMAKE_SYSROOT}

For example shadPS4 uses CMAKE_SYSROOT for checks and stuff, is it bad design? No! As per documentation CMAKE_SYSROOT MUST point to a valid sysroot, otherwise it's not a valid toolchain.

@sbc100 sbc100 Jun 10, 2026

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.

For find package we set CMAKE_FIND_ROOT_PATH.

For pkg_config we set PKG_CONFIG_LIBDIR.

As I said, I'm to to keem on the idea of seeing --sysroot=/path/to/default/sysroot added to every emcc command line that cmake generates.

@bradking, sorry to loop you in again here, but I'm not sure what the best approach is here. We do use a sysroot, but its location is already know the emcc. I guess I'm looking for way to tell cmake about the sysroot without injecting superfluous/redundant compiler flags. Is that something is possible? Are we wrong to not set CMAKE_SYSROOT?

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.

Maybe something like DEFAULT_SYSROOT which would allow cmake to be aware or it without having to also inject --sysroot?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Nonstandard and as I mentioned above will break any projects which rightfully assume CMAKE_SYSROOT points to the actual sysroot

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Additionally, I'm pretty sure that the extra appended sysroot would be a no-op in most cases.

Even if so, I'd know that conforming to the expected set variables of CMake would be far more ideal than trying to use nonstandard.

For example I know a lot of projects who try to use assembly files because cmake's processor variable is set to the host instead of... well... something reasonable like "wasm64".

It's mostly due to the fact a lot of existing projects rightfully assume CMake provides accurate variables to the environment, what Emscripten is doing in this case is give a "half-answer" for most variables.

Of my particular note is CMAKE_SYSTEM_PROCESSOR (affects boost context, containers) and CMAKE_SYSROOT (shadPS4, openssl-cmakel) to metnion a few

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