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

feat: include liblld instead of spawning as process #37

Merged
merged 2 commits into from
Nov 4, 2019
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
3 changes: 2 additions & 1 deletion .github/actions/install-llvm/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ async function execute(cmd) {
(async () => {
try {
if(isLinux) {
await exec.exec("sudo apt install llvm-7 llvm-7-* lld-7");
await exec.exec("sudo apt install llvm-7 llvm-7-* liblld-7*");
} else if(isMacOS) {
await exec.exec("brew install llvm@7")
let llvmPath = await execute("brew --prefix llvm@7");
Expand All @@ -997,6 +997,7 @@ async function execute(cmd) {
}
})();


/***/ }),

/***/ 129:
Expand Down
4 changes: 2 additions & 2 deletions .github/actions/install-llvm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function execute(cmd) {
(async () => {
try {
if(isLinux) {
await exec.exec("sudo apt install llvm-7 llvm-7-* lld-7");
await exec.exec("sudo apt install llvm-7 llvm-7-* liblld-7*");
} else if(isMacOS) {
await exec.exec("brew install llvm@7")
let llvmPath = await execute("brew --prefix llvm@7");
Expand All @@ -50,4 +50,4 @@ export async function execute(cmd) {
} catch(error) {
core.setFailed(error.message);
}
})();
})();
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ rustup](https://www.rust-lang.org/tools/install).

Mun targets LLVM 7.1.0. Installing LLVM is platform dependant and as such can be a pain. The
following steps are how we install LLVM on [our CI
runners](https://github.com/mun-lang/mun/blob/master/ci/azure-install-llvm.yml):
runners](.github/actions/install-llvm/index.js):

* ***nix**: Package managers of recent *nix distros can install binary versions of LLVM, e.g.:
```bash
# Ubuntu 18.04
sudo apt install llvm-7 llvm-7-* lld-7
sudo apt install llvm-7 llvm-7-* liblld-7*
```
* **macOS**: [Brew](https://brew.sh/) contains a binary distribution of LLVM 7.1.0. However, as it's
not the latest version, it won't be added to the path. We are using
Expand Down
3 changes: 2 additions & 1 deletion crates/mun_codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2018"
inkwell = { git = "https://github.com/TheDan64/inkwell", branch = "llvm7-0" }
mun_hir = { path = "../mun_hir" }
mun_target = { path = "../mun_target" }
mun_lld = { path = "../mun_lld" }
failure = "0.1.5"
salsa="0.12"
md5="0.6.1"
Expand All @@ -21,4 +22,4 @@ insta = "0.12.0"
[build-dependencies]
lazy_static = "1.4.0"
semver = "0.9.0"
regex = "1.3.1"
regex = "1.3.1"
211 changes: 0 additions & 211 deletions crates/mun_codegen/build.rs

This file was deleted.

40 changes: 17 additions & 23 deletions crates/mun_codegen/src/code_gen.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::code_gen::linker::LinkerError;
use crate::IrDatabase;
use failure::Fail;
use inkwell::module::Module;
Expand All @@ -7,17 +8,16 @@ use inkwell::OptimizationLevel;
use mun_hir::FileId;
use std::io::{self, Write};
use std::path::Path;
use std::process::{Child, Stdio};

mod abi_types;
mod linker;

#[derive(Debug, Fail)]
enum CodeGenerationError {
#[fail(display = "linker error: {}", 0)]
LinkerError(String),
#[fail(display = "linker error: {}", 0)]
SpawningLinkerError(io::Error),
#[fail(display = "{}", 0)]
LinkerError(#[fail(cause)] LinkerError),
#[fail(display = "error linking modules: {}", 0)]
ModuleLinkerError(String),
#[fail(display = "unknown target triple: {}", 0)]
UnknownTargetTriple(String),
#[fail(display = "error creating target machine")]
Expand All @@ -28,6 +28,12 @@ enum CodeGenerationError {
CodeGenerationError(String),
}

impl From<LinkerError> for CodeGenerationError {
fn from(e: LinkerError) -> Self {
CodeGenerationError::LinkerError(e)
}
}

/// Construct a shared object for the given `hir::FileId` at the specified output file location.
pub fn write_module_shared_object(
db: &impl IrDatabase,
Expand All @@ -49,7 +55,7 @@ pub fn write_module_shared_object(
let module = db.module_ir(file_id);
assembly_module
.link_in_module(module.llvm_module.clone())
.map_err(|e| CodeGenerationError::LinkerError(e.to_string()))?;
.map_err(|e| CodeGenerationError::ModuleLinkerError(e.to_string()))?;

// Generate the `get_info` method.
symbols::gen_reflection_ir(
Expand Down Expand Up @@ -100,25 +106,13 @@ pub fn write_module_shared_object(

// Construct a linker for the target
let mut linker = linker::create_with_target(&target);
linker.add_object(obj_file.path());
linker.add_object(obj_file.path())?;

// Link the object
linker.build_shared_object(&output_file_path);

let mut cmd = linker.finalize();
let result = cmd
.stderr(Stdio::piped())
.spawn()
.and_then(Child::wait_with_output)
.map_err(CodeGenerationError::SpawningLinkerError)?;

if !result.status.success() {
let error = String::from_utf8(result.stderr)
.unwrap_or_else(|_| "<linker error contains invalid utf8>".to_owned());
Err(CodeGenerationError::LinkerError(error).into())
} else {
Ok(())
}
linker.build_shared_object(&output_file_path)?;
linker.finalize()?;

Ok(())
}

/// Optimizes the specified LLVM `Module` using the default passes for the given
Expand Down
Loading