Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linting support on Apple Silicon #489

Merged
merged 3 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ walkdir = "2.3.2"
substrate-build-script-utils = "3.0.0"
platforms = "2.0.0"
which = "4.2.5"
regex = "1.5.5"

[dev-dependencies]
assert_cmd = "2.0.4"
Expand Down
14 changes: 13 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,16 @@ fn zip_dylint_driver(src_dir: &Path, dst_file: &Path, method: CompressionMethod)

let walkdir = WalkDir::new(src_dir);
let it = walkdir.into_iter().filter_map(|e| e.ok());
let regex = regex::Regex::new(r#"(lib)?ink_linting@.+\.(dll|so|dylib)"#)
.expect("Regex is correct; qed");
let mut lib_found = false;

for entry in it {
let path = entry.path();
let name = path.strip_prefix(&src_dir)?.to_path_buf();
let file_path = name.as_os_str().to_string_lossy();

if path.is_file() && path.display().to_string().contains("libink_linting@") {
if path.is_file() && regex.is_match(&path.display().to_string()) {
zip.start_file(file_path, options)?;
let mut f = File::open(path)?;

Expand All @@ -329,9 +332,18 @@ fn zip_dylint_driver(src_dir: &Path, dst_file: &Path, method: CompressionMethod)
buffer.clear();

zip.finish()?;
lib_found = true;
break;
}
}

if !lib_found {
anyhow::bail!(
"Couldn't find compiled lint. Is your architecture ({}) defined in ./ink_linting/.cargo/config.toml?",
std::env::var("TARGET").unwrap(),
);
}

Ok(())
}

Expand Down
27 changes: 27 additions & 0 deletions ink_linting/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
# This file corresponds to the `.cargo/config.toml` file used for the `dylint` examples here:
# https://github.com/trailofbits/dylint/tree/master/examples.

[target.aarch64-apple-darwin]
linker = "dylint-link"

[target.x86_64-apple-darwin]
linker = "dylint-link"

[target.aarch64-unknown-linux-gnu]
linker = "dylint-link"

[target.aarch64-unknown-linux-musl]
linker = "dylint-link"

[target.x86_64-unknown-linux-gnu]
linker = "dylint-link"

[target.x86_64-unknown-linux-musl]
linker = "dylint-link"

[target.x86_64-unknown-linux-gnux32]
linker = "dylint-link"

[target.aarch64-pc-windows-msvc]
linker = "dylint-link"

[target.i586-pc-windows-msvc]
linker = "dylint-link"

[target.i586-pc-windows-gnu]
linker = "dylint-link"

[target.x86_64-pc-windows-msvc]
linker = "dylint-link"

[target.x86_64-pc-windows-gnu]
linker = "dylint-link"