Skip to content

Commit 983ebb7

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` - Use cargo instructions to link builds correctly. This assures, that the linkage is always correct, even when we change the structure
1 parent 6d96df1 commit 983ebb7

File tree

7 files changed

+85
-69
lines changed

7 files changed

+85
-69
lines changed

rust/Cargo.lock

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

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: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22
//
33
// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception
44

5+
use std::env;
56
use std::fs::canonicalize;
67

78
fn main() {
8-
println!(
9-
"cargo:rustc-link-search={}",
10-
canonicalize("./lib").unwrap().to_string_lossy()
11-
);
12-
println!("cargo:rustc-link-lib=static=gcrypt");
13-
println!("cargo:rustc-link-lib=static=gpg-error");
149
println!("cargo:rerun-if-changed=c/cryptographic/gcrypt_mac.c");
1510
println!("cargo:rerun-if-changed=c/cryptographic/gcrypt_error.c");
16-
println!("cargo:rerun-if-changed=lib/libgcrypt.a");
17-
println!("cargo:rerun-if-changed=lib/libgpg-error.a");
11+
12+
let include_dir = env::var("DEP_GCRYPT_INCLUDE").unwrap();
13+
let lib_dir = env::var("DEP_GCRYPT_LIB").unwrap();
14+
15+
println!("cargo:rustc-link-search=native={lib_dir}");
16+
println!("cargo:rustc-link-lib=static=gcrypt");
17+
println!("cargo:rustc-link-lib=static=gpg-error");
1818

1919
cc::Build::new()
2020
.file("c/cryptographic/gcrypt_mac.c")
2121
.file("c/cryptographic/gcrypt_error.c")
22-
.include(canonicalize("./include").unwrap())
22+
.include(canonicalize(include_dir).unwrap())
2323
.opt_level(2)
2424
.compile("crypt");
2525
}

rust/crates/nasl-c-lib/libgcrypt-sys/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ name = "libgcrypt-sys"
33
version = "0.1.0"
44
edition = "2024"
55
links = "gcrypt"
6+
7+
[build-dependencies]
8+
autotools = "0.2"

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

Lines changed: 58 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,66 @@
22
//
33
// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception
44

5-
use std::{env, process::Command};
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";
613

714
fn main() {
8-
println!("cargo:rerun-if-changed=install-gcrypt.sh");
9-
let target = env::var("TARGET").unwrap_or_default();
10-
let cross = env::var("IN_CROSS").unwrap_or_default();
11-
let clean = env::var("CLEAN").unwrap_or_default();
12-
let out = Command::new("sh")
13-
.arg("install-gcrypt.sh")
14-
.env("TARGET", target)
15-
.env("IN_CROSS", cross)
16-
.env("CLEAN", clean)
17-
.output();
18-
match out {
19-
Ok(out) => {
20-
match out.status.code() {
21-
Some(0) | None => {
22-
//everything is dandy
23-
}
24-
Some(status) => {
25-
panic!(
26-
"Script exited with {status}:\nstdout:\n{}\nstderr:\n{}",
27-
String::from_utf8_lossy(&out.stdout),
28-
String::from_utf8_lossy(&out.stderr)
29-
);
30-
}
31-
}
15+
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
16+
let target = env::var("TARGET").unwrap();
17+
18+
let path = fetch_source("libgpg-error", GPG_ERROR_VERSION, &out_dir);
19+
build_autotools_project(&path, &target);
20+
21+
let path = fetch_source("libgcrypt", LIBGCRYPT_VERSION, &out_dir);
22+
build_autotools_project(&path, &target);
23+
24+
let include_dir = out_dir.join("include");
25+
let lib_dir = out_dir.join("lib");
26+
27+
println!("cargo:include={}", include_dir.display());
28+
println!("cargo:lib={}", lib_dir.display());
29+
println!("cargo::rerun-if-env-changed=TARGET");
30+
}
31+
32+
fn fetch_source(name: &str, version: &str, destination: &Path) -> PathBuf {
33+
let folder_name = format!("{}-{}", name, version);
34+
let extract_path = destination.join(&folder_name);
35+
let tar_path = extract_path.with_added_extension("tar.bz2");
36+
37+
if !extract_path.exists() {
38+
if !tar_path.exists() {
39+
let url = format!("https://gnupg.org/ftp/gcrypt/{name}/{folder_name}.tar.bz2");
40+
41+
Command::new("curl")
42+
.args(["--fail", "-O", &url])
43+
.current_dir(destination)
44+
.status()
45+
.unwrap();
3246
}
33-
Err(e) => panic!("Unexpected error: {e}"),
47+
48+
Command::new("tar")
49+
.args(["-xf", &tar_path.to_string_lossy()])
50+
.current_dir(destination)
51+
.status()
52+
.unwrap();
3453
}
54+
55+
extract_path
56+
}
57+
58+
fn build_autotools_project(src: &Path, target: &str) -> PathBuf {
59+
let mut config = autotools::Config::new(src);
60+
config
61+
.enable_static()
62+
.disable_shared()
63+
.config_option("with-pic", None)
64+
.host(&target);
65+
66+
config.build()
3567
}

rust/crates/nasl-c-lib/libgcrypt-sys/install-gcrypt.sh

Lines changed: 0 additions & 30 deletions
This file was deleted.

rust/src/nasl/builtin/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ mod isotime;
1616
mod knowledge_base;
1717
pub mod misc;
1818
pub mod network;
19-
mod snmp;
20-
2119
mod preferences;
2220
#[cfg(feature = "nasl-builtin-raw-ip")]
2321
pub mod raw_ip;
2422
mod regex;
2523
mod report_functions;
24+
mod snmp;
2625
mod ssh;
2726
mod string;
2827
mod sys;

0 commit comments

Comments
 (0)