Граф коммитов

227 Коммитов

Автор SHA1 Сообщение Дата
David Michael Barr d2c7f925ad Add a Memcached cache variant
This cache module uses a Memcached cluster.
To make sccache use this, set SCCACHE_MEMCACHED
to a list of tcp://<hostname>:<port> addresses,
separated by whitespace.
2018-01-23 09:42:36 -05:00
Alex Crichton adaa4ef190 Add jobserver support to sccache
This commit alters the main sccache server to operate and orchestrate its own
GNU make style jobserver. This is primarily intended for interoperation with
rustc itself.

The Rust compiler currently has a multithreaded mode where it will execute code
generation and optimization on the LLVM side of things in parallel. This
parallelism, however, can overload a machine quickly if not properly accounted
for (e.g. if 10 rustcs all spawn 10 threads...). The usage of a GNU make style
jobserver is intended to arbitrate and rate limit all these rustc instances to
ensure that one build's maximal parallelism never exceeds a particular amount.

Currently for Rust Cargo is the primary driver for setting up a jobserver. Cargo
will create this and manage this per compilation, ensuring that any one `cargo
build` invocation never exceeds a maximal parallelism. When sccache enters the
picture, however, the story gets slightly more odd.

The jobserver implementation on Unix relies on inheritance of file descriptors
in spawned processes. With sccache, however, there's no inheritance as the
actual rustc invocation is spawned by the server, not the client. In this case
the env vars used to configure the jobsever are usually incorrect.

To handle this problem this commit bakes a jobserver directly into sccache
itself. The jobserver then overrides whatever jobserver the client has
configured in its own env vars to ensure correct operation. The settings of each
jobserver may be misconfigured (there's no way to configure sccache's jobserver
right now), but hopefully that's not too much of a problem for the forseeable
future.

The implementation here was to provide a thin wrapper around the `jobserver`
crate with a futures-based interface. This interface was then hooked into the
mock command infrastructure to automatically acquire a jobserver token when
spawning a process and automatically drop the token when the process exits.
Additionally, all spawned processes will now automatically receive a configured
jobserver.

cc rust-lang/rust#42867, the original motivation for this commit
2018-01-18 10:56:56 -05:00
Kornel 9c19b7cbce Update other deps 2018-01-08 16:29:24 -05:00
Kornel 12504fbf56 Update ring 2018-01-08 16:29:24 -05:00
Ted Mielczarek 24b5b95b5f (cargo-release) start next development iteration 0.2.5-pre 2018-01-08 16:02:54 -05:00
Ted Mielczarek 5386227460 Pin zip to 0.2.3 to avoid depending on rust 1.23 right now 2018-01-08 15:59:34 -05:00
Ted Mielczarek 8c577d8a41 (cargo-release) version 0.2.4 2018-01-08 15:46:44 -05:00
Ted Mielczarek aaed2de4c0 (cargo-release) start next development iteration 0.2.4-pre 2018-01-05 12:09:37 -05:00
Ted Mielczarek c41261d978 (cargo-release) version 0.2.3 2018-01-05 12:08:22 -05:00
Ted Mielczarek 7e176dcd5a (cargo-release) start next development iteration 0.2.3-pre 2017-10-25 15:16:57 -04:00
Ted Mielczarek f5d7bac801 (cargo-release) version 0.2.2 2017-10-25 15:15:32 -04:00
Ted Mielczarek 56dcc1dc36 bump version to 0.2.2-pre 2017-10-25 15:14:17 -04:00
Ted Mielczarek f1f5573988 Update error-chain to pick up a fix for a new warning 2017-10-25 15:13:44 -04:00
Ted Mielczarek 2d9bdc1e8f Ignore CARGO_MAKEFLAGS when calculating Rust hash keys. Fixes #193
Since cargo gained jobserver support it now passes a CARGO_MAKEFLAGS
environment variable which is different for every build (it contains file
descriptor numbers or semaphore values). sccache uses all environment
variables starting with `CARGO_` as inputs to the hash key for Rust compilation
so this broke things. I think it was mostly only a problem on Windows,
where the values were semaphores. On POSIX platforms the values are file
descriptors, which are probably likely to be the same between runs of cargo.

This change also adds a test for compiling a simple Rust crate with
cargo and verifying that we get a cache hit. I pulled in the `assert_cli`
crate to write that test, which worked nicely.
2017-10-25 15:13:44 -04:00
Ted Mielczarek df04fa530d (cargo-release) version 0.2.1 2017-08-18 14:42:53 -07:00
Taylor Cramer 4e9ee4cc5f Revert "Move from openssl to pem-parser for PEM to DER conversion for GCS"
This reverts commit 39fdfd83a8.
2017-08-02 06:25:05 -04:00
Ted Mielczarek 6267caf603 (cargo-release) start next development iteration 0.2.1-pre 2017-07-25 15:47:24 -04:00
Ted Mielczarek 43300e1976 add a version to lru-disk-cache dep 2017-07-25 15:46:09 -04:00
Ted Mielczarek 5a9009a250 (cargo-release) version 0.2.0 2017-07-25 15:41:17 -04:00
Alex Crichton da8fbdb3b5 Depend on tokio-serde-bincode from crates.io 2017-07-13 11:34:22 -07:00
Taylor Cramer 39fdfd83a8 Move from openssl to pem-parser for PEM to DER conversion for GCS 2017-06-19 05:54:09 -04:00
Taylor Cramer afa99ccf6d Implement GCS backend 2017-06-19 05:54:09 -04:00
Alex Crichton 3ede3446a8 Use hyper-tls from crates.io 2017-06-14 15:30:32 -07:00
Adrian Perez de Castro 90c6a2cfe4 Fix build with --no-default-features --features=redis
The serde_json crate is always needed by src/commands.rs even when
building only with support for Redis, but serde_json would be left
out when the S3 feature is disabled. This make it possible to build
sccache only with Redis support.

Building with S3 disabled trims down a stripped release build from
5.1 MiB down to 4.4 MiB on x86_64.
2017-06-14 12:22:02 -04:00
Alex Crichton ac131fc715 Update dependencies
Notably bring in hyper from crates.io
2017-06-14 08:20:12 -07:00
Ted Mielczarek b777bcde38 tweak Cargo.toml metadata and README 2017-05-25 12:54:02 -04:00
Ted Mielczarek 69e0be5cac bump version to 0.2.0-pre 2017-05-25 12:27:25 -04:00
Tetsuharu OHZEKI 80c79ed8ab Use base64 instead of rustc-serialize
[rustc-serialize has been deprecated](https://github.com/rust-lang-deprecated/rustc-serialize).
Instead, this pull request switchs to [base64](https://crates.io/crates/base64)
2017-05-25 09:11:58 -04:00
Alex Crichton 2ee40dbda0 Update dependencies
* Mostly upgrade to serde 1.0
* Pull in lots of other updates for other small deps
2017-05-18 13:53:00 -07:00
Ted Mielczarek 16ecd0ba31 Atomically create compiler outputs from cache entries. Fixes #122.
I was seeing intermittent rustc panics when compiling with sccache.
It turns out that rustc will wind up looking for rlibs in the output dir
and sometimes it finds the ones that we're in the middle of writing out from
cache and it panics trying to read the half-written file.

This change makes us write the cache entry to a tempfile and atomically
rename it to the final name.
2017-05-17 16:38:12 -04:00
Alex Crichton 84054a8d4e Switch from SHA-1 to SHA-512
Local benchmarking showed that the implementation of SHA-512 in the *ring* crate
is 3x faster than the implementation of SHA-1 in the `sha1` crate. I've also
noticed that 80%+ of sccache's runtime on a fully cached build is spent hashing.
With this change I noticed a decrease from 108s to 92s when building a fully
cached LLVM from the network. Not a huge win but if the network were faster
could perhaps add up!

Closes #108
2017-05-15 13:25:23 -07:00
Ted Mielczarek 47404edda4 Use the gcc crate to locate MSVC for system tests. Fixes #101
Currently the system tests are not running in our Windows CI because
cl.exe is not in PATH. They also won't run in a local `cargo test` if
not run from a shell with the MSVC environment set. This is unfortunate
for many reasons. This changes fixes this by using the GCC crate to locate
MSVC. The compiler invocations in the system tests needed some fixup to
use the MSVC environment variables returned by the GCC crate as well.
2017-04-17 14:15:45 -04:00
Ted Mielczarek e56b57eba2 Update clap 2017-04-07 13:57:01 -04:00
Ted Mielczarek 3b6cb33cd7 Re-enable s3 by default, build with --features=all in CI 2017-04-05 11:56:06 -04:00
Ted Mielczarek 580c393f8c When hashing Rust compile arguments, sort -L and --cfg args as well as --extern 2017-04-03 10:21:13 -04:00
Felix Obenhuber 2349791192 Use Cargo features for S3 and Redis caches
The S3 and Redis caches are optional during build time.
Enable feature "s3" and/or "redis" to build sccache with
support for those backends. Only the local disk cache
is available by default. The "all" feature enables both.
This patch is changing the current default behavior that
always has S3 support.
2017-03-27 12:37:25 -07:00
Felix Obenhuber dc31690674 Add a Redis cache variant
This cache module uses a Redis instance. To make sccache use this,
set SCCACHE_REDIS to redis://[:<passwd>@]<hostname>[:port][/<db>].
The maximum and current cache size is retrieved from the INFO and
CONFIG GET redis command.
2017-03-27 12:34:05 -07:00
Alex Crichton a996ae6c2a Move from protobuf to bincode for a wire format
This commit migrates away from the `protobuf` crate to instead just working with
bincode on the wire as a serialization format. This is done by leveraging a few
different crates:

* The `bincode` and `serde_derive` crates are used to define serialization
  for Rust structures as well as provide a bincode implementation.
* The `tokio_io::codec::length_delimited` module implements framing via length
  prefixes to transform an asynchronous stream of bytes into a literal `Stream`
  of `BytesMut`.
* The `tokio_serde_bincode` crate is then used to tie it all together, parsing
  these `BytesMut` as the request/response types of sccache.

Most of the changes here are related to moving away from the protobuf API
throughout the codebase (e.g. `has_foo` and `take_foo`) towards a more
rustic-ish API that just uses enums/structs. Overall it felt quite natural (as
one would expect) to just use the raw enum/struct values.

This may not be quite as performant as before but that doesn't really apply to
sccache's use case where perf is hugely dominated by actually compiling and
hashing, so I'm not too too worried about that.

My personal motivation for this is twofold:

1. Using `protobuf` was a little clunky throughout the codebase and definitely
   had some sharp edges that felt good to smooth out.
2. There's currently what I believe some mysterious segfault and/or stray write
   happening in sccache and I'm not sure where. The `protobuf` crate had a lot
   of `unsafe` code and in lieu of actually auditing it I figured it'd be good
   to kill two birds with one stone. I have no idea if this fixes my segfault
   problem (I never could reproduce it) but I figured it's worth a shot.
2017-03-27 09:29:12 -07:00
Alex Crichton 76982eee57 Update to using the new tokio-io crate
This is an abstraction of the Tokio stack now and doesn't have much impact on
sccache itself but I figured it'd be good to update a few deps and pick up the
recent version of things!

Plus that and I'd like to start using the length_delimited module soon...
2017-03-24 18:37:04 -07:00
Ted Mielczarek cf7b400c90 Store file permissions for files in cache 2017-03-24 05:53:21 -04:00
Alex Crichton 8968eba6c9 Remove dependency on `named_pipe`
I was sporadically receiving a segfault locally when trying to debug issues on
Windows and in tracking this down I discovered blackbeam/named_pipe#3 which
leads to segfaults locally on startup.

This switches the one use case to the relevant functionality in
`mio-named-pipes` (already pulled in as part of `tokio-process`) and then
otherwise mirrors the same logic as the Unix version, just waiting for a byte
with a timeout.
2017-03-21 15:51:53 -04:00
Alex Crichton 4071f3bc21 Remove raw `poll` in favor of `tokio-uds`
Now that we've got tokio at our fingertips it's much easier to time out simple
operations!
2017-02-17 13:39:01 -05:00
Alex Crichton f388dbd459 Integrate the Tokio branch of Hyper
This commit pulls in Hyper from its master branch which contains the
asynchronous/Tokio integration. All instances of HTTP, namely when
interacting with S3, are now all powered by async Hyper and work with
futures rather than synchronous requests on thread pools.
2017-02-17 13:39:01 -05:00
Alex Crichton 6b3e49d971 Integrate process spawning with tokio-process
This commit replaces all process spawning with the futures-powered
versions in the `tokio-process` crate. Most functions were already ready
to return futures, but a few minor updates were made to ensure that
functions could return futures.

Additionally, some `&CpuPool` arguments have shown up to allow executing
work on a thread pool, such as filesystem operations. A number of
compilers write data to tempdirs and such before running a compiler, and
these are all executed on thread pools rather than the main thread.

My main takeaway from this commit is that translating synchronous to
asynchronous code isn't always easy. The "easy" version ends up being
relatively wasteful in terms of clones for low-level performance, but
probably shouldn't matter much in the context of spawning processes.

Other than that though I found that there was a translation for all
patterns found didn't actually hit any bugs (yet at least) from the
translation.
2017-02-17 13:39:01 -05:00
Alex Crichton b59a12abfb Rewrite the server module with Tokio
This commit rewrites the `server` module of sccache to be backed with Tokio. The
previous version was written with `mio`, which Tokio is built on, but is
unfortunately less ergonomic. Tokio is the state-of-the-art for asynchronous
programming in Rust and sccache serves as a great testing ground for ergonomics!

It's intended that the support added here will eventually extend to many other
operations that sccache does as well. For example thread spawning has all been
replaced with `CpuPool` to have a shared pool for I/O operations and such
(namely the filesystem). Eventually the HTTP requests made by the S3 backend can
be integrated with the Tokio branch of Hyper as well to run that on the event
loop instead of in a worker thread. I'd also like to eventually extend this with
`tokio-process` as well to move process spawning off helper threads as well, but
I'm leaving that to a future commit as well.

Overall I found the transition was quite smooth, with the high level
architecture look like:

* The `tokio-proto` crate is used in streaming mode. The streaming part is used
  for the one RPC sccache gets which requires a second response to be sent later
  on. This second response is the "response body" in tokio-proto terms.
* All of sccache's logic is manifested in an implementation of the `Service`
  trait.
* The transport layer is provided with `tokio_core::io::{Framed, Codec}`, and
  simple deserialization/serialization is performed with protobuf.

Some differences in design are:

* The `SccacheService` for now is just a bunch of reference-counted pointers,
  making it cheap to clone. As the futures it returns progress they will each
  retain a reference to a cloned copy of the `SccacheService`. Before all this
  data was just stored and manipulated in a struct directly, but it's now
  directly managed through shared memory.
* The storage backends share a thread pool with the main server instead of
  spawning threads.

And finally, some things I've learned along the way:

* Sharing data between futures isn't a trivial operation. It took an explicit
  decision to use `Rc` and I'm not sure I'm 100% happy with how the ergonomics
  played out.
* Shutdown is pretty tricky here. I've tried to carry over all the previous
  logic but it definitely required not using `TcpServer` in tokio-proto at the
  very least, and otherwise required a few custom futures and such to track the
  various states. I have a hunch that tokio-proto could provide more options out
  of the box for something like this.
2017-02-15 06:19:56 -05:00
Ted Mielczarek 898f90824d Disable default features in error-chain to make the build continue to work with Rust 1.12 2017-01-31 07:24:47 -05:00
Ted Mielczarek 52630820ef Use error-chain to define Result+Error types, refactor cmdline::parse to use it. 2017-01-30 13:54:21 -05:00
Ted Mielczarek d83dd03de7 Use a named unix socket or named pipe to let the background server notify the client that it started successfully 2017-01-27 15:57:09 -05:00
Ted Mielczarek 1db21485e0 Add an `SCCACHE_ERROR_LOG` variable to redirect the server's stderr, so
we can get backtraces for unhandled panics.
2017-01-10 09:36:26 -05:00
Alex Newman 9c8cadc2d1 Fix to enable cargo install 2016-12-16 14:28:22 -05:00
Ted Mielczarek c70dcf258f Don't create consoles for compiler invocations on Windows. Fixes #16.
This fixes the extra console windows that show up when the sccache server
creates compiler processes on Windows, but it only works on nightly Rust
currently, and requires building with `--features=unstable`, because it relies
on the not-yet-stable `windows_process_extensions` feature (https://github.com/rust-lang/rust/issues/37827).

Also I added a bunch of extra documentation to the mock_command traits.
2016-12-13 10:01:12 -05:00
Ted Mielczarek 030ed02ab4 Make DiskCache limit the size of the on-disk cache by using LruDiskCache. Fixes #29 2016-12-07 12:15:01 -10:00
Ted Mielczarek e8b64ca447 Pull in app_dirs to get a better default local disk cache location 2016-11-17 10:59:15 -05:00
Ted Mielczarek a41f7e451e Don't block sending compile result to client on cache write. Fixes #19.
This change makes `get_cached_or_compile` return a `Future` for the
cache write instead of blocking on it. The server then waits for the
result on a thread. It also changes the server to record cache write
timings, and display the average in the stats.
2016-11-02 17:15:14 -04:00
Ted Mielczarek 1d591f811b daemonize the server process on unix 2016-10-26 16:22:52 -04:00
Ted Mielczarek d115dc2c63 use local-encoding crate for stdout conversion 2016-09-21 15:57:28 -04:00
Ted Mielczarek 30199bef4a drop openssl dep from hyper for now 2016-08-25 15:34:42 -04:00
Ted Mielczarek 657cb895f1 drop rusoto, import some simple s3 code and use that 2016-08-12 14:03:37 -04:00
Ted Mielczarek 3444252dff use rusoto master YOLO 2016-08-08 21:15:03 -04:00
Ted Mielczarek 1565f6a85e switch back to released version of which, switch to a rusoto branch with a bug fix 2016-08-08 15:06:06 -04:00
Ted Mielczarek 4c460d133b use my fork of which-rs until a fix gets released 2016-07-27 12:47:31 -04:00
Ted Mielczarek fe628ffd62 Update to a released rusoto, and 'cargo update' while we're at it 2016-07-15 11:31:56 -04:00
Ted Mielczarek dc5f2e295d bump sha1 crate to 0.2.0 2016-07-15 10:42:08 -04:00
Stefan Ilic 11771a06da Started using which crate (#14) 2016-07-14 06:38:26 -04:00
Stefan Ilic 8b8bbc339c Start using fern for logging (#9) 2016-06-28 07:12:54 -04:00
Ted Mielczarek 86aa35b191 Detect MSVC -showIncludes prefix (not actually wired up to anything yet) 2016-06-24 07:01:25 -04:00
Ted Mielczarek 7676daf23c switch to the rusoto feature_mutex_credentials branch 2016-06-10 13:39:32 -04:00
Ted Mielczarek b16e3a2f4b try using my rusoto fork 2016-06-07 15:46:01 -04:00
Ted Mielczarek 68eebc2694 Implement S3Cache
Unlike sccache1, you need to specify both bucket and region, like:
SCCACHE_BUCKET=sccache
SCCACHE_REGION=us-east-1

Pretty limited testing, no automated tests currently.
2016-06-03 15:09:38 -04:00
Ted Mielczarek c11f6635df Implement fetching/storing to cache, interfaces for doing so, implement a disk cache 2016-05-21 14:14:26 -04:00
Ted Mielczarek a29fc7c1fe turn Compiler into CompilerKind, make a Compiler struct to hold some more info about compilers 2016-05-18 14:30:11 -04:00
Ted Mielczarek 3f9ee125d1 drop format_size code in favor of number_prefix crate 2016-05-12 15:46:22 -04:00
Ted Mielczarek 0744b40549 Support running compile commands on the server.
This change lets the server run compile commands for supported compilers.
It doesn't do any output caching yet, but if it detects that a commandline
is a supported compiler it will send a `CompileStarted` message to the client,
run the compiler on a background thread, and then send a `CompileFinished`
message with the exit status and stdout/stderr when it completes.
2016-05-12 14:47:46 -04:00
Ted Mielczarek d9e5315b9d Add compiler detection in server.
This change adds a large amount of support code to allow the server
to run compiler detection on a background thread.

It adds general support for running tasks in the server (`run_task`)
and handling their results, as well as support for using `MockCommandCreator`
across threads in a safe way. This also required making `SccacheServer`
generic over `CommandCreatorSync` so that its process execution could
be mocked for tests.

The server still does not yet actually run compile commands.
2016-05-04 13:56:59 -04:00
Ted Mielczarek 228c72f9fb Implement Mock versions of CommandCreator et. al. 2016-05-02 15:11:20 -04:00
Ted Mielczarek 3010a53dc3 Rework server to use mio 2016-04-29 09:32:01 -04:00
Ted Mielczarek 16d74015a9 Somewhat-fleshed-out skeleton.
Has a protocol (defined in protocol.proto), client-server bits,
and some basic request handling. Doesn't actually execute commands yet.
2016-04-26 16:43:03 -04:00