summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.appveyor.yml6
-rw-r--r--build_extra/rust/get_version_hash.py14
-rw-r--r--build_extra/rust/rust.gni23
3 files changed, 36 insertions, 7 deletions
diff --git a/.appveyor.yml b/.appveyor.yml
index 9e37f3640..da96eb2b3 100644
--- a/.appveyor.yml
+++ b/.appveyor.yml
@@ -306,12 +306,6 @@ before_build:
Set-FilesNeeded -Auto -Path $outputs -Reason "Build dependency graph"
build_script:
- # Attempt to work around multiple rustc instances messing with the same file
- # when building in parallel.
- # TODO: fix this properly.
- - ps: ninja -C $env:DENO_BUILD_PATH -j 1
- build_extra/rust:winapi build_extra/rust:winapi-0.2
-
- python tools\build.py
- ps: Set-FilesNeeded -Auto -Reason "Build finished"
diff --git a/build_extra/rust/get_version_hash.py b/build_extra/rust/get_version_hash.py
new file mode 100644
index 000000000..7d37cbf9b
--- /dev/null
+++ b/build_extra/rust/get_version_hash.py
@@ -0,0 +1,14 @@
+# Copyright 2018 the Deno authors. All rights reserved. MIT license.
+
+# This script computes the sha256sum of the first command line argument, and
+# writes a few hex digits of it to stdout. It is used by rust.gni to derive a
+# unique string (without dots/special characters) from a crate version number.
+
+from hashlib import sha256
+import sys
+
+if len(sys.argv) != 2:
+ raise Exception('Expected exactly one argument.')
+
+hash = sha256(sys.argv[1]).hexdigest()
+sys.stdout.write(hash[0:8])
diff --git a/build_extra/rust/rust.gni b/build_extra/rust/rust.gni
index ece21d6c0..586953917 100644
--- a/build_extra/rust/rust.gni
+++ b/build_extra/rust/rust.gni
@@ -118,9 +118,30 @@ template("run_rustc") {
]
if (defined(crate_version)) {
+ # Compute the sha256sum of the version number. See comments below.
+ # Note that we do this only if there are multiple versions of this crate.
+ hash =
+ exec_script("get_version_hash.py", [ crate_version ], "trim string")
+
args += [
+ # In our build setup, all crates are built in the same directory. The
+ # actual build outputs have unique names (e.g. 'foo-1.2.3.rlib'), but
+ # rustc also creates many temp files (e.g. 'foo.crate.metadata.rcgu.bc',
+ # 'foo.foo0.rcgu.o'), and with those files, name collisions do occur.
+ # This causes random failures during parallel builds and on CI.
+ #
+ # These name conflicts can be avoided by setting `-C extra-filename=` to
+ # some unique value. Unfortunately the version number as such can't be
+ # used: everything after the first dot (.) is thrown away, so winapi-0.2
+ # vs. winapi-0.3 would still have conflicts -- so we use a hash instead.
+ "-C",
+ "extra-filename=$hash",
+
+ # Rustc blows up if a target (directly or indirectly) depends on two+
+ # crates that have the same name *and* the same metadata. So we use the
+ # hash to give 'metadata' a unique value too (any unique value will do).
"-C",
- "metadata=$crate_version",
+ "metadata=$hash",
]
}