Skip to content

libnethack#385

Merged
nhcopier merged 42 commits intoNetHack:NetHack-3.7from
apowers313:libnethack
Oct 5, 2020
Merged

libnethack#385
nhcopier merged 42 commits intoNetHack:NetHack-3.7from
apowers313:libnethack

Conversation

@apowers313
Copy link
Copy Markdown
Contributor

This PR has two new builds:

  • libnethack.a -- a unix-ish library that can be linked against
  • nethack.js -- a WebAssembly build of NetHack that can be run in the browser or node.js. This is also prepared to be published as a public npm module under sys/lib/npm-package.

See sys/lib/README.md for more details details about how to build and the library APIs.

@apowers313
Copy link
Copy Markdown
Contributor Author

Published here: https://www.npmjs.com/package/@neth4ck/neth4ck

I created a new neth4ck organization on NPM. If anyone wants to be added to the organization to control packages let me know and I will happily add you.

(note: npm doesn't allow organizations or packages with hack in the name, thus h4ck)

@moon-chilled
Copy link
Copy Markdown

WASM is better than __EMSCRIPTEN__. Emscripten needn't be the only c compiler targeting webassembly.

@apowers313
Copy link
Copy Markdown
Contributor Author

@moon-chilled Not sure it matters much in the context of this PR since we can treat alternate WebAssembly approaches similar to other toolchains in the Unix build. That said I'm having a hard time parsing your comment and I'd like to learn more. My understanding is that "WASM" is just short for "WebAssembly" and the alternative to creating WASM with Emscripten is a process that wouldn't scale to building NetHack.

Is there a trick or a toolchain that I'm unaware of?

@nhmall
Copy link
Copy Markdown
Contributor

nhmall commented Oct 5, 2020

I've resolved the new conflicts upstream and merged the changes (I think). They will be available later this evening.
The PR had been sitting dormant for 22 days, but was updated while merging earlier today. The updates conflicted
because the PR was modified from original upon merge:

  1. instead of separate new Makefiles, I adapted it to use the existing sys/unix/Makefiles and the new cross-compiler insertion and overrides, similar to how other recent cross-compiles are doing it.
  2. In the updates that will be merged in a few hours, sys/lib/libnethackmain.c is included now, since more extensive code edits have been added in the changes today.

@nhmall nhmall closed this Oct 5, 2020
@nhmall nhmall reopened this Oct 5, 2020
@nhmall nhmall self-assigned this Oct 5, 2020
@nhcopier nhcopier merged commit 751d5ef into NetHack:NetHack-3.7 Oct 5, 2020
@nhmall
Copy link
Copy Markdown
Contributor

nhmall commented Oct 6, 2020

Assuming that you have already installed emscripten on your macOS or Linux system,

cd sys/unix ; ./setup.sh hints/macOS.2020 ; cd ../..
or
cd sys/unix ; ./setup.sh hints/linux.2020 ; cd ../..

make CROSS_TO_WASM=1 (results in targets/wasm)
make WANT_LIBNH=1 (resulting libnethack.a in src)

@apowers313 : thanks for starting this. We'll see where it might eventually go.

nhcopier pushed a commit that referenced this pull request Oct 6, 2020
Credit: The initial Web Assembly cross compile was found in a pull request:
            #385
        by apowers313. The pull request was merged with some accompanying
        NetHack source tree integration changes in early October 2020.

Cross-compiler used: emscripten
Cross-compiler url: https://emscripten.org/docs/getting_started/downloads.html

    Here's a brief guide to obtaining the cross-compiler sources via git and
    building it on your system.

    For Ubuntu, the build prerequisite packages for building the compiler can
    be easily obtained:

        sudo apt-get install python3 cmake default-jre

    For macOS, you will need to install Xcode, git, cmake, Python 3.5 or new
    (at time of this writing).

    After installing the prerequite packages above, obtain the cross-compiler
    via git and build it from the directory of your choice using steps similar
    to these:

            git clone https://github.com/emscripten-core/emsdk.git
            cd emsdk
            git pull
            ./emsdk install latest
            ./emsdk activate latest
            source ./emsdk_env.sh

    The steps above reflect what was outlined at this url at the time
    of writing:

            https://emscripten.org/docs/getting_started/downloads.html

    That is the definitive source and trumps anything documented here.

    On your linux host, prepare to cross-compile NetHack as follows:

        cd sys/unix ; sh setup.sh hints/linux.2020 ; cd ../..
        make fetch-lua

    On your macOS host, prepare to cross-compile NetHack as follows:

        cd sys/unix ; sh setup.sh hints/macOS.2020 ; cd ../..
        make fetch-lua

    Then, cross-compile to targets/wasm as follows:

        make CROSS_TO_WASM=1

    You can build src/nethacklib.a from pull request 385 as follows:

        make WANT_LIBNH=1

    Do not add any additional windowport interfaces to your build
    (such as WANT_WIN_TTY=1 WANT_WIN_CURSES=1 WANT_WIN_X11=1 or
    WANT_WIN_QT=1) as those aren't applicable to the Web Assembly
    or nethacklib builds. A "shim" pseudo-windowport is included
    from pull request 385.

    Result: As mentioned, the wasm cross-compile will end up in
            targets/wasm and the nethacklib.a will end up
            src.

    The cross-compiler hints additions are enclosed inside ifdef sections
    and shouldn't interfere with the non-cross-compile builds using
    hints/linux.2020 or hints/macOS.2020.
@apowers313 apowers313 mentioned this pull request Oct 9, 2020
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.

4 participants