Skip to content

Commit 5058347

Browse files
committed
fix: rename Cargo.toml -> Cargo.toml.hidden to fix cargo behavior
1 parent 21e4dc2 commit 5058347

File tree

7 files changed

+117
-63
lines changed

7 files changed

+117
-63
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ vendor
1919
# nix build
2020
/result*
2121
.home
22+
/ockam_ebpf_impl/Cargo.toml

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ eBPF program used by Ockam Privileged Portals
1818
[features]
1919
default = []
2020
# Build eBPF instead of downloading from artifacts
21-
build = []
21+
build = ["fs_extra"]
2222
logging = []
2323

2424
[build-dependencies]
2525
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls-native-roots", "blocking"] }
2626
url = { version = "2.5.2" }
27+
fs_extra = { version = "1.3.0", optional = true }
2728

2829
[lib]

README.md

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,63 @@
1-
# ockam-ebpf
1+
# ockam_ebpf
2+
3+
[![crate][crate-image]][crate-link]
4+
[![docs][docs-image]][docs-link]
5+
[![license][license-image]][license-link]
6+
[![discuss][discuss-image]][discuss-link]
7+
8+
Ockam is a library for building devices that communicate securely, privately
9+
and trustfully with cloud services and other devices.
10+
11+
This crate contains the eBPF part of Ockam Reliable TCP Portals.
12+
13+
### Build
14+
15+
This crate exposes eBPF binary through the `EBPF_BINARY` static constant in the root of the crate. That binary can be
16+
used to attach Ockam eBPF to network devices.
17+
18+
### Features
19+
20+
By default, this crate ships a prebuilt eBPF binary downloaded from the corresponding GitHub release artifacts. This
21+
allows to build Ockam without all the dependencies that are required to build eBPF.
22+
23+
* build - build the eBPF locally instead of downloading the prebuilt binary. This might be useful during development and debugging.
24+
* logging - this will enable logs for eBPF. Note that eBPF sends logs to the user space using `AsyncPerfEventArray`, therefore it implies performance penalty.
25+
26+
```bash
27+
cargo build
28+
```
29+
30+
### Requirements to build eBPF
31+
32+
Please refer to [ockam_ebpf_impl/README.md](ockam_ebpf_impl/README.md)
33+
34+
### Requirements to use eBPF
35+
36+
Using ockam with eBPFs requires:
37+
- Linux
38+
- root (CAP_BPF, CAP_NET_RAW, CAP_NET_ADMIN, CAP_SYS_ADMIN)
39+
40+
## Usage
41+
42+
Add this to your `Cargo.toml`:
43+
44+
```
45+
[dependencies]
46+
ockam_ebpf = "0.5.0"
47+
```
48+
49+
## License
50+
51+
This code is licensed under the terms of the [Apache License 2.0][license-link].
52+
53+
[crate-image]: https://img.shields.io/crates/v/ockam_ebpf.svg
54+
[crate-link]: https://crates.io/crates/ockam_ebpf
55+
56+
[docs-image]: https://docs.rs/ockam_ebpf/badge.svg
57+
[docs-link]: https://docs.rs/ockam_ebpf
58+
59+
[license-image]: https://img.shields.io/badge/License-Apache%202.0-green.svg
60+
[license-link]: https://github.com/build-trust/ockam/blob/HEAD/LICENSE
61+
62+
[discuss-image]: https://img.shields.io/badge/Discuss-Github%20Discussions-ff70b4.svg
63+
[discuss-link]: https://github.com/build-trust/ockam/discussions

build.rs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,35 @@ fn build_ebpf() {
77
use std::env;
88
use std::process::Command;
99

10+
use fs_extra::dir::CopyOptions;
11+
1012
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
1113
let output_file = out_dir.join("ockam_ebpf");
14+
let ebpf_subdir = out_dir.join("ebpf");
1215

13-
let target_dir = out_dir.join("ebpf");
16+
let ockam_ebpf_impl_subdir = ebpf_subdir.join("ockam_ebpf_impl");
17+
let ockam_ebpf_impl_target_subdir = ebpf_subdir.join("target");
18+
let cargo_toml_hidden = ockam_ebpf_impl_subdir.join("Cargo.toml.hidden");
19+
let cargo_toml = ockam_ebpf_impl_subdir.join("Cargo.toml");
1420

15-
// Delete the target dir for eBPF crate otherwise it doesn't want to recompile after files are
21+
// Delete the directories for eBPF crate otherwise it doesn't want to recompile after files are
1622
// updated
17-
_ = std::fs::remove_dir_all(&target_dir);
18-
std::fs::create_dir(&target_dir).unwrap();
23+
_ = std::fs::remove_dir_all(&ebpf_subdir);
24+
25+
std::fs::create_dir(&ebpf_subdir).unwrap();
26+
std::fs::create_dir(&ockam_ebpf_impl_subdir).unwrap();
27+
std::fs::create_dir(&ockam_ebpf_impl_target_subdir).unwrap();
28+
29+
// Copy the impl crate contents to build it
30+
fs_extra::copy_items(
31+
&[PathBuf::from("./ockam_ebpf_impl")],
32+
&ebpf_subdir,
33+
&CopyOptions::new(),
34+
)
35+
.unwrap();
36+
37+
// Copy Cargo.toml.hidden to Cargo.toml
38+
std::fs::copy(&cargo_toml_hidden, &cargo_toml).unwrap();
1939

2040
#[allow(unused_mut)]
2141
let mut args = vec!["build", "--release"];
@@ -24,11 +44,11 @@ fn build_ebpf() {
2444
args.extend_from_slice(&["-F", "logging"]);
2545

2646
let output = Command::new("cargo")
27-
.current_dir(PathBuf::from("./ockam_ebpf_impl"))
47+
.current_dir(&ockam_ebpf_impl_subdir)
2848
.env_remove("RUSTUP_TOOLCHAIN")
2949
.env_remove("RUSTC")
3050
.args(&args)
31-
.env("CARGO_TARGET_DIR", &target_dir)
51+
.env("CARGO_TARGET_DIR", &ockam_ebpf_impl_target_subdir)
3252
.output();
3353

3454
let output = match output {
@@ -42,7 +62,8 @@ fn build_ebpf() {
4262
panic!("Couldn't compile eBPF");
4363
}
4464

45-
let build_output_file = target_dir.join("bpfel-unknown-none/release/ockam_ebpf");
65+
let build_output_file =
66+
ockam_ebpf_impl_target_subdir.join("bpfel-unknown-none/release/ockam_ebpf");
4667
std::fs::copy(build_output_file, output_file).expect("Couldn't copy ockam_ebpf file");
4768
}
4869

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[workspace]
12
[package]
23
name = "ockam_ebpf_impl"
34
version = "0.1.0"
@@ -7,9 +8,9 @@ edition = "2021"
78
homepage = "https://github.com/build-trust/ockam"
89
keywords = ["ockam", "crypto", "p2p", "cryptography", "encryption"]
910
license = "Apache-2.0"
10-
publish = true
11+
publish = false
1112
readme = "README.md"
12-
repository = "https://github.com/build-trust/ockam/implementations/rust/ockam/ockam_ebpf"
13+
repository = "https://github.com/build-trust/ockam-ebpf/ockam_ebpf_impl"
1314
rust-version = "1.70.0"
1415
description = """
1516
eBPF program used by Ockam Privileged Portals

ockam_ebpf_impl/README.md

Lines changed: 13 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,25 @@
1-
# ockam_ebpf
1+
# ockam_ebpf_impl
22

3-
[![crate][crate-image]][crate-link]
4-
[![docs][docs-image]][docs-link]
5-
[![license][license-image]][license-link]
6-
[![discuss][discuss-image]][discuss-link]
7-
8-
Ockam is a library for building devices that communicate securely, privately
9-
and trustfully with cloud services and other devices.
10-
11-
This crate contains the eBPF part of Ockam Reliable TCP Portals.
3+
This crate is shipped as a part of `ockam_ebpf` crate rather than a stand-alone crate. Please refer to the ../README.md
4+
for more information.
125

136
### Build
147

8+
In order to build the crate it's required to copy `Cargo.toml.hidden` file and rename it to `Cargo.toml`. Note, that
9+
`Cargo.toml` file is added to `.gitignore` and shouldn't be commited, instead all changes should be inside
10+
`Cargo.toml.hidden` file. The reason for that is special cargo behaviour that doesn't allow including other crates as
11+
part of a crate. Therefore, if `ockam_ebpf_impl` subdirectory has `Cargo.toml` file, that directory will be completely
12+
ignored during `ockam_ebpf` crate release even if it's added to `include` field of root `Cargo.toml`.
13+
1514
```bash
16-
cargo build-ebpf
15+
cargo build
1716
```
17+
### Requirements
1818

1919
Building eBPFs have roughly following requirements:
2020
- Linux
2121
- Rust nightly
2222
- Some dependencies to be installed
2323

24-
Because of that crate with the eBPF code is kept out of the workspace.
25-
Example of a virtual machine to build it can be found in `ubuntu_x86.yaml`.
26-
27-
Using ockam with eBPFs requires:
28-
- Linux
29-
- root (CAP_BPF, CAP_NET_RAW, CAP_NET_ADMIN, CAP_SYS_ADMIN)
30-
31-
Example of a virtual machine to run ockam with eBPF can be found in `ubuntu_arm.yaml`.
32-
33-
eBPF is a small architecture-independent object file that is small enough,
34-
to include it in the repo.
35-
36-
The built eBPF object should be copied to `/implementations/rust/ockam/ockam_ebpf/ockam_ebpf`,
37-
from where it will be grabbed by `ockam_transport_tcp` crate.
38-
39-
## Usage
40-
41-
Add this to your `Cargo.toml`:
42-
43-
```
44-
[dependencies]
45-
ockam_ebpf = "0.1.0"
46-
```
47-
48-
## License
49-
50-
This code is licensed under the terms of the [Apache License 2.0][license-link].
51-
52-
[main-ockam-crate-link]: https://crates.io/crates/ockam
53-
54-
[crate-image]: https://img.shields.io/crates/v/ockam_ebpf.svg
55-
[crate-link]: https://crates.io/crates/ockam_ebpf
56-
57-
[docs-image]: https://docs.rs/ockam_ebpf/badge.svg
58-
[docs-link]: https://docs.rs/ockam_ebpf
59-
60-
[license-image]: https://img.shields.io/badge/License-Apache%202.0-green.svg
61-
[license-link]: https://github.com/build-trust/ockam/blob/HEAD/LICENSE
62-
63-
[discuss-image]: https://img.shields.io/badge/Discuss-Github%20Discussions-ff70b4.svg
64-
[discuss-link]: https://github.com/build-trust/ockam/discussions
24+
Because of that, crate with the eBPF code is kept out of the workspace.
25+
Example of a virtual machine to build and run eBPF can be found in [ubuntu_arm.yaml](../vm/ubuntu_arm.yaml)

0 commit comments

Comments
 (0)