Skip to content

Commit 47bb784

Browse files
committed
dataplane now builds, but need to undo lots of hacks
1 parent 4a5df4f commit 47bb784

File tree

12 files changed

+169
-198
lines changed

12 files changed

+169
-198
lines changed

.cargo/config.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
[env]
2-
COMPILE_ENV = { value = "sysroot", relative = true, force = false }
3-
#PATH = { value = "compile-env/bin", relative = true, force = true }
4-
#LIBCLANG_PATH = { value = "compile-env/lib", relative = true, force = true }
5-
# PKG_CONFIG_PATH = { value = "compile-env/sysroot/x86_64-unknown-linux-gnu/release/lib/pkgconfig", relative = true, force = true }
2+
# COMPILE_ENV = { value = "sysroot", relative = true, force = false }
3+
# PATH = { value = "compile-env/bin", relative = true, force = true }
4+
LIBCLANG_PATH = { value = "compile-env/lib", relative = true, force = false }
5+
PKG_CONFIG_PATH = { value = "compile-env/sysroot/x86_64-unknown-linux-gnu/release/lib/pkgconfig", relative = true, force = false }
6+
LIBRARY_PATH = { value = "sysroot/lib", relative = true, force = false }
7+
C_INCLUDE_PATH = { value = "sysroot/include", relative = true, force = false }
8+
GW_CRD_PATH = { value = "devroot/src/gateway/config/crd/bases", relative = true, force = false }
69

710
[build]
811
target = "x86_64-unknown-linux-gnu"

Cargo.lock

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

default.nix

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ let
3232
};
3333
dataplane-dev-pkgs = import sources.nixpkgs {
3434
overlays = [
35+
overlays.llvm
3536
overlays.dataplane-dev
3637
];
3738
};
3839
dataplane-pkgs =
3940
(import sources.nixpkgs {
4041
overlays = [
42+
overlays.llvm
4143
overlays.dataplane
4244
];
4345
}).pkgsCross.${platform'.info.nixarch};
@@ -75,8 +77,8 @@ let
7577
executable = false;
7678
destination = "/.clangd";
7779
};
78-
crane = import sources.crane { };
79-
craneLib = crane.craneLib.overrideToolchain dataplane-pkgs.rust-toolchain;
80+
crane-base = import sources.crane { };
81+
crane = crane-base.craneLib.overrideToolchain dataplane-dev-pkgs.rust-toolchain;
8082
dev-tools = dataplane-pkgs.symlinkJoin {
8183
name = "dataplane-dev-shell";
8284
paths = [
@@ -96,6 +98,7 @@ let
9698
cargo-llvm-cov
9799
cargo-nextest
98100
direnv
101+
gateway-crd
99102
just
100103
npins
101104
]);
@@ -116,6 +119,14 @@ let
116119
dataplane-pkgs.hwloc
117120
];
118121

122+
env = {
123+
LIBCLANG_PATH = "${dataplane-pkgs.llvmPackages.libclang.lib}/lib";
124+
C_INCLUDE_PATH = "${sysroot}/include";
125+
LIBRARY_PATH = "${sysroot}/lib";
126+
PKG_CONFIG_PATH = "${sysroot}/lib/pkgconfig";
127+
GW_CRD_PATH = "${dataplane-dev-pkgs.gateway-crd}/src/gateway/config/crd/bases";
128+
};
129+
119130
# Additional environment variables can be set directly
120131
# MY_CUSTOM_VAR = "some value";
121132
};
@@ -136,11 +147,6 @@ let
136147
root = ./.;
137148
fileset = lib.fileset.unions [
138149
./.
139-
./Cargo.toml
140-
./Cargo.lock
141-
# (crane.fileset.commonCargoSources ./crates/my-common)
142-
# (crane.fileset.commonCargoSources ./crates/my-workspace-hack)
143-
(crane.fileset.commonCargoSources crate)
144150
];
145151
};
146152
rekon = crane.buildPackage (
@@ -181,11 +187,6 @@ let
181187
pname = "dataplane-dpdk-sys";
182188
cargoExtraArgs = "--package dataplane-dpdk-sys";
183189
src = fileSetForCrate ./dpdk-sys;
184-
env = {
185-
LIBCLANG_PATH = "${dataplane-pkgs.llvmPackages.libclang.lib}/lib";
186-
C_INCLUDE_PATH = "${dataplane-pkgs.dpdk.dev}/include:${dataplane-pkgs.libbsd.dev}/include:${dataplane-pkgs.stdenv'.cc.libc.dev}/include";
187-
LIBRARY_PATH = "${sysroot}/lib";
188-
};
189190
nativeBuildInputs = [
190191
dataplane-pkgs.pkg-config
191192
dataplane-pkgs.llvmPackages.libclang.lib
@@ -203,11 +204,6 @@ let
203204
pname = "dataplane-dpdk";
204205
cargoExtraArgs = "--package dataplane-dpdk";
205206
src = fileSetForCrate ./dpdk;
206-
env = {
207-
LIBCLANG_PATH = "${dataplane-pkgs.llvmPackages.libclang.lib}/lib";
208-
C_INCLUDE_PATH = "${dataplane-pkgs.dpdk.dev}/include:${dataplane-pkgs.libbsd.dev}/include:${dataplane-pkgs.stdenv'.cc.libc.dev}/include";
209-
LIBRARY_PATH = "${sysroot}/lib";
210-
};
211207
nativeBuildInputs = [
212208
dataplane-pkgs.pkg-config
213209
dataplane-pkgs.llvmPackages.libclang.lib
@@ -225,16 +221,12 @@ let
225221
pname = "dataplane";
226222
cargoExtraArgs = "--package dataplane";
227223
src = fileSetForCrate ./dataplane;
228-
env = {
229-
LIBCLANG_PATH = "${dataplane-pkgs.llvmPackages.libclang.lib}/lib";
230-
C_INCLUDE_PATH = "${dataplane-pkgs.dpdk.dev}/include:${dataplane-pkgs.libbsd.dev}/include:${dataplane-pkgs.stdenv'.cc.libc.dev}/include";
231-
LIBRARY_PATH = "${sysroot}/lib";
232-
};
233224
nativeBuildInputs = [
234225
dataplane-pkgs.pkg-config
235226
dataplane-pkgs.llvmPackages.libclang.lib
236227
dataplane-pkgs.llvmPackages.clang
237228
dataplane-pkgs.llvmPackages.lld
229+
dataplane-dev-pkgs.kopium
238230
];
239231
buildInputs = [
240232
sysroot
@@ -269,7 +261,6 @@ in
269261
x = (builtins.attrNames crane.craneLib);
270262
};
271263
};
272-
z = dataplane-pkgs.runCommand "ls" { } "echo potato > $out";
273264
# y = crane.buildPackage
274265

275266
}

k8s-intf/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ lpm = { workspace = true, features = [] }
3737
net = { workspace = true, features = ["bolero", "test_buffer"] }
3838

3939
[build-dependencies]
40-
dotenvy = { workspace = true, features = [] }
41-
ureq = { workspace = true, features = ["rustls", "gzip"] }
40+
# dotenvy = { workspace = true, features = [] }
41+
# ureq = { workspace = true, features = ["rustls", "gzip"] }

k8s-intf/build.rs

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,10 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// Copyright Open Network Fabric Authors
33

4-
use std::env;
54
use std::fs;
5+
use std::io::Read;
66
use std::path::PathBuf;
77

8-
fn workspace_root() -> PathBuf {
9-
PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"))
10-
.ancestors()
11-
.nth(1)
12-
.expect("Workspace root not found")
13-
.to_path_buf()
14-
}
15-
16-
fn get_agent_crd_url() -> String {
17-
let env_file_path = workspace_root().join("scripts").join("k8s-crd.env");
18-
println!("cargo:rerun-if-changed={}", env_file_path.display());
19-
20-
let env_file =
21-
dotenvy::from_path_iter(env_file_path).expect("Failed to read scripts/k8s-crd.env");
22-
23-
env_file
24-
.filter_map(Result::ok)
25-
.find_map(|(key, value)| {
26-
if key == "K8S_GATEWAY_AGENT_CRD_URL" {
27-
Some(value)
28-
} else {
29-
None
30-
}
31-
})
32-
.expect("K8S_GATEWAY_AGENT_CRD_URL not found in scripts/k8s-crd.env")
33-
}
34-
35-
fn fetch_crd(url: &str) -> String {
36-
println!("cargo:note=Fetching CRD from: {url}");
37-
ureq::get(url)
38-
.call()
39-
.expect("Failed to fetch agent CRD from url")
40-
.body_mut()
41-
.read_to_string()
42-
.expect("Failed to read response body")
43-
}
44-
458
const LICENSE_PREAMBLE: &str = "// SPDX-License-Identifier: Apache-2.0
469
// Copyright Open Network Fabric Authors
4710
@@ -124,8 +87,31 @@ fn code_needs_regen(new_code: &str) -> bool {
12487
}
12588

12689
fn main() {
127-
let agent_crd_url = get_agent_crd_url();
128-
let agent_crd_contents = fetch_crd(&agent_crd_url);
90+
let agent_crd_contents = {
91+
let agent_crd_path =
92+
PathBuf::from(std::env::var("GW_CRD_PATH").expect("GW_CRD_PATH var unset"))
93+
.join("gwint.githedgehog.com_gatewayagents.yaml");
94+
let mut agent_crd_file = std::fs::OpenOptions::new()
95+
.read(true)
96+
.write(false)
97+
.open(&agent_crd_path)
98+
.unwrap_or_else(|e| {
99+
panic!(
100+
"failed to open {path}: {e}",
101+
path = agent_crd_path.to_str().expect("non unicode crd path")
102+
)
103+
});
104+
let mut contents = String::with_capacity(
105+
agent_crd_file
106+
.metadata()
107+
.expect("unable to get crd metadata")
108+
.len() as usize,
109+
);
110+
agent_crd_file
111+
.read_to_string(&mut contents)
112+
.unwrap_or_else(|e| panic!("unable to read crd data into string: {e}"));
113+
contents
114+
};
129115
let agent_generated_code = generate_rust_for_crd(&agent_crd_contents);
130116

131117
if !code_needs_regen(&agent_generated_code) {

0 commit comments

Comments
 (0)