detect.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import os
  2. import string
  3. import sys
  4. def is_active():
  5. return True
  6. def get_name():
  7. return "JavaScript"
  8. def can_build():
  9. return ("EMSCRIPTEN_ROOT" in os.environ or "EMSCRIPTEN" in os.environ)
  10. def get_opts():
  11. from SCons.Variables import BoolVariable
  12. return [
  13. BoolVariable('javascript_eval', 'Enable JavaScript eval interface', True),
  14. ]
  15. def get_flags():
  16. return [
  17. ('tools', False),
  18. ('module_theora_enabled', False),
  19. # Disabling the mbedtls module reduces file size.
  20. # The module has little use due to the limited networking functionality
  21. # in this platform. For the available networking methods, the browser
  22. # manages TLS.
  23. ('module_mbedtls_enabled', False),
  24. ]
  25. def create(env):
  26. # remove Windows' .exe suffix
  27. return env.Clone(tools=['textfile', 'zip'], PROGSUFFIX='')
  28. def escape_sources_backslashes(target, source, env, for_signature):
  29. return [path.replace('\\','\\\\') for path in env.GetBuildPath(source)]
  30. def escape_target_backslashes(target, source, env, for_signature):
  31. return env.GetBuildPath(target[0]).replace('\\','\\\\')
  32. def configure(env):
  33. ## Build type
  34. if (env["target"] == "release"):
  35. # Use -Os to prioritize optimizing for reduced file size. This is
  36. # particularly valuable for the web platform because it directly
  37. # decreases download time.
  38. # -Os reduces file size by around 5 MiB over -O3. -Oz only saves about
  39. # 100 KiB over -Os, which does not justify the negative impact on
  40. # run-time performance.
  41. env.Append(CCFLAGS=['-Os'])
  42. env.Append(LINKFLAGS=['-Os'])
  43. elif (env["target"] == "release_debug"):
  44. env.Append(CCFLAGS=['-O2', '-DDEBUG_ENABLED'])
  45. env.Append(LINKFLAGS=['-O2'])
  46. # retain function names at the cost of file size, for backtraces and profiling
  47. env.Append(LINKFLAGS=['--profiling-funcs'])
  48. elif (env["target"] == "debug"):
  49. env.Append(CCFLAGS=['-O1', '-D_DEBUG', '-g', '-DDEBUG_ENABLED'])
  50. env.Append(LINKFLAGS=['-O1', '-g'])
  51. env.Append(LINKFLAGS=['-s', 'ASSERTIONS=1'])
  52. ## Compiler configuration
  53. env['ENV'] = os.environ
  54. if ("EMSCRIPTEN_ROOT" in os.environ):
  55. env.PrependENVPath('PATH', os.environ['EMSCRIPTEN_ROOT'])
  56. elif ("EMSCRIPTEN" in os.environ):
  57. env.PrependENVPath('PATH', os.environ['EMSCRIPTEN'])
  58. env['CC'] = 'emcc'
  59. env['CXX'] = 'em++'
  60. env['LINK'] = 'emcc'
  61. env['RANLIB'] = 'emranlib'
  62. # Emscripten's ar has issues with duplicate file names, so use cc
  63. env['AR'] = 'emcc'
  64. env['ARFLAGS'] = '-o'
  65. if (os.name == 'nt'):
  66. # use TempFileMunge on Windows since some commands get too long for
  67. # cmd.exe even with spawn_fix
  68. # need to escape backslashes for this
  69. env['ESCAPED_SOURCES'] = escape_sources_backslashes
  70. env['ESCAPED_TARGET'] = escape_target_backslashes
  71. env['ARCOM'] = '${TEMPFILE("%s")}' % env['ARCOM'].replace('$SOURCES', '$ESCAPED_SOURCES').replace('$TARGET', '$ESCAPED_TARGET')
  72. env['OBJSUFFIX'] = '.bc'
  73. env['LIBSUFFIX'] = '.bc'
  74. ## Compile flags
  75. env.Append(CPPPATH=['#platform/javascript'])
  76. env.Append(CPPFLAGS=['-DJAVASCRIPT_ENABLED', '-DUNIX_ENABLED', '-DPTHREAD_NO_RENAME', '-DTYPED_METHOD_BIND', '-DNO_THREADS'])
  77. env.Append(CPPFLAGS=['-DGLES3_ENABLED'])
  78. # These flags help keep the file size down
  79. env.Append(CPPFLAGS=["-fno-exceptions", '-DNO_SAFE_CAST', '-fno-rtti'])
  80. if env['javascript_eval']:
  81. env.Append(CPPFLAGS=['-DJAVASCRIPT_EVAL_ENABLED'])
  82. ## Link flags
  83. env.Append(LINKFLAGS=['-s', 'BINARYEN=1'])
  84. env.Append(LINKFLAGS=['-s', 'ALLOW_MEMORY_GROWTH=1'])
  85. env.Append(LINKFLAGS=['-s', 'USE_WEBGL2=1'])
  86. env.Append(LINKFLAGS=['-s', 'EXTRA_EXPORTED_RUNTIME_METHODS="[\'FS\']"'])
  87. env.Append(LINKFLAGS=['-s', 'INVOKE_RUN=0'])
  88. env.Append(LINKFLAGS=['-s', 'NO_EXIT_RUNTIME=1'])
  89. # TODO: Move that to opus module's config
  90. if 'module_opus_enabled' in env and env['module_opus_enabled']:
  91. env.opus_fixed_point = "yes"