Skip to content

Commit 41c146d

Browse files
committed
rust: use once_cell
This seems to be the modern replacement for lazy_static.
1 parent 5a1bc3c commit 41c146d

File tree

3 files changed

+82
-63
lines changed

3 files changed

+82
-63
lines changed

Cargo.lock

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ edition = "2018"
88
anyhow = "1.0"
99
clap = "2.33"
1010
goblin = "0.3"
11-
lazy_static = "1.4"
11+
once_cell = "1"
1212
scroll = "0.10"
1313
serde_json = "1.0"
1414
serde = { version = "1.0", features = ["derive"] }

src/main.rs

Lines changed: 74 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use {
1010
anyhow::{anyhow, Context, Result},
1111
clap::{App, AppSettings, Arg, ArgMatches, SubCommand},
1212
goblin::mach::load_command::CommandVariant,
13-
lazy_static::lazy_static,
13+
once_cell::sync::Lazy,
1414
scroll::Pread,
1515
std::{
1616
collections::{BTreeSet, HashMap},
@@ -113,19 +113,28 @@ const PE_ALLOWED_LIBRARIES: &[&str] = &[
113113
"tk86t.dll",
114114
];
115115

116-
lazy_static! {
117-
static ref GLIBC_MAX_VERSION: version_compare::Version<'static> =
118-
version_compare::Version::from("2.19").unwrap();
116+
static GLIBC_MAX_VERSION: Lazy<version_compare::Version<'static>> =
117+
Lazy::new(|| version_compare::Version::from("2.19").unwrap());
119118

120-
static ref ELF_ALLOWED_LIBRARIES_BY_TRIPLE: HashMap<&'static str, Vec<&'static str>> = {
119+
static ELF_ALLOWED_LIBRARIES_BY_TRIPLE: Lazy<HashMap<&'static str, Vec<&'static str>>> =
120+
Lazy::new(|| {
121121
[
122-
("armv7-unknown-linux-gnueabi", vec!["ld-linux.so.3", "libgcc_s.so.1"]),
123-
("armv7-unknown-linux-gnueabihf", vec!["ld-linux-armhf.so.3", "libgcc_s.so.1"]),
124-
].iter().cloned().collect()
125-
};
122+
(
123+
"armv7-unknown-linux-gnueabi",
124+
vec!["ld-linux.so.3", "libgcc_s.so.1"],
125+
),
126+
(
127+
"armv7-unknown-linux-gnueabihf",
128+
vec!["ld-linux-armhf.so.3", "libgcc_s.so.1"],
129+
),
130+
]
131+
.iter()
132+
.cloned()
133+
.collect()
134+
});
126135

127-
static ref DARWIN_ALLOWED_DYLIBS: Vec<MachOAllowedDylib> = {
128-
[
136+
static DARWIN_ALLOWED_DYLIBS: Lazy<Vec<MachOAllowedDylib>> = Lazy::new(|| {
137+
[
129138
MachOAllowedDylib {
130139
name: "@executable_path/../lib/libpython3.8.dylib".to_string(),
131140
max_compatibility_version: "3.8.0".try_into().unwrap(),
@@ -230,56 +239,60 @@ lazy_static! {
230239
},
231240
]
232241
.to_vec()
233-
};
234-
static ref IOS_ALLOWED_DYLIBS: Vec<MachOAllowedDylib> = {
235-
[
236-
MachOAllowedDylib {
237-
name: "@executable_path/../lib/libpython3.9.dylib".to_string(),
238-
max_compatibility_version: "3.9.0".try_into().unwrap(),
239-
required: false,
240-
},
241-
MachOAllowedDylib {
242-
name: "@executable_path/../lib/libpython3.9d.dylib".to_string(),
243-
max_compatibility_version: "3.9.0".try_into().unwrap(),
244-
required: false,
245-
},
246-
// For some reason, CoreFoundation is present in debug/noopt builds but not
247-
// LTO builds.
248-
MachOAllowedDylib {
249-
name: "/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation".to_string(),
250-
max_compatibility_version: "150.0.0".try_into().unwrap(),
251-
required: false,
252-
},
253-
MachOAllowedDylib {
254-
name: "/usr/lib/libSystem.B.dylib".to_string(),
255-
max_compatibility_version: "1.0.0".try_into().unwrap(),
256-
required: true,
257-
},
258-
MachOAllowedDylib {
259-
name: "/usr/lib/libz.1.dylib".to_string(),
260-
max_compatibility_version: "1.0.0".try_into().unwrap(),
261-
required: true,
262-
},
263-
].to_vec()
264-
};
265-
266-
static ref PLATFORM_TAG_BY_TRIPLE: HashMap<&'static str, &'static str> = {
267-
[
268-
("aarch64-apple-darwin", "macosx-11.0-arm64"),
269-
("aarch64-apple-ios", "iOS-aarch64"),
270-
("aarch64-unknown-linux-gnu", "linux-aarch64"),
271-
("armv7-unknown-linux-gnueabi", "linux-arm"),
272-
("armv7-unknown-linux-gnueabihf", "linux-arm"),
273-
("i686-pc-windows-msvc", "win32"),
274-
("i686-unknown-linux-gnu", "linux-i686"),
275-
("x86_64-apple-darwin", "macosx-10.9-x86_64"),
276-
("x86_64-apple-ios", "iOS-x86_64"),
277-
("x86_64-pc-windows-msvc", "win-amd64"),
278-
("x86_64-unknown-linux-gnu", "linux-x86_64"),
279-
("x86_64-unknown-linux-musl", "linux-x86_64"),
280-
].iter().cloned().collect()
281-
};
282-
}
242+
});
243+
244+
static IOS_ALLOWED_DYLIBS: Lazy<Vec<MachOAllowedDylib>> = Lazy::new(|| {
245+
[
246+
MachOAllowedDylib {
247+
name: "@executable_path/../lib/libpython3.9.dylib".to_string(),
248+
max_compatibility_version: "3.9.0".try_into().unwrap(),
249+
required: false,
250+
},
251+
MachOAllowedDylib {
252+
name: "@executable_path/../lib/libpython3.9d.dylib".to_string(),
253+
max_compatibility_version: "3.9.0".try_into().unwrap(),
254+
required: false,
255+
},
256+
// For some reason, CoreFoundation is present in debug/noopt builds but not
257+
// LTO builds.
258+
MachOAllowedDylib {
259+
name: "/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation".to_string(),
260+
max_compatibility_version: "150.0.0".try_into().unwrap(),
261+
required: false,
262+
},
263+
MachOAllowedDylib {
264+
name: "/usr/lib/libSystem.B.dylib".to_string(),
265+
max_compatibility_version: "1.0.0".try_into().unwrap(),
266+
required: true,
267+
},
268+
MachOAllowedDylib {
269+
name: "/usr/lib/libz.1.dylib".to_string(),
270+
max_compatibility_version: "1.0.0".try_into().unwrap(),
271+
required: true,
272+
},
273+
]
274+
.to_vec()
275+
});
276+
277+
static PLATFORM_TAG_BY_TRIPLE: Lazy<HashMap<&'static str, &'static str>> = Lazy::new(|| {
278+
[
279+
("aarch64-apple-darwin", "macosx-11.0-arm64"),
280+
("aarch64-apple-ios", "iOS-aarch64"),
281+
("aarch64-unknown-linux-gnu", "linux-aarch64"),
282+
("armv7-unknown-linux-gnueabi", "linux-arm"),
283+
("armv7-unknown-linux-gnueabihf", "linux-arm"),
284+
("i686-pc-windows-msvc", "win32"),
285+
("i686-unknown-linux-gnu", "linux-i686"),
286+
("x86_64-apple-darwin", "macosx-10.9-x86_64"),
287+
("x86_64-apple-ios", "iOS-x86_64"),
288+
("x86_64-pc-windows-msvc", "win-amd64"),
289+
("x86_64-unknown-linux-gnu", "linux-x86_64"),
290+
("x86_64-unknown-linux-musl", "linux-x86_64"),
291+
]
292+
.iter()
293+
.cloned()
294+
.collect()
295+
});
283296

284297
fn allowed_dylibs_for_triple(triple: &str) -> Vec<MachOAllowedDylib> {
285298
match triple {

0 commit comments

Comments
 (0)