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

[suggestion] move /scripts to a separate repo or do some other thing to support cross-compile #93

Open
RadND opened this issue Jun 11, 2023 · 3 comments

Comments

@RadND
Copy link

RadND commented Jun 11, 2023

TLDR : i'm trying to compile mcmap to wasm using emscripten , /scripts makes it hard to do that "cross-compile"

Rencently , player of my creative server want to render some small part of map (e.g. a single floor of a big building ) , due to the truncate on y-axis this can't be achieved by dynmap. So I plan to compile mcmap to wasm to make they render thier building in browser. The problem here is because tools in /scripts got compiled to wasm format , too. It can't run when called in MakeFile.

I know I can tell players to use the Windows GUI one, but it's difficult for them to read English , and it seems the program isn't able to read spigot server world (except overworld , other show error "... not a save folder")

Make json->bson optional also helps ,since it's the only tool got called by now.

This change will make cross-compile easier in general , not only c++->wasm

@spoutn1k
Copy link
Owner

spoutn1k commented Jun 11, 2023

Hey that's super cool ! I thought about using wasm too recently but got busy.

Moving the scripts would be a major pain, I am sure we can figure out a way to do it without moving them. Would you be able to share what you are doing to compile so that I can take a look and configure/update the build system ?

The json->bson tool is also essential, as it allows to have the colors in plain text in the source code. I can make it optional if the BSON file has already been generated - but having a binary blob in the sources is a no-go.

EDIT: I believe I added a log window in the GUI. If you could open it and see what the error is when opening other dimension that would be really helpful.

@RadND
Copy link
Author

RadND commented Jun 12, 2023

my environment is wsl Ubuntu 22.04.2 LTS

  1. install emscripten (I choose to clone their SDK repo)
  2. download/git clone all code of dependencies
    when search the web i found zlib-ng , it can be ABI compatible to zlib ,so I choose it. Can you change zlib to zlib-ng ? start another issue i guess.
  3. loop{compile,see errors,change}
    I failed to make any header-only lib working,so I change them to "normal"(can't figure out a word to describe this version) one in all CMakeList.txt in mcmap/

at the end of the day the workspace look like this:

/mnt/c/Users/radnd/Documents/Code/
  /emsdk
  /fmt-master
  /libpng
  /spdlog-1.x
  /mcmap
  /zlib-ng

compile command like this , cd to their ./build folder first

#zlib-ng
emcmake cmake .. -DZLIB_COMPAT=on -DBUILD_SHARED_LIBS=OFF
cmake --build ..

#lib-png
emcmake cmake .. -DPNG_SHARED=OFF -DPNG_STATIC=ON -DZLIB_LIBRARY="../../zlib-ng" -DZLIB_INCLUDE_DIR="../../zlib-ng"

#fmt
emcmake cmake .. -DBUILD_SHARED_LIBS=OFF -DFMT_TEST=OFF -DCMAKE_CXX_COMPILER="/mnt/c/Users/radnd/Documents/Code/emsdk/upstream/emscripten/em++"

#spdlog
emcmake cmake .. -DSPDLOG_FMT_EXTERNAL=ON -DSPDLOG_BUILD_EXAMPLE=OFF -DSPDLOG_BUILD_TESTS=OFF

#mcmap
#I didn't managed to make relative path work
emcmake cmake .. -DCMAKE_BUILD_TYPE=Release -DZLIB_LIBRARY="/mnt/c/Users/radnd/Documents/Code/zlib-ng/build/libz.a" -DZLIB_INCLUDE_DIR="/mnt/c/Users/radnd/Documents/Code/zlib-ng/build/" -DPNG_PNG_INCLUDE_DIR="/mnt/c/Users/radnd/Documents/Code/libpng/build" -DPNG_LIBRARY="/mnt/c/Users/radnd/Documents/Code/libpng/build" 

We never try to build in nether/end , so it's actually not a problem to me , would be good to make code handle this special case anyway,here is the log i reproduced on my temp local server

\world-dir\
  \world
    level.dat
    \region
    ...
  \world_nether
    level.dat
    \DIM-1
      \region
    ...
  \world_the_end
    \DIM1
    ...


blahblah... world-dir/world_nether\region' is of an unexpected format           #when in \world_nether
blahblah... world-dir/world_nether/DIM-1\level.dat': No such file or directory  #when in \world_nether\DIM-1

@spoutn1k
Copy link
Owner

spoutn1k commented Jun 30, 2023

I got mcmap to compile using the following steps.

json2bson compiles but fails to execute; the rest of the scripts create an error when compiled, I need to add a CMake flag to skip them. However, json2bson's sole purpose is to use the JSON library to compile the color JSON to BSON (and embed it in the binary). This is bypassed if the BSON file already exists; you can either do that like the above gist or by creating a file src/colors.bson with the contents of this gist.

The core library mcmap_core compiles but you will need to create a WASM interface to use it.

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

No branches or pull requests

2 participants