Skip to content

Commit 2e02343

Browse files
authored
Fix update_openmp.py, openmp README. NFC (emscripten-core#27383)
The version of openmp that we imported was based on LLVM commit 1823581ecb rather than an emscripten-libs branch. This change updates the update_openmp.py script, and I verified that running it against 1823581ecb was a no-op aside from the one-line downstream patch I made in emscripten-core#27289.
1 parent c9cdff6 commit 2e02343

2 files changed

Lines changed: 35 additions & 60 deletions

File tree

system/lib/openmp/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
llvm's OpenMP
22
-------------
33

4+
Note: This version of openmp is actually based on 1823581ecb but
5+
we are in the process of updating it.
6+
47
These files are from the llvm-project based on release 21.1.8.
58

69
We maintain a local fork of llvm-project that contains any Emscripten

system/lib/update_openmp.py

100644100755
Lines changed: 32 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
# found in the LICENSE file.
66

77
import os
8-
import sys
98
import shutil
109
import subprocess
1110

12-
13-
script_dir = os.path.abspath(os.path.dirname(__file__))
14-
emscripten_root = os.path.dirname(os.path.dirname(script_dir))
15-
default_llvm_dir = os.path.join(os.path.dirname(emscripten_root), 'llvm-project')
11+
from update_common import (
12+
clean_dir,
13+
copy_tree,
14+
default_llvm_dir,
15+
emscripten_root,
16+
parse_args,
17+
script_dir,
18+
)
1619

1720
# system/lib/openmp (to be updated)
1821
local_root = os.path.join(script_dir, 'openmp')
@@ -21,77 +24,47 @@
2124
local_prebuilt = os.path.join(local_root, 'prebuilt')
2225

2326
# Files to ignore during copy_tree
24-
excludes = [
25-
'doc',
26-
'build',
27-
'tests',
28-
'CMakeFiles',
29-
'libgomp.a',
30-
'libiomp5.a',
31-
'libomp.a',
32-
]
33-
34-
35-
def clean_dir(dirname):
36-
for f in os.listdir(dirname):
37-
full = os.path.join(dirname, f)
38-
if os.path.isdir(full):
39-
shutil.rmtree(full)
40-
else:
41-
os.remove(full)
42-
43-
44-
def copy_tree(upstream_dir, local_dir):
45-
for f in os.listdir(upstream_dir):
46-
full = os.path.join(upstream_dir, f)
47-
if f not in excludes:
48-
if os.path.isdir(full):
49-
if not os.path.exists(os.path.join(local_dir, f)):
50-
os.makedirs(os.path.join(local_dir, f))
51-
copy_tree(full, os.path.join(local_dir, f))
52-
else:
53-
shutil.copy2(full, os.path.join(local_dir, f))
27+
excludes = (
28+
'doc',
29+
'build',
30+
'tests',
31+
'CMakeFiles',
32+
'libgomp.a',
33+
'libiomp5.a',
34+
'libomp.a',
35+
)
5436

5537

5638
def main():
57-
if len(sys.argv) > 1:
58-
llvm_dir = os.path.join(os.path.abspath(sys.argv[1]))
59-
else:
60-
llvm_dir = default_llvm_dir
39+
llvm_dir = parse_args(default_llvm_dir, 'llvm_dir')
6140

6241
# Output directory for build
6342
output_dir = os.path.join(emscripten_root, 'out')
6443
build_dir = os.path.join(output_dir, 'build_openmp')
6544

6645
# LLVM/OpenMP folder containing latest version
67-
upstream_runtimes = os.path.join(llvm_dir, 'runtimes/')
68-
upstream_root = os.path.join(llvm_dir, 'openmp/')
46+
upstream_runtimes = os.path.join(llvm_dir, 'runtimes')
47+
upstream_root = os.path.join(llvm_dir, 'openmp')
6948
upstream_runtime_root = os.path.join(upstream_root, 'runtime/src')
7049
assert os.path.exists(upstream_runtime_root)
7150

7251
# Build output paths
7352
upstream_build_src = os.path.join(build_dir, 'openmp/runtime/src') # contains various *.a and generated *.h
7453

7554
# Remove old version
76-
clean_dir(local_root)
77-
os.mkdir(local_src)
78-
os.mkdir(local_include)
79-
os.mkdir(local_prebuilt)
55+
clean_dir(local_src)
56+
clean_dir(local_include)
57+
clean_dir(local_prebuilt)
8058

8159
# Update source
82-
copy_tree(upstream_runtime_root, local_src)
60+
copy_tree(upstream_runtime_root, local_src, excludes)
8361

8462
# Generates header files for OpenMP library build
85-
subprocess.run(
86-
[
87-
'emcmake',
88-
'cmake',
89-
'-S',
90-
f'{upstream_runtimes}',
91-
'-B',
92-
f'{build_dir}',
93-
'-G',
94-
'Ninja',
63+
subprocess.run([
64+
os.path.join(emscripten_root, 'emcmake'), 'cmake',
65+
'-S', upstream_runtimes,
66+
'-B', build_dir,
67+
'-G', 'Ninja',
9568
'-DLLVM_ENABLE_RUNTIMES=openmp',
9669
'-DLLVM_DEFAULT_TARGET_TRIPLE=wasm32-unknown-emscripten',
9770
'-DOPENMP_ENABLE_LIBOMPTARGET=OFF',
@@ -103,9 +76,8 @@ def main():
10376
'-DLIBOMP_ENABLE_SHARED=OFF',
10477
'-DLIBOMP_ARCH=wasm32',
10578
'-DOPENMP_ENABLE_LIBOMPTARGET_PROFILING=OFF',
106-
]
107-
)
108-
subprocess.run(['cmake', '--build', '.'], cwd=build_dir)
79+
], check=True)
80+
subprocess.run(['cmake', '--build', '.'], cwd=build_dir, check=True)
10981

11082
# Update license file
11183
shutil.copy2(os.path.join(upstream_root, 'LICENSE.TXT'), local_root)
@@ -116,7 +88,7 @@ def main():
11688
shutil.copy2(os.path.join(upstream_build_src, file), local_include)
11789

11890
# Update generated header files
119-
built_files = ['kmp_config.h', 'kmp_i18n_id.inc', 'kmp_i18n_default.inc']
91+
built_files = ['kmp_config.h', 'kmp_i18n_id.inc', 'kmp_i18n_default.inc']
12092
for file in built_files:
12193
shutil.copy2(os.path.join(upstream_build_src, file), local_prebuilt)
12294

0 commit comments

Comments
 (0)