Skip to content

Commit 677ff02

Browse files
committed
Add support for using a custom target under linux
1 parent fa8f3ee commit 677ff02

File tree

2 files changed

+99
-1
lines changed

2 files changed

+99
-1
lines changed

openblas-build/src/build.rs

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
33
use crate::{check::*, error::*};
44
use std::{
5-
fs,
5+
fmt, fs,
66
os::unix::io::*,
77
path::*,
88
process::{Command, Stdio},
9+
str::FromStr,
910
};
1011
use walkdir::WalkDir;
1112

@@ -116,6 +117,99 @@ pub enum Target {
116117
Z14,
117118
}
118119

120+
impl FromStr for Target {
121+
type Err = ParseTargetError;
122+
123+
fn from_str(s: &str) -> Result<Self, Self::Err> {
124+
let target = match s.to_ascii_lowercase().as_str() {
125+
"p2" => Self::P2,
126+
"katamai" => Self::KATMAI,
127+
"coppermine" => Self::COPPERMINE,
128+
"northwood" => Self::NORTHWOOD,
129+
"prescott" => Self::PRESCOTT,
130+
"banias" => Self::BANIAS,
131+
"yonah" => Self::YONAH,
132+
"core2" => Self::CORE2,
133+
"penryn" => Self::PENRYN,
134+
"dunnington" => Self::DUNNINGTON,
135+
"nehalem" => Self::NEHALEM,
136+
"sandybridge" => Self::SANDYBRIDGE,
137+
"haswell" => Self::HASWELL,
138+
"skylakex" => Self::SKYLAKEX,
139+
"atom" => Self::ATOM,
140+
"athlon" => Self::ATHLON,
141+
"opteron" => Self::OPTERON,
142+
"opteron_sse3" => Self::OPTERON_SSE3,
143+
"barcelona" => Self::BARCELONA,
144+
"shanghai" => Self::SHANGHAI,
145+
"istanbul" => Self::ISTANBUL,
146+
"bobcat" => Self::BOBCAT,
147+
"bulldozer" => Self::BULLDOZER,
148+
"piledriver" => Self::PILEDRIVER,
149+
"steamroller" => Self::STEAMROLLER,
150+
"excavator" => Self::EXCAVATOR,
151+
"zen" => Self::ZEN,
152+
"sse_generic" => Self::SSE_GENERIC,
153+
"viac3" => Self::VIAC3,
154+
"nano" => Self::NANO,
155+
"power4" => Self::POWER4,
156+
"power5" => Self::POWER5,
157+
"power6" => Self::POWER6,
158+
"power7" => Self::POWER7,
159+
"power8" => Self::POWER8,
160+
"power9" => Self::POWER9,
161+
"ppcg4" => Self::PPCG4,
162+
"ppc970" => Self::PPC970,
163+
"ppc970mp" => Self::PPC970MP,
164+
"ppc440" => Self::PPC440,
165+
"ppc440fp2" => Self::PPC440FP2,
166+
"cell" => Self::CELL,
167+
"p5600" => Self::P5600,
168+
"mips1004k" => Self::MIPS1004K,
169+
"mips24k" => Self::MIPS24K,
170+
"sicortex" => Self::SICORTEX,
171+
"loongson3a" => Self::LOONGSON3A,
172+
"loongson3b" => Self::LOONGSON3B,
173+
"i6400" => Self::I6400,
174+
"p6600" => Self::P6600,
175+
"i6500" => Self::I6500,
176+
"itanium2" => Self::ITANIUM2,
177+
"sparc" => Self::SPARC,
178+
"sparcv7" => Self::SPARCV7,
179+
"cortexa15" => Self::CORTEXA15,
180+
"cortexa9" => Self::CORTEXA9,
181+
"armv7" => Self::ARMV7,
182+
"armv6" => Self::ARMV6,
183+
"armv5" => Self::ARMV5,
184+
"armv8" => Self::ARMV8,
185+
"cortexa53" => Self::CORTEXA53,
186+
"cortexa57" => Self::CORTEXA57,
187+
"cortexa72" => Self::CORTEXA72,
188+
"cortexa73" => Self::CORTEXA73,
189+
"neoversen1" => Self::NEOVERSEN1,
190+
"emag8180" => Self::EMAG8180,
191+
"falkor" => Self::FALKOR,
192+
"thunderx" => Self::THUNDERX,
193+
"thunderx2t99" => Self::THUNDERX2T99,
194+
"tsv110" => Self::TSV110,
195+
"zarch_generic" => Self::ZARCH_GENERIC,
196+
"z13" => Self::Z13,
197+
"z14" => Self::Z14,
198+
_ => return Err(ParseTargetError::default()),
199+
};
200+
Ok(target)
201+
}
202+
}
203+
204+
#[derive(Debug, Clone, PartialEq, Eq, Default)]
205+
pub struct ParseTargetError;
206+
207+
impl fmt::Display for ParseTargetError {
208+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
209+
"provided string was not a valid target".fmt(f)
210+
}
211+
}
212+
119213
/// make option generator
120214
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
121215
pub struct Configure {

openblas-src/build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ fn build() {
104104
} else {
105105
cfg.no_static = true;
106106
}
107+
cfg.target = match env::var("OPENBLAS_TARGET") {
108+
Ok(target) => target.parse().ok(),
109+
_ => None,
110+
};
107111

108112
let output = if feature_enabled("cache") {
109113
use std::{collections::hash_map::DefaultHasher, hash::*};

0 commit comments

Comments
 (0)