From d9efd6635b6bc875427ce84f171ea4b541e623bd Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Fri, 13 Dec 2019 14:15:12 -0800 Subject: [PATCH] Store LLVM version info directly in internal_macros --- Cargo.toml | 1 + internal_macros/Cargo.toml | 5 ----- internal_macros/build.rs | 41 -------------------------------------- internal_macros/src/lib.rs | 15 +++++--------- 4 files changed, 6 insertions(+), 56 deletions(-) delete mode 100644 internal_macros/build.rs diff --git a/Cargo.toml b/Cargo.toml index 62fd67ee11f92..be89eec832518 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ edition = "2018" [features] default = ["target-all"] +# Please update internal_macros::FEATURE_VERSIONS when adding a new LLVM version llvm3-6 = [] llvm3-7 = [] llvm3-8 = [] diff --git a/internal_macros/Cargo.toml b/internal_macros/Cargo.toml index c76429513e4db..73269fe966d0d 100644 --- a/internal_macros/Cargo.toml +++ b/internal_macros/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors = ["Daniel Kolsoi "] description = "Internal macro crate for inkwell" edition = "2018" -build = "build.rs" repository = "https://github.com/TheDan64/inkwell" readme = "README.md" license = "Apache-2.0" @@ -14,9 +13,5 @@ quote = "0.6" syn = { version = "0.15", features = ["full", "fold"] } proc-macro2 = "0.4" -[build-dependencies] -cargo_toml = "0.8" -reqwest = "0.9" - [lib] proc-macro = true diff --git a/internal_macros/build.rs b/internal_macros/build.rs deleted file mode 100644 index d61e889f8530c..0000000000000 --- a/internal_macros/build.rs +++ /dev/null @@ -1,41 +0,0 @@ -extern crate cargo_toml; - -use cargo_toml::Manifest; - -use std::error::Error; -use std::path::Path; - -fn main() { - let (manifest, manifest_path) = get_manifest().expect("Unable to load Cargo manifest!"); - let features = manifest.features - .keys() - .filter(|feature| feature.as_str().starts_with("llvm")) - .cloned() - .collect::>(); - - let features_csv = features.as_slice().join(","); - - // Exports a comma-separated feature list in the environment during compilation - // Can be fetched with `env!("INKWELL_FEATURES")` - println!("cargo:rustc-env=INKWELL_FEATURES={}", features_csv); - if let Some(path) = manifest_path { - println!("cargo:rerun-if-changed={}", path); - } -} - -/// If we're developing locally we should use the local manifest -/// so that we don't have to duplicate LLVM version info. If we're publishing -/// then grab the manifest from online since we need internet access to publish anyway. -fn get_manifest() -> Result<(Manifest, Option<&'static str>), Box> { - const MANIFEST_PATH: &str = "../Cargo.toml"; - - Ok(match Manifest::from_path(Path::new(MANIFEST_PATH)) { - Ok(m) => (m, Some(MANIFEST_PATH)), - Err(_) => { - let manifest_str = reqwest::get("https://raw.githubusercontent.com/TheDan64/inkwell/master/Cargo.toml")?.text()?; - let manifest = Manifest::from_str(&manifest_str)?; - - (manifest, None) - }, - }) -} diff --git a/internal_macros/src/lib.rs b/internal_macros/src/lib.rs index 4cc166f8ae3ed..483477f557126 100644 --- a/internal_macros/src/lib.rs +++ b/internal_macros/src/lib.rs @@ -18,14 +18,9 @@ use syn::fold::Fold; use syn::spanned::Spanned; use syn::{Token, LitFloat, Ident, Item, Field, Variant, Attribute}; -const FEATURES_ENV: &str = env!("INKWELL_FEATURES"); - -/// Fetches a vector of feature version strings, e.g. llvm8-0 -fn get_feature_versions() -> Vec<&'static str> { - FEATURES_ENV - .split(',') - .collect() -} +// This array should match the LLVM features in the top level Cargo manifest +const FEATURE_VERSIONS: [&str; 9] = + ["llvm3-6", "llvm3-7", "llvm3-8", "llvm3-9", "llvm4-0", "llvm5-0", "llvm6-0", "llvm7-0", "llvm8-0"]; /// Gets the index of the feature version that represents `latest` fn get_latest_feature_index(features: &[&str]) -> usize { @@ -43,7 +38,7 @@ fn get_feature_index(features: &[&str], feature: String, span: Span) -> Result Result> { - let features = get_feature_versions(); + let features = FEATURE_VERSIONS; let latest = get_latest_feature_index(&features); match vt { VersionType::Specific(version, span) => { @@ -189,7 +184,7 @@ struct FeatureSet(Vec<&'static str>, Option); impl Default for FeatureSet { fn default() -> Self { // Default to all versions - Self(get_feature_versions(), None) + Self(FEATURE_VERSIONS.to_vec(), None) } } impl Parse for FeatureSet {