Skip to content

Commit 38e50d4

Browse files
committed
Add build.sh script; add pthread_sigmask patch
build.sh simplifies running the build and automatically enables Emscripten if appropriate. Emscripten doesn't support pthread_sigmask, so disable it. Add support for multiple patches.
1 parent b3fa5db commit 38e50d4

File tree

6 files changed

+63
-13
lines changed

6 files changed

+63
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ env/
44
llvm/
55
llvm.orig/
66
**/__pycache__/
7+
emsdk-portable

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@
1212
against Clang 3.9.
1313
* CMake - Currently, version 3.4.3 or newer is required. See [LLVM
1414
documentation](http://llvm.org/docs/CMake.html) for details.
15-
2. Run the build script.
15+
2. Optionally, create a symlink to `emsdk-portable` (or place the
16+
`emsdk-portable` directory in the `emllvm` directory) so that the build script
17+
can automatically find it.
18+
3. Run the build script.
1619

1720
```
1821
cd emllvm
19-
python3 -m builder
22+
./build.sh
2023
```
2124
2225
## Further reading
2326
2427
* http://llvm.org/docs/HowToCrossCompileLLVM.html
28+
* http://llvm.org/docs/CMake.html
2529
* https://github.com/kripken/llvm.js - may be outdated, but it has some useful
2630
info

build.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
cd "$(dirname "$0")"
6+
7+
if ! which emcc >& /dev/null; then
8+
if [ -d emsdk-portable ]; then
9+
. emsdk-portable/emsdk_env.sh
10+
fi
11+
fi
12+
13+
python3 -m builder

builder/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def main():
3636
Untar('llvm/tools/clang'),
3737
Download(llvm_releases + 'clang-tools-extra-%s.src.tar.xz' % version),
3838
Untar('llvm/tools/clang/tools/extra'),
39-
Patch('llvm-%s.patch' % version),
39+
Patch(['llvm-%s.patch' % version, 'pthread_sigmask.patch']),
4040
MakeBuildDirectory(),
4141
Configure(),
4242
Make()

builder/commands.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,26 +130,30 @@ def execute(self):
130130

131131

132132
class Patch(Command):
133-
def __init__(self, patch_file):
134-
self.patch_file = patch_file
133+
def __init__(self, patch_files):
134+
self.patch_files = patch_files
135135

136-
def patch_path(self):
137-
return os.path.join(self.config.root, 'patches', self.patch_file)
136+
def patch_path(self, patch_file):
137+
return os.path.join(self.config.root, 'patches', patch_file)
138138

139-
def check(self):
139+
def is_applied(self, patch_file):
140140
# If a reversed patch would succeed, then the patch has been applied.
141141
# From https://unix.stackexchange.com/a/86872/615
142-
with open(self.patch_path()) as f:
142+
with open(self.patch_path(patch_file)) as f:
143143
return 0 == subprocess.call(['patch', '-p0', '--reverse', '--dry-run'], stdin=f,
144144
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
145145

146146
def execute(self):
147-
with open(self.patch_path()) as f:
148-
subprocess.check_call(['patch', '-p0', '--backup'], stdin=f)
147+
for patch_file in self.patch_files:
148+
if not self.is_applied(patch_file):
149+
with open(self.patch_path(patch_file)) as f:
150+
subprocess.check_call(['patch', '-p0', '--backup'], stdin=f)
149151

150152
def rollback(self):
151-
with open(self.patch_path()) as f:
152-
subprocess.check_call(['patch', '-p0', '--reverse'], stdin=f)
153+
for patch_file in self.patch_files:
154+
if self.is_applied(patch_file):
155+
with open(self.patch_path(patch_files)) as f:
156+
subprocess.check_call(['patch', '-p0', '--reverse'], stdin=f)
153157

154158

155159
class MakeBuildDirectory(Command):

patches/pthread_sigmask.patch

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
diff -ur llvm.orig/lib/Support/Unix/Process.inc llvm/lib/Support/Unix/Process.inc
2+
--- llvm.orig/lib/Support/Unix/Process.inc 2016-05-04 12:56:51.000000000 -0400
3+
+++ llvm/lib/Support/Unix/Process.inc 2017-05-13 11:17:15.682268600 -0400
4+
@@ -252,8 +252,11 @@
5+
if (sigfillset(&FullSet) < 0)
6+
return std::error_code(errno, std::generic_category());
7+
// Atomically swap our current signal mask with a full mask.
8+
- sigset_t SavedSet;
9+
-#if LLVM_ENABLE_THREADS
10+
+ sigset_t SavedSet __attribute__((maybe_unused));
11+
+#if __EMSCRIPTEN__
12+
+ // Emscripten doesn't support signals, so we don't need to block signals.
13+
+ // See https://kripken.github.io/emscripten-site/docs/porting/pthreads.html
14+
+#elif LLVM_ENABLE_THREADS
15+
if (int EC = pthread_sigmask(SIG_SETMASK, &FullSet, &SavedSet))
16+
return std::error_code(EC, std::generic_category());
17+
#else
18+
@@ -268,7 +271,9 @@
19+
ErrnoFromClose = errno;
20+
// Restore the signal mask back to what we saved earlier.
21+
int EC = 0;
22+
-#if LLVM_ENABLE_THREADS
23+
+#if __EMSCRIPTEN__
24+
+ // No need to block signals - see above
25+
+#elif LLVM_ENABLE_THREADS
26+
EC = pthread_sigmask(SIG_SETMASK, &SavedSet, nullptr);
27+
#else
28+
if (sigprocmask(SIG_SETMASK, &SavedSet, nullptr) < 0)

0 commit comments

Comments
 (0)