From 81ccbac103dbb972151ef3ca9d47001696cea2a1 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Tue, 19 Jul 2016 09:52:09 +1000 Subject: [PATCH 1/6] Close the temporary file before using it An instance of NamedTemporaryFile would keep the file open in the current process, however, on Windows, a opened filed is no accessible from any other process, and thus the following commands use this file would fail to execute. To fix this, this commit ensures that the temporary file has been closed before it is used anywhere else, and removes the temporary file after everything gets done. --- ports/geckolib/gecko_bindings/tools/regen.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ports/geckolib/gecko_bindings/tools/regen.py b/ports/geckolib/gecko_bindings/tools/regen.py index 82897ffdb8d..a4c2dde4d51 100755 --- a/ports/geckolib/gecko_bindings/tools/regen.py +++ b/ports/geckolib/gecko_bindings/tools/regen.py @@ -284,10 +284,11 @@ def build(objdir, target_name, kind_name=None, print("[RUSTC]... ", end='') sys.stdout.flush() - tests_file = tempfile.NamedTemporaryFile() + with tempfile.NamedTemporaryFile(delete=False) as f: + test_file = f.name output = None try: - rustc_command = ["rustc", output_filename, "--test", "-o", tests_file.name] + rustc_command = ["rustc", output_filename, "--test", "-o", test_file] output = subprocess.check_output(rustc_command, stderr=subprocess.STDOUT) output = output.decode('utf8') except subprocess.CalledProcessError as e: @@ -299,17 +300,17 @@ def build(objdir, target_name, kind_name=None, if verbose: print(output) - tests_file.file.close() print("[RUSTC_TEST]... ", end='') sys.stdout.flush() try: - output = subprocess.check_output([tests_file.name], stderr=subprocess.STDOUT) + output = subprocess.check_output([test_file], stderr=subprocess.STDOUT) output = output.decode('utf8') except subprocess.CalledProcessError as e: print("tests failed: ", e.output.decode('utf8')) return 1 + os.remove(test_file) print("OK") # TODO: this -3 is hacky as heck From 9eea2be09eff1432da971c9e156ea00a09f94dd9 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Tue, 19 Jul 2016 09:57:27 +1000 Subject: [PATCH 2/6] Use Cargo to run bindgen when possible Cargo would take care of stuff like library injecting, so that it works cross platform. This is necessary for Windows because Windows doesn't have things like LD_LIBRARY_PATH env var. --- ports/geckolib/gecko_bindings/tools/regen.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ports/geckolib/gecko_bindings/tools/regen.py b/ports/geckolib/gecko_bindings/tools/regen.py index a4c2dde4d51..eebe31305fc 100755 --- a/ports/geckolib/gecko_bindings/tools/regen.py +++ b/ports/geckolib/gecko_bindings/tools/regen.py @@ -125,9 +125,6 @@ COMPILATION_TARGETS = { "nsMainThreadPtrHolder", "nscolor", "nsFont", "FontFamilyList", "FontFamilyType", "nsIAtom", ], - "void_types": [ - "nsINode", "nsIDocument", "nsIPrincipal", "nsIURI", - ] } } @@ -178,7 +175,13 @@ def build(objdir, target_name, kind_name=None, (kind_name in current_target["build_kinds"])) if bindgen is None: - bindgen = "{}/rust-bindgen/target/debug/bindgen".format(TOOLS_DIR) + bindgen = os.path.join(TOOLS_DIR, "rust-bindgen") + + if os.path.isdir(bindgen): + bindgen = ["cargo", "run", "--manifest-path", + os.path.join(bindgen, "Cargo.toml"), "--"] + else: + bindgen = [bindgen] if output_filename is None: filename = "{}.rs".format(target_name) @@ -266,7 +269,7 @@ def build(objdir, target_name, kind_name=None, assert len(current_target["files"]) == 1 flags.append(current_target["files"][0].format(objdir)) - flags.insert(0, bindgen) + flags = bindgen + flags output = None try: output = subprocess.check_output(flags, stderr=subprocess.STDOUT) From cfc27b3df587daa6282097cb5bf09b368a35a8a0 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Tue, 19 Jul 2016 10:02:10 +1000 Subject: [PATCH 3/6] Convert platform dictionary to if-else Makes it more extendible. --- ports/geckolib/gecko_bindings/tools/regen.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ports/geckolib/gecko_bindings/tools/regen.py b/ports/geckolib/gecko_bindings/tools/regen.py index eebe31305fc..15c2a916bd4 100755 --- a/ports/geckolib/gecko_bindings/tools/regen.py +++ b/ports/geckolib/gecko_bindings/tools/regen.py @@ -135,11 +135,13 @@ def platform_dependent_defines(): if os.name == "posix": ret.append("-DOS_POSIX=1") - ret.append({ - "Linux": "-DOS_LINUX=1", - "Darwin": "-DOS_MACOSX=1", - # TODO: Windows? - }[platform.system()]) + system = platform.system() + if system == "Linux": + ret.append("-DOS_LINUX=1") + elif system == "Darwin": + ret.append("-DOS_MACOSX=1") + else: + raise Exception("Unknown platform") return ret From 49f7f5433144eec81639a288dc93b6d5fe5a63ce Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Tue, 19 Jul 2016 11:03:55 +1000 Subject: [PATCH 4/6] Add necessary flags for building MSVC binding Using C++14 mode is necessary because MSVC's std headers include some C++14 syntax. "utility" is converted to "/utility" to exclude MSVC's "xutility" header. --- ports/geckolib/gecko_bindings/tools/regen.py | 26 ++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/ports/geckolib/gecko_bindings/tools/regen.py b/ports/geckolib/gecko_bindings/tools/regen.py index 15c2a916bd4..6be27a22bae 100755 --- a/ports/geckolib/gecko_bindings/tools/regen.py +++ b/ports/geckolib/gecko_bindings/tools/regen.py @@ -21,7 +21,7 @@ COMPILATION_TARGETS = { # Flags common for all the targets. COMMON_BUILD_KEY: { "flags": [ - "-x", "c++", "-std=gnu++0x", + "-x", "c++", "-std=c++14", "-allow-unknown-types", "-no-bitfield-methods", "-no-type-renaming", "-no-namespaced-constants", "-DTRACING=1", "-DIMPL_LIBXUL", "-DMOZ_STYLO_BINDINGS=1", @@ -71,10 +71,11 @@ COMPILATION_TARGETS = { "gfxFontFamilyList.h", "gfxFontFeatures.h", "imgRequestProxy.h", "nsIRequest.h", "imgIRequest.h", "CounterStyleManager.h", "nsStyleConsts.h", "nsCSSValue.h", "SheetType.h", "nsIPrincipal.h", - "nsDataHashtable.h", "nsCSSScanner.h", "utility", "nsTArray", + "nsDataHashtable.h", "nsCSSScanner.h", "nsTArray", "pair", "SheetParsingMode.h", "StaticPtr.h", "nsProxyRelease.h", "mozilla/dom/AnimationEffectReadOnlyBinding.h", "/Types.h", # <- Disallow UnionTypes.h + "/utility", # <- Disallow xutility "nsINode.h", # <- For `NodeFlags`. ], "blacklist": [ @@ -140,6 +141,27 @@ def platform_dependent_defines(): ret.append("-DOS_LINUX=1") elif system == "Darwin": ret.append("-DOS_MACOSX=1") + elif system == "Windows": + ret.append("-DOS_WIN=1") + ret.append("-DWIN32=1") + ret.append("-use-msvc-mangling") + msvc_platform = os.environ["PLATFORM"] + if msvc_platform == "X86": + ret.append("--target=i686-pc-win32") + elif msvc_platform == "X64": + ret.append("--target=x86_64-pc-win32") + else: + raise Exception("Only MSVC builds are supported on Windows") + # For compatibility with MSVC 2015 + ret.append("-fms-compatibility-version=19") + # To enable the builtin __builtin_offsetof so that CRT wouldn't + # use reinterpret_cast in offsetof() which is not allowed inside + # static_assert(). + ret.append("-D_CRT_USE_BUILTIN_OFFSETOF") + # Enable hidden attribute (which is not supported by MSVC and + # thus not enabled by default with a MSVC-compatibile build) + # to exclude hidden symbols from the generated file. + ret.append("-DHAVE_VISIBILITY_HIDDEN_ATTRIBUTE=1") else: raise Exception("Unknown platform") From c3e20eb7f548e9f95aa643819ff64628b2611842 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Tue, 19 Jul 2016 11:08:40 +1000 Subject: [PATCH 5/6] Fix target check and use "all" as default target --- ports/geckolib/gecko_bindings/tools/regen.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/geckolib/gecko_bindings/tools/regen.py b/ports/geckolib/gecko_bindings/tools/regen.py index 6be27a22bae..9c4acfdaa43 100755 --- a/ports/geckolib/gecko_bindings/tools/regen.py +++ b/ports/geckolib/gecko_bindings/tools/regen.py @@ -376,7 +376,7 @@ def builds_for(target_name, kind): def main(): parser = argparse.ArgumentParser(description=DESCRIPTION) - parser.add_argument('--target', + parser.add_argument('--target', default="all", help='The target to build, either "structs" or "bindings"') parser.add_argument('--kind', help='Kind of build') @@ -398,7 +398,7 @@ def main(): print("\"{}\" doesn't seem to be a directory".format(args.objdir)) return 1 - if args.target != COMMON_BUILD_KEY and args.target != "all" and args.target not in COMPILATION_TARGETS: + if (args.target != "all" and args.target not in COMPILATION_TARGETS) or args.target == COMMON_BUILD_KEY: print("{} is not a valid compilation target.".format(args.target)) print("Valid compilation targets are:") for target in COMPILATION_TARGETS.keys(): From c30f7a3f69ed1ce40dff60e5329808f0cec16034 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Tue, 19 Jul 2016 14:22:26 +1000 Subject: [PATCH 6/6] Restore mistakenly removed code --- ports/geckolib/gecko_bindings/tools/regen.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ports/geckolib/gecko_bindings/tools/regen.py b/ports/geckolib/gecko_bindings/tools/regen.py index 9c4acfdaa43..d2cf66a0f54 100755 --- a/ports/geckolib/gecko_bindings/tools/regen.py +++ b/ports/geckolib/gecko_bindings/tools/regen.py @@ -126,6 +126,9 @@ COMPILATION_TARGETS = { "nsMainThreadPtrHolder", "nscolor", "nsFont", "FontFamilyList", "FontFamilyType", "nsIAtom", ], + "void_types": [ + "nsINode", "nsIDocument", "nsIPrincipal", "nsIURI", + ] } }