Skip to content

Commit

Permalink
feat: add release task for firefly distribution
Browse files Browse the repository at this point in the history
This commit adds a new task for building an archive containing Firefly
and its associated toolchain for installation on a particular target.
The archive produced contains a directory structure like so:

    /bin
      firefly
    /etc (not currently generated as it has no contents)
    /share (not currently generated as it has no contents)
    /libexec (not currently generated as it has no contents)
    /lib
      fireflylib/
        <llvm_target>/
          bin/
            gcc-ld/
              ..firefly-lld wrappers..
            firefly-lld
          lib/
            ..various rlibs..

This tarball can be unpacked under `/usr/local` or similar installation
prefix on a UNIX-like system and used like any other program as long as
the `bin` directory is in the PATH. For Windows, we will likely need to
produce a different package entirely, with a structure more amenable to
that OS, but for the time being we assume installs will be on UNIX-like
systems until we have time to conduct more robust tests on Windows
outside of WSL.
  • Loading branch information
bitwalker committed Sep 12, 2022
1 parent b371bea commit 323e0ca
Show file tree
Hide file tree
Showing 8 changed files with 261 additions and 147 deletions.
9 changes: 9 additions & 0 deletions Makefile.toml
Expand Up @@ -363,6 +363,15 @@ command = "rustup"
env = { CARGO_TARGET_DIR = "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/tools/firefly-make/target" }
args = ["run", "${CARGO_MAKE_TOOLCHAIN}", "cargo", "-Z", "unstable-options", "build", "--manifest-path", "tools/firefly-lld/Cargo.toml", "--release", "--out-dir", "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/tools/firefly-make/target"]

[tasks.release]
category = "Release"
description = "Packages a distribution of the Firefly compiler"
command = "bin/firefly-make"
args = ["dist", "@@remove-empty(CARGO_MAKE_CARGO_VERBOSE_FLAGS)"]
dependencies = [
"firefly"
]

[tasks.require-ninja]
private = true
script = ['''
Expand Down
106 changes: 0 additions & 106 deletions bin/release

This file was deleted.

96 changes: 96 additions & 0 deletions tools/firefly-make/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 tools/firefly-make/Cargo.toml
Expand Up @@ -10,7 +10,9 @@ edition = "2021"
anyhow = "1.0"
cargo_metadata = "0.15"
clap = { version = "3.2", features = ["derive", "env"] }
flate2 = "1.0"
lit = { git = "https://github.com/getfirefly/lit", branch = "erlang" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tar = "0.4"
walkdir = "*"
44 changes: 3 additions & 41 deletions tools/firefly-make/src/build.rs
Expand Up @@ -9,14 +9,9 @@ use std::sync::OnceLock;
use anyhow::bail;
use cargo_metadata::{Message, MetadataCommand};
use clap::Args;
use serde::Deserialize;
use walkdir::{DirEntry, WalkDir};

#[derive(Deserialize)]
struct TargetSpec {
#[serde(rename = "llvm-target")]
llvm_target: String,
}
use crate::util;

#[derive(Args)]
pub struct Config {
Expand Down Expand Up @@ -119,7 +114,7 @@ impl Config {
}

pub fn llvm_target(&self) -> &str {
get_llvm_target(self.toolchain(), self.rust_target())
util::get_llvm_target(self.toolchain(), self.rust_target())
}

pub fn is_darwin(&self) -> bool {
Expand Down Expand Up @@ -484,7 +479,7 @@ pub fn run(config: &Config) -> anyhow::Result<()> {
// for `-C gcc-ld=lld`
let lld_wrapper = target_dir.join(exe("firefly-lld", &llvm_target));
let gcc_ld_dir = install_target_bin_dir.join("gcc-ld");
fs::create_dir(&gcc_ld_dir).unwrap();
fs::create_dir_all(&gcc_ld_dir).unwrap();

for lld_name in &["ld.lld", "ld64.lld", "lld-link", "wasm-ld"] {
let dest = gcc_ld_dir.join(exe(lld_name, &llvm_target));
Expand Down Expand Up @@ -543,39 +538,6 @@ pub fn run(config: &Config) -> anyhow::Result<()> {
Ok(())
}

static LLVM_TARGET: OnceLock<String> = OnceLock::new();

fn get_llvm_target(toolchain_name: &str, target: &str) -> &'static str {
let target = LLVM_TARGET.get_or_init(|| {
let mut rustc_cmd = Command::new("rustup");
let rustc_cmd = rustc_cmd
.arg("run")
.arg(toolchain_name)
.args(&["rustc"])
.args(&["-Z", "unstable-options"])
.args(&["--print", "target-spec-json", "--target"])
.arg(target);

let output = rustc_cmd
.stdin(Stdio::null())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.output()
.unwrap();

if !output.status.success() {
panic!(
"unable to determine llvm target triple!: {}",
String::from_utf8(output.stderr).unwrap()
);
}

let spec: TargetSpec = serde_json::from_slice(output.stdout.as_slice()).unwrap();
spec.llvm_target
});
target.as_str()
}

static RUST_SYSROOT: OnceLock<PathBuf> = OnceLock::new();

fn get_rust_sysroot() -> &'static Path {
Expand Down

0 comments on commit 323e0ca

Please sign in to comment.