Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile in release mode only when build is in release mode #6

Merged
merged 2 commits into from
May 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 31 additions & 18 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct Builder {
pub struct Output {
output_path: PathBuf,
crate_name: String,
profile: String,
}

pub enum BuildStatus {
Expand Down Expand Up @@ -67,20 +68,26 @@ impl Builder {

let mut xargo = ExecutableRunner::new(Xargo);

let mut args = Vec::new();

args.push("build");

let profile = env::var("PROFILE").unwrap_or("release".to_string());
if profile == "release" {
args.push("--release");
}

args.push("--color");
args.push(match self.colors {
true => "always",
false => "never",
});

args.push("--target");
args.push(self.target.get_target_name());

xargo
.with_args(&[
"build",
"--release",
"--color",
{
match self.colors {
true => "always",
false => "never",
}
},
"--target",
self.target.get_target_name(),
])
.with_args(&args)
.with_cwd(proxy.get_path())
.with_env("PTX_CRATE_BUILDING", "1")
.with_env("CARGO_TARGET_DIR", proxy.get_output_path())
Expand All @@ -103,22 +110,25 @@ impl Builder {
Ok(BuildStatus::Success(Output::new(
proxy.get_output_path(),
proxy.get_name(),
&profile,
)))
}
}

impl Output {
fn new(output_path: PathBuf, crate_name: &str) -> Self {
fn new(output_path: PathBuf, crate_name: &str, profile: &str) -> Self {
Output {
output_path,
crate_name: String::from(crate_name),
profile: String::from(profile),
}
}

pub fn get_assembly_path(&self) -> PathBuf {
self.output_path.join(format!(
"nvptx64-nvidia-cuda/release/{}.ptx",
self.crate_name
"nvptx64-nvidia-cuda/{}/{}.ptx",
self.profile,
self.crate_name,
))
}

Expand Down Expand Up @@ -161,8 +171,11 @@ impl Output {
}

fn get_deps_file_contents(&self) -> Result<String> {
let crate_deps_path = self.output_path
.join(format!("nvptx64-nvidia-cuda/release/{}.d", self.crate_name));
let crate_deps_path = self.output_path.join(format!(
"nvptx64-nvidia-cuda/{}/{}.d",
self.profile,
self.crate_name,
));

let mut crate_deps_reader = BufReader::new(File::open(crate_deps_path)?);
let mut crate_deps_contents = String::new();
Expand Down
50 changes: 34 additions & 16 deletions tests/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ lazy_static! {
#[test]
fn should_provide_output_path() {
let project = Project::analyze("tests/fixtures/sample-crate").unwrap();
let mut builder = {
let _lock = ENV_MUTEX.lock().unwrap();
Builder::new("tests/fixtures/sample-crate").unwrap()
};
let _lock = ENV_MUTEX.lock().unwrap();
let mut builder = Builder::new("tests/fixtures/sample-crate").unwrap();

match builder.build().unwrap() {
BuildStatus::Success(output) => {
Expand All @@ -45,10 +43,34 @@ fn should_write_assembly() {
let project = Project::analyze("tests/fixtures/sample-crate").unwrap();
remove_dir_all(project.get_proxy_crate().unwrap().get_output_path()).unwrap_or_default();

let mut builder = {
let _lock = ENV_MUTEX.lock().unwrap();
Builder::new("tests/fixtures/sample-crate").unwrap()
};
let _lock = ENV_MUTEX.lock().unwrap();
let mut builder = Builder::new("tests/fixtures/sample-crate").unwrap();

match builder.build().unwrap() {
BuildStatus::Success(output) => {
let mut assembly_contents = String::new();

File::open(output.get_assembly_path())
.unwrap()
.read_to_string(&mut assembly_contents)
.unwrap();

assert!(assembly_contents.contains(".visible .entry the_kernel("));
}

BuildStatus::NotNeeded => unreachable!(),
}
}

#[test]
fn should_write_assembly_in_debug_mode() {
let project = Project::analyze("tests/fixtures/sample-crate").unwrap();
remove_dir_all(project.get_proxy_crate().unwrap().get_output_path()).unwrap_or_default();

let _lock = ENV_MUTEX.lock().unwrap();
let mut builder = Builder::new("tests/fixtures/sample-crate").unwrap();

env::set_var("PROFILE", "debug");

match builder.build().unwrap() {
BuildStatus::Success(output) => {
Expand All @@ -68,10 +90,8 @@ fn should_write_assembly() {

#[test]
fn should_report_about_build_failure() {
let mut builder = {
let _lock = ENV_MUTEX.lock().unwrap();
Builder::new("tests/fixtures/faulty-crate").unwrap()
};
let _lock = ENV_MUTEX.lock().unwrap();
let mut builder = Builder::new("tests/fixtures/faulty-crate").unwrap();

let output = builder.disable_colors().build();
let crate_absoulte_path = current_dir().unwrap().join("tests/fixtures/faulty-crate");
Expand Down Expand Up @@ -118,10 +138,8 @@ fn should_report_about_build_failure() {

#[test]
fn should_provide_crate_source_files() {
let mut builder = {
let _lock = ENV_MUTEX.lock().unwrap();
Builder::new("tests/fixtures/sample-crate").unwrap()
};
let _lock = ENV_MUTEX.lock().unwrap();
let mut builder = Builder::new("tests/fixtures/sample-crate").unwrap();

match builder.build().unwrap() {
BuildStatus::Success(output) => {
Expand Down