Skip to content

Commit 9c65611

Browse files
authored
Ccache (#711)
* Add support for ccache. * Simplify ccache activation. * Fix macOS ccache build * Make ccache executable * Add Ninja build support. Change ccache name to git. * Fix merge conflict
1 parent 1ee4a9c commit 9c65611

File tree

2 files changed

+133
-1
lines changed

2 files changed

+133
-1
lines changed

emsdk.py

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,111 @@ def build_llvm(tool):
12291229
return success
12301230

12311231

1232+
def build_ninja(tool):
1233+
debug_print('build_ninja(' + str(tool) + ')')
1234+
root = os.path.normpath(tool.installation_path())
1235+
src_root = os.path.join(root, 'src')
1236+
success = git_clone_checkout_and_pull(tool.download_url(), src_root, tool.git_branch)
1237+
if not success:
1238+
return False
1239+
1240+
build_dir = llvm_build_dir(tool)
1241+
build_root = os.path.join(root, build_dir)
1242+
1243+
build_type = decide_cmake_build_type(tool)
1244+
1245+
# Configure
1246+
cmake_generator = CMAKE_GENERATOR
1247+
args = []
1248+
if 'Visual Studio 16' in CMAKE_GENERATOR: # VS2019
1249+
# With Visual Studio 16 2019, CMake changed the way they specify target arch.
1250+
# Instead of appending it into the CMake generator line, it is specified
1251+
# with a -A arch parameter.
1252+
args += ['-A', 'x64' if tool.bitness == 64 else 'x86']
1253+
args += ['-Thost=x64']
1254+
elif 'Visual Studio' in CMAKE_GENERATOR and tool.bitness == 64:
1255+
cmake_generator += ' Win64'
1256+
args += ['-Thost=x64']
1257+
1258+
cmakelists_dir = os.path.join(src_root)
1259+
success = cmake_configure(cmake_generator, build_root, cmakelists_dir, build_type, args)
1260+
if not success:
1261+
return False
1262+
1263+
# Make
1264+
success = make_build(build_root, build_type, 'x64' if tool.bitness == 64 else 'Win32')
1265+
1266+
if success:
1267+
bin_dir = os.path.join(root, 'bin')
1268+
mkdir_p(bin_dir)
1269+
exe_paths = [os.path.join(build_root, 'Release', 'ninja'), os.path.join(build_root, 'ninja')]
1270+
for e in exe_paths:
1271+
for s in ['.exe', '']:
1272+
ninja = e + s
1273+
if os.path.isfile(ninja):
1274+
dst = os.path.join(bin_dir, 'ninja' + s)
1275+
shutil.copyfile(ninja, dst)
1276+
os.chmod(dst, os.stat(dst).st_mode | stat.S_IEXEC)
1277+
1278+
return success
1279+
1280+
1281+
def build_ccache(tool):
1282+
debug_print('build_ccache(' + str(tool) + ')')
1283+
root = os.path.normpath(tool.installation_path())
1284+
src_root = os.path.join(root, 'src')
1285+
success = git_clone_checkout_and_pull(tool.download_url(), src_root, tool.git_branch)
1286+
if not success:
1287+
return False
1288+
1289+
build_dir = llvm_build_dir(tool)
1290+
build_root = os.path.join(root, build_dir)
1291+
1292+
build_type = decide_cmake_build_type(tool)
1293+
1294+
# Configure
1295+
cmake_generator = CMAKE_GENERATOR
1296+
args = ['-DZSTD_FROM_INTERNET=ON']
1297+
if 'Visual Studio 16' in CMAKE_GENERATOR: # VS2019
1298+
# With Visual Studio 16 2019, CMake changed the way they specify target arch.
1299+
# Instead of appending it into the CMake generator line, it is specified
1300+
# with a -A arch parameter.
1301+
args += ['-A', 'x64' if tool.bitness == 64 else 'x86']
1302+
args += ['-Thost=x64']
1303+
elif 'Visual Studio' in CMAKE_GENERATOR and tool.bitness == 64:
1304+
cmake_generator += ' Win64'
1305+
args += ['-Thost=x64']
1306+
1307+
cmakelists_dir = os.path.join(src_root)
1308+
success = cmake_configure(cmake_generator, build_root, cmakelists_dir, build_type, args)
1309+
if not success:
1310+
return False
1311+
1312+
# Make
1313+
success = make_build(build_root, build_type, 'x64' if tool.bitness == 64 else 'Win32')
1314+
1315+
if success:
1316+
bin_dir = os.path.join(root, 'bin')
1317+
mkdir_p(bin_dir)
1318+
exe_paths = [os.path.join(build_root, 'Release', 'ccache'), os.path.join(build_root, 'ccache')]
1319+
for e in exe_paths:
1320+
for s in ['.exe', '']:
1321+
ccache = e + s
1322+
if os.path.isfile(ccache):
1323+
dst = os.path.join(bin_dir, 'ccache' + s)
1324+
shutil.copyfile(ccache, dst)
1325+
os.chmod(dst, os.stat(dst).st_mode | stat.S_IEXEC)
1326+
1327+
cache_dir = os.path.join(root, 'cache')
1328+
open(os.path.join(root, 'emcc_ccache.conf'), 'w').write('''# Set maximum cache size to 10 GB:
1329+
max_size = 10G
1330+
cache_dir = %s
1331+
''' % cache_dir)
1332+
mkdir_p(cache_dir)
1333+
1334+
return success
1335+
1336+
12321337
# Emscripten asm.js optimizer build scripts:
12331338
def optimizer_build_root(tool):
12341339
build_root = tool.installation_path().strip()
@@ -1898,6 +2003,10 @@ def install_tool(self):
18982003
success = build_fastcomp(self)
18992004
elif hasattr(self, 'custom_install_script') and self.custom_install_script == 'build_llvm':
19002005
success = build_llvm(self)
2006+
elif hasattr(self, 'custom_install_script') and self.custom_install_script == 'build_ninja':
2007+
success = build_ninja(self)
2008+
elif hasattr(self, 'custom_install_script') and self.custom_install_script == 'build_ccache':
2009+
success = build_ccache(self)
19012010
elif hasattr(self, 'git_branch'):
19022011
success = git_clone_checkout_and_pull(url, self.installation_path(), self.git_branch)
19032012
elif url.endswith(ARCHIVE_SUFFIXES):
@@ -1925,7 +2034,7 @@ def install_tool(self):
19252034
success = emscripten_post_install(self)
19262035
elif self.custom_install_script == 'emscripten_npm_install':
19272036
success = emscripten_npm_install(self, self.installation_path())
1928-
elif self.custom_install_script in ('build_fastcomp', 'build_llvm'):
2037+
elif self.custom_install_script in ('build_fastcomp', 'build_llvm', 'build_ninja', 'build_ccache'):
19292038
# 'build_fastcomp' is a special one that does the download on its
19302039
# own, others do the download manually.
19312040
pass

emsdk_manifest.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,29 @@
476476
"windows_url": "mingw_7.1.0_64bit.zip",
477477
"activated_cfg": "MINGW_ROOT='%installation_dir%'",
478478
"activated_path": "%installation_dir%/bin"
479+
},
480+
{
481+
"id": "ninja",
482+
"version": "git-release",
483+
"bitness": 64,
484+
"url": "https://github.com/ninja-build/ninja.git",
485+
"git_branch": "release",
486+
"activated_cfg": "NINJA=%installation_dir%/bin",
487+
"activated_path": "%installation_dir%/bin",
488+
"cmake_build_type": "Release",
489+
"custom_install_script": "build_ninja"
490+
},
491+
{
492+
"id": "ccache",
493+
"version": "git-emscripten",
494+
"bitness": 64,
495+
"url": "https://github.com/juj/ccache.git",
496+
"git_branch": "emscripten",
497+
"activated_cfg": "EMCC_CCACHE=1",
498+
"activated_path": "%installation_dir%/bin",
499+
"activated_env": "EMCC_CCACHE=1;CCACHE_CONFIGPATH=%installation_dir%/emcc_ccache.conf",
500+
"cmake_build_type": "Release",
501+
"custom_install_script": "build_ccache"
479502
}
480503
],
481504

0 commit comments

Comments
 (0)