Skip to content

Commit

Permalink
Revert to using cpuprofiler-0.0
Browse files Browse the repository at this point in the history
We cannot publish sandboxfs as a crate if it depends on non-published
crates, so we must pin cpuprofiler to 0.0.  We were only using a custom
branch that simplifies the build process, but we can do the same thing
ourselves with a custom build.rs file.
  • Loading branch information
jmmv committed Feb 4, 2019
1 parent e921fb6 commit 3f33b44
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
9 changes: 3 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ default = []
profiling = ["cpuprofiler"]

[dependencies]
cpuprofiler = { version = "0.0", optional = true }
env_logger = "0.5"
failure = "~0.1.2"
getopts = "0.2"
Expand All @@ -29,12 +30,8 @@ serde_json = "1.0"
signal-hook = "0.1"
time = "0.1"

[dependencies.cpuprofiler]
# TODO(https://github.com/AtheMathmo/cpuprofiler/pull/10): Replace this with
# 0.0.4 or an upstream branch reference once released.
git = "https://github.com/jmmv/cpuprofiler.git"
rev = "a852024d6aed7202863dc43a3348e793aa432d54"
optional = true
[build-dependencies]
pkg-config = "0.3"

[dependencies.fuse]
# TODO(jmmv): Replace this with 0.4 once released.
Expand Down
47 changes: 47 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2019 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy
// of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.

extern crate pkg_config;

/// Configures the crate to link against `lib_name`.
///
/// The library is searched via the pkg-config file provided in `pc_name`, which provides us
/// accurate information on how to find the library to link to.
///
/// However, for libraries that do not provide a pkg-config file, `fallback` can be set to true to
/// just rely on the linker's search path to find it. This is not accurate but is better than just
/// failing to build.
#[allow(unused)]
fn find_library(pc_name: &str, lib_name: &str, fallback: bool) {
match pkg_config::Config::new().atleast_version("2.0").probe(pc_name) {
Ok(_) => (),
Err(_) => if fallback { println!("cargo:rustc-link-lib={}", lib_name) },
};
}

fn main () {
// Look for the libraries required by our cpuprofiler dependency. Such dependency should do
// this on its own but it doesn't yet. Given that we just need this during linking, we can
// cheat and do it ourselves.
//
// Note that older versions of gperftools (the package providing libprofiler) did not ship a
// pkg-config file, so we must fall back to using the linker's path.
//
// TODO(https://github.com/AtheMathmo/cpuprofiler/pull/10): Remove this in favor of upstream
// doing the right thing when this PR is accepted a new cpuprofiler version is released.
// TODO(https://github.com/dignifiedquire/rust-gperftools/pull/1): Remove this in favor of
// upstream doing the right thing when this PR is accepted and switch to rust-gperftools instead
// (which has the added benefit of providing heap profiling).
#[cfg(feature = "profiling")] find_library("libprofiler", "profiler", true);
}

0 comments on commit 3f33b44

Please sign in to comment.