Skip to content

Commit 3cb0a8b

Browse files
committed
Clean up build scripts
This includes: - Move all build artifacts to target directory, so they will be cleaned with a `cargo clean` - Remove shell script for building `libgcrypt` and `libgpg-error`. Instead building it within `build.rs` - Compile needed c functions in sys crate - Provide bindings in sys crate - Re-export sys crate in nas-c-lib to make bindings available
1 parent 6d96df1 commit 3cb0a8b

File tree

21 files changed

+109
-6552
lines changed

21 files changed

+109
-6552
lines changed

rust/Cargo.lock

Lines changed: 0 additions & 6443 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/Cargo.toml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ license = "GPL-2.0-or-later"
77
[workspace.dependencies]
88
anyhow = "1.0.75"
99
cc = "1.0"
10+
bindgen = "0.72"
11+
autotools = "0.2"
1012
clap = { version = "4.5.27", features = ["derive", "env"] }
1113
futures = "0.3.30"
1214
futures-util = "0.3.28"
@@ -73,7 +75,11 @@ pnet = { version = "0.35.0", optional = true }
7375
pnet_base = { version = "0.35.0", optional = true }
7476
pnet_macros = { version = "0.35.0", optional = true }
7577
pnet_macros_support = { version = "0.35.0", optional = true }
76-
quick-xml = { version = "0.38.1", features = ["serde", "serde-types", "serialize",] }
78+
quick-xml = { version = "0.38.1", features = [
79+
"serde",
80+
"serde-types",
81+
"serialize",
82+
] }
7783
rand = "0.9.2"
7884
rand_core = "0.6.4"
7985
rc4 = "0.1.0"
@@ -85,7 +91,9 @@ russh = "0.54.2"
8591
rustls-native-certs = "0.8.1"
8692
search_path = "0.1.4"
8793
sequoia-ipc = "0.36.0"
88-
sequoia-openpgp = { version = "2.0.0", default-features = false, features = ["crypto-openssl",] }
94+
sequoia-openpgp = { version = "2.0.0", default-features = false, features = [
95+
"crypto-openssl",
96+
] }
8997
sha1 = "0.10.5"
9098
snmp2 = { version = "0.4.8", features = ["full"] }
9199
socket2 = { version = "0.6.0", features = ["all"] }
@@ -107,7 +115,7 @@ serde = { workspace = true }
107115
serde_json = { workspace = true }
108116
sha2 = { workspace = true }
109117
thiserror = { workspace = true }
110-
tokio = {workspace = true }
118+
tokio = { workspace = true }
111119
tokio-rustls = { workspace = true }
112120
tracing = { workspace = true }
113121
tracing-subscriber = { workspace = true }

rust/Cross.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
[build.env]
2-
passthrough = ["IN_CROSS=1", "CLEAN=1"]
31
[target.aarch64-unknown-linux-gnu]
42
dockerfile = "cross_aarch64.Dockerfile"
3+
[target.aarch64-unknown-linux-gnu.env]
4+
passthrough = ["CC=aarch64-linux-gnu-gcc", "CHOST=arm64"]
55
[target.x86_64-unknown-linux-gnu]
66
dockerfile = "cross.Dockerfile"

rust/crates/nasl-c-lib/build.rs

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "libcrypt-sys"
3+
version = "0.1.0"
4+
edition = "2024"
5+
links = "crypt"
6+
7+
[build-dependencies]
8+
autotools = { workspace = true }
9+
cc = { workspace = true }
10+
bindgen = { workspace = true }
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// SPDX-FileCopyrightText: 2024 Greenbone AG
2+
//
3+
// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception
4+
5+
use std::{
6+
env,
7+
path::{Path, PathBuf},
8+
process::Command,
9+
};
10+
11+
const GPG_ERROR_VERSION: &str = "1.54";
12+
const LIBGCRYPT_VERSION: &str = "1.10.2";
13+
14+
fn main() {
15+
println!("cargo:rerun-if-changed=build.rs");
16+
println!("cargo:rerun-if-changed=c/gcrypt_error.c");
17+
println!("cargo:rerun-if-changed=c/gcrypt_error.h");
18+
println!("cargo:rerun-if-changed=c/gcrypt_mac.c");
19+
println!("cargo:rerun-if-changed=c/gcrypt_mac.h");
20+
println!("cargo::rerun-if-env-changed=TARGET");
21+
22+
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
23+
let target = env::var("TARGET").unwrap();
24+
25+
let path = fetch_source("libgpg-error", GPG_ERROR_VERSION, &out_dir);
26+
build_autotools_project(&path, &target);
27+
28+
let path = fetch_source("libgcrypt", LIBGCRYPT_VERSION, &out_dir);
29+
build_autotools_project(&path, &target);
30+
31+
let include_dir = out_dir.join("include");
32+
let lib_dir = out_dir.join("lib");
33+
34+
println!("cargo:rustc-link-search=native={}", lib_dir.display());
35+
println!("cargo:rustc-link-lib=static=gcrypt");
36+
println!("cargo:rustc-link-lib=static=gpg-error");
37+
38+
cc::Build::new()
39+
.file("c/gcrypt_mac.c")
40+
.file("c/gcrypt_error.c")
41+
.include(include_dir)
42+
.opt_level(2)
43+
.compile("crypt");
44+
}
45+
46+
fn fetch_source(name: &str, version: &str, destination: &Path) -> PathBuf {
47+
let folder_name = format!("{}-{}", name, version);
48+
let extract_path = destination.join(&folder_name);
49+
let tar_path = extract_path.with_added_extension("tar.bz2");
50+
51+
if !extract_path.exists() {
52+
if !tar_path.exists() {
53+
let url = format!("https://gnupg.org/ftp/gcrypt/{name}/{folder_name}.tar.bz2");
54+
55+
Command::new("curl")
56+
.args(["--fail", "-O", &url])
57+
.current_dir(destination)
58+
.status()
59+
.unwrap();
60+
}
61+
62+
Command::new("tar")
63+
.args(["-xf", &tar_path.to_string_lossy()])
64+
.current_dir(destination)
65+
.status()
66+
.unwrap();
67+
}
68+
69+
extract_path
70+
}
71+
72+
fn build_autotools_project(src: &Path, target: &str) -> PathBuf {
73+
let mut config = autotools::Config::new(src);
74+
config
75+
.enable_static()
76+
.disable_shared()
77+
.config_option("with-pic", None)
78+
.host(target);
79+
80+
config.build()
81+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)