Skip to content

Commit

Permalink
Use Cargo's target directory sharing.
Browse files Browse the repository at this point in the history
This speeds up `./mach build --dev` followed by `./mach build-cef` by a
large amount, and also speeds up other build combos found in our CI.
  • Loading branch information
metajack committed Jun 15, 2015
1 parent ce30807 commit a023708
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 30 deletions.
2 changes: 1 addition & 1 deletion cargo-nightly-build
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2015-04-14
2015-06-15
2 changes: 1 addition & 1 deletion components/servo/.cargo/config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
paths = ["../../support/android-rs-glue"]

[target.arm-linux-androideabi]
linker = "../../support/android-rs-glue/apk-builder/target/debug/apk-builder"
linker = "../../target/debug/apk-builder"
ar = "arm-linux-androideabi-ar"
15 changes: 5 additions & 10 deletions components/util/resource_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,29 @@ pub fn resources_dir_path() -> PathBuf {
Some(ref path) => PathBuf::from(path),
None => {
// FIXME: Find a way to not rely on the executable being
// under `<servo source>/components/servo/target`
// or `<servo source>/components/servo/target/release`.
// under `<servo source>[/$target_triple]/target/debug`
// or `<servo source>[/$target_triple]/target/release`.
let mut path = env::current_exe().ok().expect("can't get exe path");
path.pop();
path.push("resources");
if !path.is_dir() { // resources dir not in same dir as exe?
path.pop();
// exe is probably in target/{debug,release} so we need to go back to topdir
path.pop();
path.pop();
path.pop();
path.push("resources");
if !path.is_dir() { // self_exe_path() is probably in .../target/release
if !path.is_dir() {
// exe is probably in target/$target_triple/{debug,release} so go back one more
path.pop();
path.pop();
path.push("resources");
if !path.is_dir() { // self_exe_path() is probably in .../target/release
path.pop();
path.pop();
path.push("resources");
}
}
}
path
}
}
}


pub fn read_resource_file(relative_path_components: &[&str]) -> io::Result<Vec<u8>> {
let mut path = resources_dir_path();
for component in relative_path_components {
Expand Down
4 changes: 2 additions & 2 deletions etc/ci/upload_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cd "$(dirname $0)/../.."

./mach doc
# etc/doc.servo.org/index.html overwrites $(mach rust-root)/doc/index.html
cp etc/doc.servo.org/* components/servo/target/doc/
cp etc/doc.servo.org/* target/doc/

ghp-import -n components/servo/target/doc
ghp-import -n target/doc
git push -qf https://${TOKEN}@github.com/servo/doc.servo.org.git gh-pages
2 changes: 1 addition & 1 deletion ports/cef/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ crate-type = ["dylib"]
log = "*"
url = "*"
libc = "*"
objc = "0.1"

[dependencies.servo]
path = "../../components/servo"
Expand Down Expand Up @@ -72,6 +71,7 @@ git = "https://github.com/servo/rust-stb-image"
git = "https://github.com/servo/gleam"

[target.x86_64-apple-darwin.dependencies]
objc = "0.1"
cocoa = "*"
core-foundation = "*"
core-graphics = "*"
Expand Down
4 changes: 2 additions & 2 deletions ports/gonk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Run `./mach build-gonk` from the root directory

## Copy the files to the Flame

To reduce the size of libmozjs.so (`ports/gonk/target/arm-linux-androideabi/build/mozjs-sys-*/out/libmozjs.so`),
To reduce the size of libmozjs.so (`target/arm-linux-androideabi/build/mozjs-sys-*/out/libmozjs.so`),
you can run `strip` on it. Use the one in your toolchain (`$ANDROID_TOOLCHAIN/bin/arm-linux-androideabi-strip libmozjs.so`).

Make sure the device is on, connected to wifi, with high or no screen timeout.
Expand All @@ -64,7 +64,7 @@ adb remount
adb push /path/to/stripped/mozjs.so system/lib
# Copy b2s
adb push ports/gonk/target/arm-linux-androideabi system/bin
adb push target/arm-linux-androideabi system/bin
# Copy resources
adb shell mkdir sdcard/servo
Expand Down
2 changes: 1 addition & 1 deletion python/servo/build_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def build(self, target=None, release=False, dev=False, jobs=None,
opts = params or []
features = []

base_path = path.join("components", "servo", "target")
base_path = self.get_target_dir()
release_path = path.join(base_path, "release", "servo")
dev_path = path.join(base_path, "debug", "servo")

Expand Down
11 changes: 10 additions & 1 deletion python/servo/command_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,14 @@ def cargo_build_id(self):
self._cargo_build_id = open(filename).read().strip()
return self._cargo_build_id

def get_target_dir(self):
if "CARGO_TARGET_DIR" in os.environ:
return os.environ["CARGO_TARGET_DIR"]
else:
return path.join(self.context.topdir, "target")

def get_binary_path(self, release, dev):
base_path = path.join("components", "servo", "target")
base_path = self.get_target_dir()
release_path = path.join(base_path, "release", "servo")
dev_path = path.join(base_path, "debug", "servo")

Expand Down Expand Up @@ -199,6 +205,9 @@ def build_env(self, gonk=False, hosts_file_path=None):
if "CARGO_HOME" not in env:
env["CARGO_HOME"] = self.config["tools"]["cargo-home-dir"]

if "CARGO_TARGET_DIR" not in env:
env["CARGO_TARGET_DIR"] = path.join(self.context.topdir, "target")

if extra_lib:
if sys.platform == "darwin":
env["DYLD_LIBRARY_PATH"] = "%s%s%s" % \
Expand Down
5 changes: 2 additions & 3 deletions python/servo/post_build_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ def doc(self, params):
if not path.exists(path.join(self.config["tools"]["rust-root"], "doc")):
Registrar.dispatch("bootstrap-rust-docs", context=self.context)
rust_docs = path.join(self.config["tools"]["rust-root"], "doc")
docs = path.join(
self.context.topdir, "components", "servo", "target", "doc")
docs = path.join(self.get_target_dir(), "doc")
if not path.exists(docs):
os.makedirs(docs)

Expand Down Expand Up @@ -167,4 +166,4 @@ def serve_docs(self):
self.doc([])
import webbrowser
webbrowser.open("file://" + path.abspath(path.join(
self.servo_crate(), "target", "doc", "servo", "index.html")))
self.get_target_dir(), "doc", "servo", "index.html")))
5 changes: 2 additions & 3 deletions python/servo/testing_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,11 @@ def ensure_built_tests(self):

def find_test(self, prefix):
target_contents = os.listdir(path.join(
self.context.topdir, "components", "servo", "target", "debug"))
self.get_target_dir(), "debug"))
for filename in target_contents:
if filename.startswith(prefix + "-"):
filepath = path.join(
self.context.topdir, "components", "servo",
"target", "debug", filename)
self.get_target_dir(), "debug", filename)

if path.isfile(filepath) and os.access(filepath, os.X_OK):
return filepath
Expand Down
3 changes: 1 addition & 2 deletions python/tidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
# Generated and upstream code combined with our own. Could use cleanup
"components/script/dom/bindings/codegen/*",
"components/style/properties/mod.rs",
"components/servo/target/*",
"ports/gonk/target/*",
"target/*",
"ports/gonk/src/native_window_glue.cpp",
"ports/cef/*",

Expand Down
2 changes: 1 addition & 1 deletion tests/power/PowerMeasure.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def PowerCollector(OutputDir, Benchmarks, LayoutThreads, Renderer):
power_dir, "power-Layout%d-set%d.csv" % (layoutT, ExpNum))
TimeFiles = path.join(
time_dir, "time-Layout%d-set%d.csv" % (layoutT, ExpNum))
ServoCmd = "(time ../../components/servo/target/release/servo -x -y %d %s %s) 2> %s" % \
ServoCmd = "(time ../../target/release/servo -x -y %d %s %s) 2> %s" % \
(layoutT, Renderer, Benchmarks, TimeFiles)
Metrics = path.join(
etc_dir, "metrics-Layout%d-set%d-css.csv" % (layoutT, ExpNum))
Expand Down
2 changes: 1 addition & 1 deletion tests/wpt/harness/test/test.cfg.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ssl-type=none
# prefs-root=/path/to/gecko-src/testing/profiles/

# [servo]
# binary=/path/to/servo-src/components/servo/target/servo
# binary=/path/to/servo-src/target/release/servo
# exclude=testharness # Because it needs a special testharness.js

# [chrome]
Expand Down
2 changes: 1 addition & 1 deletion tests/wpt/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def set_defaults(paths, kwargs):

if kwargs["binary"] is None:
bin_dir = "release" if kwargs["release"] else "debug"
bin_path = servo_path("components", "servo", "target", bin_dir, "servo")
bin_path = servo_path("target", bin_dir, "servo")

kwargs["binary"] = bin_path

Expand Down

0 comments on commit a023708

Please sign in to comment.