Commit e82c6480 authored by Robin Randhawa's avatar Robin Randhawa
Browse files

Get TARGET from the environment

Checks against a static list of targets. This makes it possible to use
redoxer with AArch64 as well as x86_64.
parent 3edb39fb
use std::{env, io, process};
use std::ffi::OsString;
use crate::{status_error, toolchain, TARGET};
use crate::{status_error, toolchain, target};
fn inner<I: Iterator<Item=String>>(mut args: I) -> io::Result<()> {
let toolchain_dir = toolchain()?;
......@@ -21,7 +21,7 @@ fn inner<I: Iterator<Item=String>>(mut args: I) -> io::Result<()> {
// TODO: Ensure no spaces in toolchain_dir
let rustflags = format!(
"-L {}",
toolchain_dir.join(TARGET).join("lib").display()
toolchain_dir.join(target()).join("lib").display()
);
let command = args.next().unwrap();
......@@ -53,7 +53,7 @@ fn inner<I: Iterator<Item=String>>(mut args: I) -> io::Result<()> {
crate::env::command("cargo")?
.arg(subcommand)
.arg("--target").arg(TARGET)
.arg("--target").arg(target())
.args(arguments)
.env("CARGO_TARGET_X86_64_UNKNOWN_REDOX_RUNNER", runner)
.env("RUSTFLAGS", rustflags)
......
use std::{env, ffi, io, process};
use crate::{status_error, toolchain, TARGET};
use crate::{status_error, toolchain, target};
pub fn command<S: AsRef<ffi::OsStr>>(program: S) -> io::Result<process::Command> {
let toolchain_dir = toolchain()?;
......@@ -17,10 +17,10 @@ pub fn command<S: AsRef<ffi::OsStr>>(program: S) -> io::Result<process::Command>
env::set_var("PATH", new_path);
}
let ar = format!("{}-ar", TARGET);
let cc = format!("{}-gcc", TARGET);
let cxx = format!("{}-g++", TARGET);
let cc_target_var = TARGET.replace("-", "_");
let ar = format!("{}-ar", target());
let cc = format!("{}-gcc", target());
let cxx = format!("{}-g++", target());
let cc_target_var = target().replace("-", "_");
let cargo_target_var = cc_target_var.to_uppercase();
let mut command = process::Command::new(program);
......@@ -29,7 +29,7 @@ pub fn command<S: AsRef<ffi::OsStr>>(program: S) -> io::Result<process::Command>
command.env(format!("CC_{}", cc_target_var), &cc);
command.env(format!("CXX_{}", cc_target_var), &cxx);
command.env("RUSTUP_TOOLCHAIN", &toolchain_dir);
command.env("TARGET", TARGET);
command.env("TARGET", target());
Ok(command)
}
......
......@@ -5,7 +5,7 @@ use std::path::{Path, PathBuf};
use std::process::{self, Command};
use std::time::{SystemTime, UNIX_EPOCH};
use crate::{installed, redoxer_dir, status_error, syscall_error, toolchain, TARGET};
use crate::{installed, redoxer_dir, status_error, syscall_error, toolchain, target};
use crate::redoxfs::RedoxFs;
static BASE_TOML: &'static str = include_str!("../res/base.toml");
......@@ -203,7 +203,7 @@ fn inner(arguments: &[String], folder_opt: Option<String>, gui: bool) -> io::Res
None
};
let toolchain_lib_dir = toolchain_dir.join(TARGET).join("lib");
let toolchain_lib_dir = toolchain_dir.join(target()).join("lib");
let lib_dir = redoxer_dir.join("lib");
for obj in &[
"ld64.so.1",
......
......@@ -8,7 +8,10 @@ mod exec;
mod redoxfs;
mod toolchain;
static TARGET: &'static str = "x86_64-unknown-redox";
const SUPPORTED_TARGETS: &'static [&'static str] = &[
"x86_64-unknown-redox",
"aarch64-unknown-redox"
];
//TODO: Confirm capabilities on other OSes
#[cfg(target_os = "linux")]
......@@ -65,6 +68,18 @@ fn usage() {
process::exit(1);
}
pub fn target() -> &'static str {
let target_from_env = std::env::var("TARGET").unwrap_or("".to_string());
let index = if SUPPORTED_TARGETS.contains(&&*target_from_env) == true {
SUPPORTED_TARGETS.iter().position(|t| **t == target_from_env).unwrap().into()
} else {
0usize
};
SUPPORTED_TARGETS[index]
}
pub fn main(args: &[String]) {
match args.get(1) {
Some(arg) => match arg.as_str() {
......
......@@ -2,7 +2,7 @@ use std::{env, fs, io};
use std::path::{Path, PathBuf};
use std::process::{self, Command};
use crate::{redoxer_dir, status_error, TARGET};
use crate::{redoxer_dir, status_error, target};
//TODO: Rewrite with hyper or reqwest, tar-rs, sha2, and some gzip crate?
fn download<P: AsRef<Path>>(url: &str, path: P) -> io::Result<()> {
......@@ -40,7 +40,7 @@ pub fn toolchain() -> io::Result<PathBuf> {
return Ok(PathBuf::from(redoxer_toolchain));
}
let url = format!("https://static.redox-os.org/toolchain/{}", TARGET);
let url = format!("https://static.redox-os.org/toolchain/{}", target());
let toolchain_dir = redoxer_dir().join("toolchain");
if ! toolchain_dir.is_dir() {
println!("redoxer: building toolchain");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment