Skip to content

[feature request] Option for a custom compiler wrapper path for emmake / emconfigure / emcmake (EM_COMPILER_WRAPPER?) #12256

Open

Description

@vadimkantorov

Original title: [feature request] emcc option for copy-pasting a third-party binary instead of compiling #12256

While porting a recent texlive to emscripten (https://github.com/vadimkantorov/busytex), I found useful the following pattern: overriding CC="python3 ccskip.py /some/native/binary1 /some/native/binary2 -- emcc" when calling make. This allows skipping compiling some intermediate build-time tools and using copy-pasting their native versions instead.

Is there another recommended way for achieveing this? If not, I propose adding some option to emcc that would achieve the same. and would be more discoverable.

Some things that I had to copy-over:

CCSKIP_wasm_icu = python3 $(ROOT)/ccskip.py "$(ROOT)/build/native/texlive/libs/icu/icu-build/bin/icupkg" "$(ROOT)/build/native/texlive/libs/icu/icu-build/bin/pkgdata" --
CCSKIP_wasm_freetype2 = python3 $(ROOT)/ccskip.py $(ROOT)/build/native/texlive/libs/freetype2/ft-build/apinames --
CCSKIP_wasm_xetex = python3 $(ROOT)/ccskip.py $(addprefix $(ROOT)/build/native/texlive/texk/web2c, ctangle otangle tangle tangleboot ctangleboot tieweb2c) $(addprefix $(ROOT)/build/native/texlive/texk/web2c/web2c, fixwrites makecpool splitup web2c) --

Activity

  1. sbc100 commented on Sep 17, 2020

    @sbc100
    Collaborator

    Ideally a given build system would support cross compiling fully and be aware of the difference between the host toolchain and the target toolchain.

    It sounds like this tool is designed to work around build system that don't fully support cross compiling and assume that build-time builds are built with the same compiler?

    Perhaps such tool is useful, but maybe its not specific to emscripten and would be useful for all cross compilers? Or is there something emscripten-specific about this?

  2. sbc100 commented on Sep 17, 2020

    @sbc100
    Collaborator

    BTW I'm not saying I would necessarily be against adding such a tool to emscripten if it was integrated the correct way.

  3. sbc100 commented on Sep 17, 2020

    @sbc100
    Collaborator

    Also just to be clear if you skip binary foo then all the object files that go into foo are still compiled right? Only the final link is skipped and replaced with a copy?

  4. vadimkantorov commented on Sep 17, 2020

    @vadimkantorov
    Author

    Also just to be clear if you skip binary foo then all the object files that go into foo are still compiled right? Only the final link is skipped and replaced with a copy?

    This tools is a hack to have something just enough to get TexLive and its many dependencies to compile, so yes, it just skips compiling the wasm tools (another solution is to let them being compiled, and replace them after, but this requires a very delicate surgery of the build process), object files are still being built

    It sounds like this tool is designed to work around build system that don't fully support cross compiling and assume that build-time builds are built with the same compiler?

    Correct!

    (I didn't try to use cross-compling support of TexLive, it might work, but all previous work at this didn't do this, so I didn't either)

  5. vadimkantorov commented on Sep 17, 2020

    @vadimkantorov
    Author

    A more general solution "for porting hacks" would be some DSL or config that specifies some behavior on some condition (e.g. output object matches some glob). Behaviors may be append/redefine some define or CFLAG, append/prepend linker flags. Otherwise complex ports become a journey into studying the build system.

    Some Makefiles propagate CC env variable to children, some do not etc. Sometimes resetting make CFLAGS=... is not propagated and make -e CFLAGS would be needed. But that destroys preconfigured CFLAGS. So I resort to CC=... or -e CC=... just to override some CFLAGS.

    Sometimes it's not easily possible to configure some part of source tree without destroying configuration for other part, that's why I have to build dependencies in some particular order in my busytex setup

  6. vadimkantorov commented on Sep 17, 2020

    @vadimkantorov
    Author

    Is it possible to set some compiler-wrapper (e.g. some tool like one described above) to be used by emmake instead of emcc/em++?

  7. sbc100 commented on Sep 17, 2020

    @sbc100
    Collaborator

    The implementation of emmake is just to run make with a specific environment set. This is the code that creates the environment (from building.py)

    def get_building_env(cflags=[]):                                                                     
      env = os.environ.copy()                                                                            
      # point CC etc. to the em* tools.                                                                  
      env['CC'] = EMCC                                                                                   
      env['CXX'] = EMXX                                                                                  
      env['AR'] = EMAR                                                                                      
      env['LD'] = EMCC                                                                                      
      env['NM'] = LLVM_NM                                                                                   
      env['LDSHARED'] = EMCC                                                                                
      env['RANLIB'] = EMRANLIB                                                                              
      env['EMSCRIPTEN_TOOLS'] = path_from_root('tools')                                                     
      if cflags:                                                                                            
        env['CFLAGS'] = env['EMMAKEN_CFLAGS'] = ' '.join(cflags)                                            
      env['HOST_CC'] = CLANG_CC                                                                             
      env['HOST_CXX'] = CLANG_CXX                                                                           
      env['HOST_CFLAGS'] = "-W" # if set to nothing, CFLAGS is used, which we don't want                    
      env['HOST_CXXFLAGS'] = "-W" # if set to nothing, CXXFLAGS is used, which we don't want                
      env['PKG_CONFIG_LIBDIR'] = path_from_root('system', 'local', 'lib', 'pkgconfig') + os.path.pathsep + path_from_root('system', 'lib', 'pkgconfig')                                                               env['PKG_CONFIG_PATH'] = os.environ.get('EM_PKG_CONFIG_PATH', '')                                  
      env['EMSCRIPTEN'] = path_from_root()                                                                  
      env['PATH'] = path_from_root('system', 'bin') + os.pathsep + env['PATH']                              
      env['CROSS_COMPILE'] = path_from_root('em') # produces /path/to/emscripten/em , which then can have 'cc', 'ar', etc appended to it 
      return env           
    

    I would recommend creating your own script that configures the environment you wan can uses your compiler wrapper script. Then it can function completely independently of emscripten.

  8. vadimkantorov commented on Sep 18, 2020

    @vadimkantorov
    Author

    Then I'd also need to dump emcmake and emconfigure :(

  9. sbc100 commented on Sep 18, 2020

    @sbc100
    Collaborator

    I think we could add an extra EM_COMPILER_WRAPPER environment variable that emcmake and emconfigure could honor?

  10. sbc100 commented on Sep 18, 2020

    @sbc100
    Collaborator

    Might be useful for things distcc too.

  11. vadimkantorov commented on Sep 18, 2020

    @vadimkantorov
    Author

    For now, would executing something like this remove the need of emconfigure / emcmake / make (in some simple case)?

    EMROOT=$(dirname $(which emcc))
    
    export CC=emcc
    export CXX=em++
    export AR=emar
    export LD=emcc
    export NM=LLVM_NM
    export LDSHARED=emcc
    export RANLIB=emranlib
    export EMSCRIPTEN_TOOLS="$EMROOT/tools"
    export HOST_CC=clang
    export HOST_CXX=clang++
    export HOST_CFLAGS=-W
    export HOST_CXXFLAGS=-W
    export PKG_CONFIG_LIBDIR="$EMROOT/system/local/lib/pkgconfig:$EMROOT/system/lib/pkgconfig"
    export PKG_CONFIG_PATH="$EM_PKG_CONFIG_PATH"
    export EMSCRIPTEN=$EMROOT
    export PATH="$EMROOT/system/bin:$EMROOT/../bin:$PATH"
    export CROSS_COMPILE=$EMROOT/em
    
  12. vadimkantorov commented on Sep 18, 2020

    @vadimkantorov
    Author

    Hmm, my configure did not like this approach: "configure: WARNING: you should use --build, --host, --target"

  13. changed the title [-][feature request] emcc option for copy-pasting a third-party binary instead of compiling[/-] [+][feature request] Option for a custom compiler wrapper path for emmake / emconfigure / emcmake (EM_COMPILER_WRAPPER?)[/+] on Sep 24, 2020
  14. stale commented on Sep 26, 2021

    @stale

    This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.

  15. vadimkantorov commented on Sep 27, 2021

    @vadimkantorov
    Author

    The issue is still standing...

  16. vadimkantorov commented on Dec 29, 2022

    @vadimkantorov
    Author

    The implementation of emmake is just to run make with a specific environment set. This is the code that creates the environment (from building.py)

    def get_building_env(cflags=[]):                                                                     
      env = os.environ.copy()                                                                            
      # point CC etc. to the em* tools.                                                                  
      env['CC'] = EMCC                                                                                   
      env['CXX'] = EMXX                                                                                  
      env['AR'] = EMAR                                                                                      
      env['LD'] = EMCC                                                                                      
      env['NM'] = LLVM_NM                                                                                   
      env['LDSHARED'] = EMCC                                                                                
      env['RANLIB'] = EMRANLIB                                                                              
      env['EMSCRIPTEN_TOOLS'] = path_from_root('tools')                                                     
      if cflags:                                                                                            
        env['CFLAGS'] = env['EMMAKEN_CFLAGS'] = ' '.join(cflags)                                            
      env['HOST_CC'] = CLANG_CC                                                                             
      env['HOST_CXX'] = CLANG_CXX                                                                           
      env['HOST_CFLAGS'] = "-W" # if set to nothing, CFLAGS is used, which we don't want                    
      env['HOST_CXXFLAGS'] = "-W" # if set to nothing, CXXFLAGS is used, which we don't want                
      env['PKG_CONFIG_LIBDIR'] = path_from_root('system', 'local', 'lib', 'pkgconfig') + os.path.pathsep + path_from_root('system', 'lib', 'pkgconfig')                                                               env['PKG_CONFIG_PATH'] = os.environ.get('EM_PKG_CONFIG_PATH', '')                                  
      env['EMSCRIPTEN'] = path_from_root()                                                                  
      env['PATH'] = path_from_root('system', 'bin') + os.pathsep + env['PATH']                              
      env['CROSS_COMPILE'] = path_from_root('em') # produces /path/to/emscripten/em , which then can have 'cc', 'ar', etc appended to it 
      return env           
    

    I would recommend creating your own script that configures the environment you wan can uses your compiler wrapper script. Then it can function completely independently of emscripten.

    It may also be that some makefiles use HOSTCC convention instead of HOST_CC...

  17. vadimkantorov commented on Aug 11, 2026

    @vadimkantorov
    Author

    It can be sometimes much simpler to have such a compiler wrapper, than properly solving https://tug.org/texinfohtml/tlbuild.html#Cross-problems-1 (can be simpler to pretend that target compiler produced a host artifact than making sure that one given binary artifact is compiled with host compiler)

  18. sbc100 commented on Aug 11, 2026

    @sbc100
    Collaborator

    Can this issue be closed since #12380 added EM_COMPILER_WRAPPER ?

  19. sbc100 commented on Aug 11, 2026

    @sbc100
    Collaborator

    Oh, no sorry, EM_COMPILER_WRAPPER is a wrapper for the inner clang process.

  20. vadimkantorov commented on Aug 14, 2026

    @vadimkantorov
    Author

    Yeah, I propose to support a global environment variable which emcc (or at least emconfigure/emmake/emcmake) could somehow support, this wrapper script could do some custom processing (e.g. flags modification or instead invoke the host compiler) before delegate-invoking the base emcc.

    For complex cases, this can allow to centralize all hacks in one compiler wrapper script

  21. vadimkantorov commented on Aug 20, 2026

    @vadimkantorov
    Author

    Maybe emcc/em++ could detect this env variable and if set, unset it and invoke the wrapper and exit. The wrapper can itself call back into emcc/em++ with this variable unset.

    I do it to modify some flags depending on the artifact being built or to copy-out native pre-built executable when cannot set properly host compiler.

  22. sbc100 commented on Aug 20, 2026

    @sbc100
    Collaborator

    Wouldn't it be possible to create these wrappers today without emcc support?

    $ export PATH=/path/to/wrapper:/path/to/real/esmcripten
    $ which emcc
    /path/to/wrapper/emcc
    $ which emconfigure
    /path/to/wrapper/emconfigure
    

    Then you can do whatever you want in your wapper version and then invoke the real emcc by looking for the next thing in the path?

  23. vadimkantorov commented on Aug 20, 2026

    @vadimkantorov
    Author

    Wouldn't emconfigure/emmake still fetch out abspaths for proper emcc and set CC accordingly, thus circumventing the PATH trick?

  24. sbc100 commented on Aug 20, 2026

    @sbc100
    Collaborator

    Oh yes, sorry I forget that detail.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions