Skip to content
This repository was archived by the owner on Nov 12, 2022. It is now read-only.

Commit 4d4466f

Browse files
author
bors-servo
authored
Auto merge of #302 - fitzgen:bindings-all, r=Ms2ger
Add the `etc/bindings-all.py` script to orchestrate bindings generation The `bindings-all.py` script will make sure that you don't accidentally try and use DEBUG bindings for a non-DEBUG build or vice-versa. It orchestrates all of building, regenerating and testing new SpiderMonkey bindings. Running this script on fedora regenerates the linux_64 bindings exactly as they are on the smup branch for me. I think this is a large usability improvement over what we do now. r? @Ms2ger @nox <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-mozjs/302) <!-- Reviewable:end -->
2 parents bbf907b + c9e056c commit 4d4466f

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

etc/bindings-all.py

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env python3
2+
3+
import os, subprocess, sys
4+
5+
def usage_and_exit():
6+
print("")
7+
print("Usage:")
8+
print(" bindings-all.py <platform> <bindgen> <clang_lib_path>")
9+
print("")
10+
print(" Regenerates both debugmozjs and non-debugmozjs bindings and")
11+
print(" tests them.")
12+
print("")
13+
print(" <platform> One of 'linux_32', 'linux_64', 'macos_64',")
14+
print(" 'windows_gcc_64', or 'windows_msvc14_64'.")
15+
print("")
16+
print(" <bindgen> The path to bindgen")
17+
print("")
18+
print(" <clang_lib_path> The path to the directory of clang library files")
19+
sys.exit(1)
20+
21+
# Validate arguments.
22+
23+
if len(sys.argv) != 4:
24+
usage_and_exit()
25+
26+
[platform, bindgen, clang_lib_path] = sys.argv[1:]
27+
28+
try:
29+
["linux_32", "linux_64", "macos_64", "windows_gcc_64", "windows_msvc14_64"].index(platform)
30+
except ValueError:
31+
print("error: {} is not a valid platform".format(platform))
32+
usage_and_exit()
33+
34+
bindgen = os.path.abspath(bindgen)
35+
if not (os.path.isfile(bindgen) and os.access(bindgen, os.X_OK)):
36+
print("error: {} is not executable".format(bindgen))
37+
usage_and_exit()
38+
39+
clang_lib_path = os.path.abspath(clang_lib_path)
40+
if not os.path.isdir(clang_lib_path):
41+
print("error: {} is not a directory".format(bindgen))
42+
43+
# Go to the root of our repo.
44+
os.chdir(os.path.dirname(sys.argv[0]))
45+
os.chdir("..")
46+
47+
def run(cmd, **kwargs):
48+
"""Run the given shell command.
49+
50+
Pass through kwargs (like env=...) to `subprocess.Popen`. Wait for the
51+
subprocess to complete, and throw an exception if it didn't exit with 0.
52+
53+
"""
54+
print("{}: Running".format(sys.argv[0]), cmd)
55+
proc = subprocess.Popen(cmd, **kwargs)
56+
proc.wait()
57+
if proc.returncode != 0:
58+
raise subprocess.CalledProcessError(proc.returncode, cmd)
59+
60+
# Set up the environment needed to run bindgen.
61+
bindgen_env = os.environ.copy()
62+
bindgen_env["LIBCLANG_PATH"] = clang_lib_path
63+
if platform.startswith("macos"):
64+
bindgen_env["DYLD_LIBRARY_PATH"] = clang_lib_path
65+
else:
66+
bindgen_env["LD_LIBRARY_PATH"] = clang_lib_path
67+
68+
# Run our builds.
69+
70+
BUILDS = [
71+
# Release build
72+
("", []),
73+
# DEBUG build
74+
("_debug", ["--features", "debugmozjs"])
75+
]
76+
77+
for (build_modifier, extra_cargo_flags) in BUILDS:
78+
run(["cargo", "clean"])
79+
run(["cargo", "build", "-p", "mozjs_sys"] + extra_cargo_flags)
80+
run(["./etc/bindings.sh"], env=bindgen_env)
81+
run(["mv", "out.rs", "src/jsapi_{}{}.rs".format(platform, build_modifier)])
82+
run(["cargo", "test"] + extra_cargo_flags)

0 commit comments

Comments
 (0)