-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored and cleaned up remaining workspace comilation code
- Loading branch information
1 parent
1507a42
commit 2a1d816
Showing
6 changed files
with
242 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
mod invoke; | ||
mod options; | ||
mod parse; | ||
mod supported_targets; | ||
|
||
pub use options::BuildOptions; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use crate::{ | ||
diagnostics::{Diagnostics, WarningDiagnostic}, | ||
target::{Target, TargetArch, TargetOs}, | ||
}; | ||
|
||
pub fn warn_if_unsupported_target(target: &Target, diagnostics: &Diagnostics) { | ||
if target.arch().is_none() { | ||
diagnostics.push(WarningDiagnostic::plain( | ||
"Target architecture is not supported, falling back to best guess", | ||
)); | ||
} | ||
|
||
if target.os().is_none() { | ||
diagnostics.push(WarningDiagnostic::plain( | ||
"Target os is not supported, falling back to best guess", | ||
)); | ||
} | ||
|
||
match target.os().zip(target.arch()) { | ||
Some((TargetOs::Windows, TargetArch::X86_64)) => (), | ||
Some((TargetOs::Windows, TargetArch::Aarch64)) => (), | ||
Some((TargetOs::Mac, TargetArch::X86_64)) => (), | ||
Some((TargetOs::Mac, TargetArch::Aarch64)) => (), | ||
Some((TargetOs::Linux, TargetArch::X86_64)) => (), | ||
Some((TargetOs::Linux, TargetArch::Aarch64)) => (), | ||
Some((TargetOs::FreeBsd, TargetArch::X86_64)) => (), | ||
None => (), | ||
#[allow(unreachable_patterns)] | ||
_ => { | ||
diagnostics.push(WarningDiagnostic::plain( | ||
"Host os/architecture configuration is not officially supported, taking best guess", | ||
)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use crate::{compiler::Compiler, ir, llvm_backend::llvm_backend, resolved, unerror::unerror}; | ||
use std::{ | ||
ffi::OsString, | ||
fs::create_dir_all, | ||
path::{Path, PathBuf}, | ||
time::Duration, | ||
}; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct ExportDetails { | ||
pub linking_duration: Duration, | ||
pub executable_filepath: PathBuf, | ||
} | ||
|
||
pub fn export_and_link( | ||
compiler: &mut Compiler, | ||
project_folder: &Path, | ||
resolved_ast: &resolved::Ast, | ||
ir_module: &ir::Module, | ||
) -> Result<ExportDetails, ()> { | ||
let target = &compiler.options.target; | ||
let project_name = project_name(project_folder); | ||
|
||
let binary_artifacts_folder = project_folder.join("bin"); | ||
let object_files_folder = project_folder.join("obj"); | ||
create_dir_all(&binary_artifacts_folder).expect("failed to create bin folder"); | ||
create_dir_all(&object_files_folder).expect("failed to create obj folder"); | ||
|
||
let object_file_filepath = | ||
object_files_folder.join(target.default_object_file_name(&project_name)); | ||
|
||
let executable_filepath = | ||
binary_artifacts_folder.join(target.default_executable_name(&project_name)); | ||
|
||
let linking_duration = unerror( | ||
unsafe { | ||
llvm_backend( | ||
compiler, | ||
&ir_module, | ||
&resolved_ast, | ||
&object_file_filepath, | ||
&executable_filepath, | ||
&compiler.diagnostics, | ||
) | ||
}, | ||
compiler.source_files, | ||
)?; | ||
|
||
Ok(ExportDetails { | ||
linking_duration, | ||
executable_filepath, | ||
}) | ||
} | ||
|
||
fn project_name(project_folder: &Path) -> OsString { | ||
project_folder | ||
.file_name() | ||
.map(OsString::from) | ||
.or_else(|| { | ||
std::env::current_dir() | ||
.ok() | ||
.and_then(|dir| dir.file_name().map(OsString::from)) | ||
}) | ||
.unwrap_or_else(|| OsString::from("main")) | ||
} |
Oops, something went wrong.