Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to cross-compile magnum-based project for Emscripten #490

Closed
Xeverous opened this issue Jan 3, 2021 · 6 comments
Closed

Unable to cross-compile magnum-based project for Emscripten #490

Xeverous opened this issue Jan 3, 2021 · 6 comments

Comments

@Xeverous
Copy link

Xeverous commented Jan 3, 2021

I have successfully installed Emscripten on Windows but when I'm trying to build my project for Emscripten the configuration fails with this error:

CMake Error at external/magnum/CMakeLists.txt:295 (include):
  include could not find load file:

    UseEmscripten

magnum/CMakeLists.txt seems to try to include UseEmscripten.cmake but this file is located in magnum/toolchains/modules. I think that the relative path is wrong - the file is in a different directory:

magnum/CMakeLists.txt

Lines 294 to 296 in 515bfce

if(CORRADE_TARGET_EMSCRIPTEN)
include(UseEmscripten)
endif()

Few notes:

  • I have pulled newest magnum, magnum-integration and corrade (all from their master).
  • It's unclear to me in which shell and what state should I have before running commands desribed here: https://doc.magnum.graphics/corrade/building-corrade.html#building-corrade-cross-emscripten - it seems to me that corrade docs coflict with this emscripten docs which tell me to use emcmake cmake and then input my all flags as usual. emcmake adds extra cmake flags, including CMAKE_TOOLCHAIN_FILE which has different path value from one recommended in corrade docs.
  • I get the same error regardless of whether I use cmake ... or emcmake cmake ... in emscripten-activated shell.
  • For native 64-bit Windows build I'm building the project using submoduled magnum and corrade repositories, added by add_subdirectory within my CMake files. I would like to keep this approach. It works very well.
  • I would like to build my project as for the native build, just with small differences as on emscripten docs (emcmake cmake ... instead of cmake ... and emmake make instead of make). A lot of my dependencies are recursively git-submoduled and are added using add_subdirectory in my CMake files (this also applies to magnum and corrade). This forms some dependency chain in CMake recipes and when I tell CMake to build everything it performs incremental build flawlessly.
@Xeverous
Copy link
Author

Xeverous commented Jan 3, 2021

Attempted cmake commands looked like this:

(emcmake) cmake ../.. -G "MinGW Makefiles" \
    ([...] some my-project-specific-cmake-flags) \
    -DCORRADE_RC_EXECUTABLE="C:/Program Files (x86)/Corrade/bin/corrade-rc.exe" \
    -DEMSCRIPTEN_PREFIX="[...]/emsdk/upstream/emscripten" \
    (-DCMAKE_TOOLCHAIN_FILE="[...]/corrade/toolchains/generic/Emscripten.cmake")

all ends in the same error

@mosra mosra added this to the 2020.0b milestone Jan 4, 2021
@mosra
Copy link
Owner

mosra commented Jan 4, 2021

Hi,

it seems to me that corrade docs coflict with this emscripten docs which tell me to use emcmake cmake and then input my all flags as usual

No no, there's no conflict -- it's just that historically Emscripten's toolchain files were unreliable, broken in particular versions and doing too much / being too automatic, which is why Magnum provides its own, and adds toolchains/modules to CMAKE_MODULE_PATH, which then makes the UseEmscripten be found properly.

Nowadays, ideally Magnum should be independent of the toolchain used and work with either, so this is a bug :) Unfortunately for you, people learned to use Magnum's toolchains exclusively for their Emscripten projects and so you're the first to discover this issue. Sorry about that. The UseEmscripten module isn't actually needed by Magnum itself, only by some of its tests, so I can include it only in that case. I did a similar change for Corrade not so long agao (mosra/corrade@9bc3950) so something similar needs to be done here as well.

Attempted cmake commands looked like this [...] all ends in the same error

It shouldn't be (if you really use vanilla CMake), not sure what the (emcmake) prompt actually implies. FYI CMAKE_TOOLCHAIN_FILE is read only on the first ever CMake run and it's ignored after, so starting out with a fresh (clear) build directory and using Magnum's toolchain should work.

... well until I fix it, at least. I'll let you know when the dependency on UseEmscripten is removed so you can use the upstream toolchain instead.

@Xeverous
Copy link
Author

Xeverous commented Jan 4, 2021

historically Emscripten's toolchain files were unreliable, broken in particular versions and doing too much / being too automatic

Yes, I'm currently affected by 2 bugs:

The first one doesn't look like it is a toolchain file problem.


I cleared the build dir and I can do the build (without using toolchain file provided by magnum). The problematic part was -G "MinGW Makefiles" - it was just unneeded.

not sure what the (emcmake) prompt actually implies

I'm not sure either but I noticed:

  • It is already run in emscripten's shell, so it the shell has modified env variables
  • the prompt adds some cmake flags, interestingly CMAKE_TOOLCHAIN_FILE and -G "MinGW Makefiles" but in different order

So in short, the solution was to use it just as emscripten recommends: use emcmake ... and emmake ... prompts and don't use anything from magnum that impacts the toolchain state.

@mosra
Copy link
Owner

mosra commented Jan 9, 2021

The UseEmscripten module wasn't actually needed for anything at all, so I removed it completely in 8eb7557; will do similar changes in remaining projects.

@mosra mosra closed this as completed Jan 9, 2021
@mosra
Copy link
Owner

mosra commented May 18, 2021

Hm, looks like I closed too soon. Reopening until I'm sure the LTO / ar related issues are resolved. And mosra/toolchains#13 is also related.

@mosra
Copy link
Owner

mosra commented Sep 3, 2023

The LTO and ar issues are finally fixed with mosra/toolchains#14 and the toolchains submodule is updated to include these in 14477c8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

2 participants