From a396483141ae50e438b22dabb8da698678a66b1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Mon, 4 Apr 2022 15:53:38 +0200 Subject: [PATCH 1/5] Fix linting support on M1 --- Cargo.toml | 1 + build.rs | 11 ++++++++++- ink_linting/.cargo/config.toml | 27 +++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index bb7f1e4d..06302129 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/build.rs b/build.rs index 7b5618ed..e1a3d131 100644 --- a/build.rs +++ b/build.rs @@ -26,6 +26,7 @@ use std::{ }; use anyhow::Result; +use regex::Regex; use walkdir::WalkDir; use zip::{write::FileOptions, CompressionMethod, ZipWriter}; @@ -314,13 +315,15 @@ 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::new(r#"libink_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)?; @@ -329,9 +332,15 @@ 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?"); + } + Ok(()) } diff --git a/ink_linting/.cargo/config.toml b/ink_linting/.cargo/config.toml index e8488c83..55e90548 100644 --- a/ink_linting/.cargo/config.toml +++ b/ink_linting/.cargo/config.toml @@ -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" -- GitLab From 15ea70053602d2f5bc2000df0f9d6d5f8b35e710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Tue, 5 Apr 2022 01:20:54 +0200 Subject: [PATCH 2/5] Fix CI and add arch to debug output --- build.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/build.rs b/build.rs index e1a3d131..1d6a5e01 100644 --- a/build.rs +++ b/build.rs @@ -26,7 +26,6 @@ use std::{ }; use anyhow::Result; -use regex::Regex; use walkdir::WalkDir; use zip::{write::FileOptions, CompressionMethod, ZipWriter}; @@ -315,7 +314,8 @@ 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::new(r#"libink_linting@.+\.(dll|so|dylib)"#).expect("Regex is correct; qed"); + let regex = + regex::Regex::new(r#"libink_linting@.+\.(dll|so|dylib)"#).expect("Regex is correct; qed"); let mut lib_found = false; for entry in it { @@ -338,7 +338,10 @@ fn zip_dylint_driver(src_dir: &Path, dst_file: &Path, method: CompressionMethod) } if !lib_found { - anyhow::bail!("Couldn't find compiled lint. Is your architecture defined in ./ink_linting/.cargo/config.toml?"); + anyhow::bail!( + "Couldn't find compiled lint. Is your architecture ({}) defined in ./ink_linting/.cargo/config.toml?", + std::env::var("TARGET").unwrap(), + ); } Ok(()) -- GitLab From 21abdad640cf77ca0b86cd2c5751c5bebc24058d Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Tue, 5 Apr 2022 06:18:04 +0200 Subject: [PATCH 3/5] Add debug output --- build.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/build.rs b/build.rs index 1d6a5e01..d597af64 100644 --- a/build.rs +++ b/build.rs @@ -323,6 +323,7 @@ fn zip_dylint_driver(src_dir: &Path, dst_file: &Path, method: CompressionMethod) let name = path.strip_prefix(&src_dir)?.to_path_buf(); let file_path = name.as_os_str().to_string_lossy(); + println!("path: {:?}", path.display().to_string()); if path.is_file() && regex.is_match(&path.display().to_string()) { zip.start_file(file_path, options)?; let mut f = File::open(path)?; -- GitLab From ba5bcaef6f456226de63483bd8a699ec7929b8f3 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Tue, 5 Apr 2022 07:33:53 +0200 Subject: [PATCH 4/5] Debug dll for Windows --- build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.rs b/build.rs index d597af64..7669406f 100644 --- a/build.rs +++ b/build.rs @@ -315,7 +315,7 @@ 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#"libink_linting@.+\.(dll|so|dylib)"#).expect("Regex is correct; qed"); + regex::Regex::new(r#"(lib)?ink_linting@.+\.(dll|so|dylib)"#).expect("Regex is correct; qed"); let mut lib_found = false; for entry in it { -- GitLab From a49fefcd35d91bbc03b4613f41193aa7921e7787 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Tue, 5 Apr 2022 07:55:56 +0200 Subject: [PATCH 5/5] Apply `cargo fmt` --- build.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.rs b/build.rs index 7669406f..5c7f9f11 100644 --- a/build.rs +++ b/build.rs @@ -314,8 +314,8 @@ 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 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 { -- GitLab