Skip to content

Commit 311d93a

Browse files
committed
Clean up build scripts
1 parent 6d96df1 commit 311d93a

File tree

6 files changed

+83
-67
lines changed

6 files changed

+83
-67
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/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+
17+
let path = fetch_source("libgpg-error", GPG_ERROR_VERSION, &out_dir);
18+
build_autotools_project(&path);
19+
20+
let path = fetch_source("libgcrypt", LIBGCRYPT_VERSION, &out_dir);
21+
build_autotools_project(&path);
22+
23+
let include_dir = out_dir.join("include");
24+
let lib_dir = out_dir.join("lib");
25+
26+
println!("cargo:include={}", include_dir.display());
27+
println!("cargo:lib={}", lib_dir.display());
28+
}
29+
30+
fn fetch_source(name: &str, version: &str, destination: &Path) -> PathBuf {
31+
let folder_name = format!("{}-{}", name, version);
32+
let extract_path = destination.join(&folder_name);
33+
let tar_path = extract_path.with_added_extension("tar.bz2");
34+
35+
if !extract_path.exists() {
36+
if !tar_path.exists() {
37+
let url = format!("https://gnupg.org/ftp/gcrypt/{name}/{folder_name}.tar.bz2");
38+
39+
Command::new("curl")
40+
.args(["--fail", "-O", &url])
41+
.current_dir(destination)
42+
.status()
43+
.unwrap();
3244
}
33-
Err(e) => panic!("Unexpected error: {e}"),
45+
46+
Command::new("tar")
47+
.args(["-xf", &tar_path.to_string_lossy()])
48+
.current_dir(destination)
49+
.status()
50+
.unwrap();
3451
}
52+
53+
extract_path
54+
}
55+
56+
fn build_autotools_project(src: &Path) -> PathBuf {
57+
let target = env::var("TARGET").unwrap();
58+
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)