Skip to content

Commit

Permalink
Fix linting support on Apple Silicon (#489)
Browse files Browse the repository at this point in the history
* Fix linting support on M1

* Fix CI and add arch to debug output

* Fix regex for windows
  • Loading branch information
athei authored Apr 5, 2022
1 parent 8806e40 commit 7f6568d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
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"

0 comments on commit 7f6568d

Please sign in to comment.