Skip to content

Commit

Permalink
fix: use absolute include path in gcc compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
coffeeispower committed Feb 22, 2024
1 parent 4a6b4b5 commit ccd601a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub trait Compiler {
/// It may use the package info to modify the way the command is generated (e.g. with compiler flags or dependencies)
fn compile_command(
&self,
package_path: PathBuf,
source_path: PathBuf,
output_path: PathBuf,
package_info: &manifest::Package,
Expand All @@ -30,6 +31,7 @@ pub trait Compiler {
/// It may use the package info to modify the way the command is generated (e.g. with linker flags or dependencies)
fn link_command(
&self,
package_path: PathBuf,
object_files: Vec<PathBuf>,
output_path: PathBuf,
package_info: &manifest::Package,
Expand Down
6 changes: 5 additions & 1 deletion src/compiler/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub struct GCC;
impl Compiler for GCC {
fn compile_command(
&self,
package_path: PathBuf,
source_path: PathBuf,
output_path: PathBuf,
package_info: &crate::manifest::Package,
Expand All @@ -17,12 +18,15 @@ impl Compiler for GCC {
}
command.arg(source_path).args(["-c", "-o"]).arg(output_path);
command.args(&package_info.additional_compiler_flags);
command.arg(format!("-I{}", package_info.include_folder.display()));
let mut include_folder_absolute_path = package_path.clone();
include_folder_absolute_path.push(&package_info.include_folder);
command.arg(format!("-I{}", include_folder_absolute_path.display()));
command
}

fn link_command(
&self,
_package_path: PathBuf,
object_files: Vec<PathBuf>,
output_path: PathBuf,
package_info: &crate::manifest::Package,
Expand Down
14 changes: 12 additions & 2 deletions src/package/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,12 @@ impl PackageBuilder {
create_parent_folder(&object_file_path)?;
if file_needs_rebuild(&src, &object_file_path) {
let output = compiler
.compile_command(src.clone(), object_file_path.clone(), self.package())
.compile_command(
self.package_path(),
src.clone(),
object_file_path.clone(),
self.package(),
)
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()?;
Expand Down Expand Up @@ -228,7 +233,12 @@ impl PackageBuilder {
self.create_output_folder()?;
let package_output_path = self.output_path();
let link_command_output = compiler
.link_command(object_files, package_output_path.clone(), self.package())
.link_command(
self.package_path(),
object_files,
package_output_path.clone(),
self.package(),
)
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()?;
Expand Down

0 comments on commit ccd601a

Please sign in to comment.