emscripten-core / emsdk

Emscripten SDK
http://emscripten.org
Other
2.96k stars 676 forks source link

Add documentation on how to use local emscripten #1291

Open ericoporto opened 10 months ago

ericoporto commented 10 months ago

Hi,

I think the documentation here in the readme has unfortunately aged: https://github.com/emscripten-core/emsdk#how-do-i-use-my-own-emscripten-github-fork-with-the-sdk

I tried to instead just cd upstream/emscripten as emscripten/main dir doesn't exist, but that didn't work either, because that will instead switch the remote of the emsdk local git repo as whole. My hack so far has been to rm -rf emscripten && ln -s ../../emscripten (this surprisingly works in git-bash on windows!), which has my outer clone of emscripten.

There is an issue that I don't know how to install emsdk and activate it, with my fork and branch, without getting

error: BINARYEN_ROOT is set to empty value  C:\Users\user\git\emsdk\upstream\emscripten\.emscripten

I don't know what is the right approach but I guess there is a process everyone here uses - it's just everyone is so used they forgot to document! 😆

ericoporto commented 10 months ago

I guess the docs that are here are supposed to mysteriously explain this in some other way, but find . -iname ".emscripten" comes up empty in the emsdk directory after clone or after ./emsdk install tot do all it's things... I have no idea what this file is or how it's supposed to work. The environment variable thing also doesn't work as it's apparently supposed to point to a dir that contains this mysterious file.

sbc100 commented 10 months ago

The .emscripten file in the emsdk directory is created by ./emsdk activate tot (which should be done after ./emsdk install tot). Once you have don't that setting EM_CONFIG=/path/to/emsdk/.emscripten should work.

As for the docs at https://github.com/emscripten-core/emsdk#how-do-i-use-my-own-emscripten-github-fork-with-the-sdk, I agree they are perhpas out-of-date or confusing. They are referring to how using a custom branch in the "build-from-source" scenario which is different way to use emsdk. Most folks don't use that method so we should probably either remove or update the question.

ericoporto commented 10 months ago

I don't understand this yet, I don't want to pass a "path/to/emsdk", I want to pass a path to emscripten! My local emscripten doesn't have that dot emscripten file, no matter what I do.

(but like, it's Sunday, I am ok getting a better answer during the week :p)

sbc100 commented 10 months ago

I don't understand this yet, I don't want to pass a "path/to/emsdk", I want to pass a path to emscripten! My local emscripten doesn't have that dot emscripten file, no matter what I do.

(but like, it's Sunday, I am ok getting a better answer during the week :p)

The .emscripten file in emsdk is the one you want. You don't need to have in your emscripten checkout.

To use your emscripten just make sure it comes first in the PATH. Then you run emcc it will find your local checkout in the PATH.. and then EM_CONFIG will tell your checkout of emscripten where to find other things like llvm and binaryen.

sbc100 commented 10 months ago

In other words the .emscripten file in the emsdk works for any/all versions of emscripten. It doesn't say where emscripten lives.. only where the dependencies live.

ericoporto commented 10 months ago

Sorry, what are supposed the contents of this file? I think it's not being created. I am on Windows. I would like to create it by hand.

sbc100 commented 10 months ago

The .emscripten file in the emsdk directory is created for you by the emsdk activate command, for example emsdk activate latest.

If you don't want to use emsdk and you want to build your own dependencies for some reason you can create a .emscripten file in your emscripten checkout. You can use ./emcc --generate-config to have emscripten create a dummy config file for you. See https://emscripten.org/docs/building_from_source/configuring_emscripten_settings.html#configuring-emscripten-settings-when-manually-building-from-source for more on that.

However, I would strongly recommend using emsdk since that avoids build the dependencies yourself.

shrinktofit commented 8 months ago

I had this question as well. I want to figure out why DWARF was not correctly generated. So I want to git clone the emscripten-core repository and debug. Briefly, I want:

What I tried:

Here is my final solution:

  1. emsdk install 3.1.43 then emsdk activate 3.1.43

    This install and activate the prebuilt dependencies.

  2. ./emsdk_env

    This makes the dependencies available.

  3. Set environment variable EMSCRIPTEN = <path-to-my-emscripten-fork>.

    This might be optional. My project use this env var to locate emscripten CMake toolchain.

  4. Set environment variable EM_CONFIG = <path-to-emsdk>/.emscripten.

    I don't know why this is required, but I have to do this.

sbc100 commented 7 months ago

Your solution looks good. The EM_CONFIG environment is most important thing which tells emcc where to find its dependencies.

The EMSCRIPTEN environment variable is not used by emscripten itself these days.