From 713cd4e858d9474318104b2a1e4dee0a25e8c67a Mon Sep 17 00:00:00 2001 From: Dave Tucker Date: Mon, 13 Jun 2022 13:56:50 +0100 Subject: [PATCH 1/3] docs: Add crabby logo Signed-off-by: Dave Tucker --- aya/src/lib.rs | 7 +++++++ bpf/aya-bpf/src/lib.rs | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/aya/src/lib.rs b/aya/src/lib.rs index 87de3a4e0..9d31efead 100644 --- a/aya/src/lib.rs +++ b/aya/src/lib.rs @@ -1,3 +1,5 @@ +//! [![](https://aya-rs.dev/assets/images/aya_logo_docs.svg)](https://aya-rs.dev) +//! //! A library to work with eBPF programs. //! //! eBPF is a technology that allows running user-supplied programs inside the @@ -29,6 +31,11 @@ //! //! [tokio]: https://docs.rs/tokio //! [async-std]: https://docs.rs/async-std + +#![doc( + html_logo_url = "https://aya-rs.dev/assets/images/crabby.svg", + html_favicon_url = "https://aya-rs.dev/assets/images/crabby.svg" +)] #![deny(clippy::all, missing_docs)] #![allow(clippy::missing_safety_doc, clippy::len_without_is_empty)] diff --git a/bpf/aya-bpf/src/lib.rs b/bpf/aya-bpf/src/lib.rs index e62f10bd4..dd375a4f9 100644 --- a/bpf/aya-bpf/src/lib.rs +++ b/bpf/aya-bpf/src/lib.rs @@ -1,3 +1,14 @@ +//! [![](https://aya-rs.dev/assets/images/aya_logo_docs.svg)](https://aya-rs.dev) +//! +//! A library to write eBPF programs. +//! +//! Aya-bpf is an eBPF library built with a focus on operability and developer experience. +//! It is the kernel-space counterpart of [Aya](https://docs.rs/aya) + +#![doc( + html_logo_url = "https://aya-rs.dev/assets/images/crabby.svg", + html_favicon_url = "https://aya-rs.dev/assets/images/crabby.svg" +)] #![feature(never_type)] #![allow(clippy::missing_safety_doc)] #![no_std] From 67951cd2d72a166d3179f90ab0d566f14f681c8f Mon Sep 17 00:00:00 2001 From: Dave Tucker Date: Mon, 13 Jun 2022 18:00:29 +0100 Subject: [PATCH 2/3] xtask: Fix docs generation Publish user/kernel space docs seperately. Add an index.html at the root for navigation. Ensure that search engines don't index these pages. Signed-off-by: Dave Tucker --- .gitignore | 2 ++ netlify.toml | 6 +--- xtask/Cargo.toml | 3 +- xtask/src/docs/mod.rs | 82 +++++++++++++++++++++++++++++++++++++++---- 4 files changed, 80 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index fbf6b41c8..d194918fe 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ target/ libbpf/ .vscode/ !.vscode/settings.json +site/ +header.html diff --git a/netlify.toml b/netlify.toml index 12363de1a..0b8e19913 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,7 +1,3 @@ [build] - publish = "target/doc" + publish = "site" command = "rustup toolchain install nightly && cargo xtask docs" - -[[redirects]] - from = "/" - to = "/aya" diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index a40372c5a..6a709059e 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -11,4 +11,5 @@ anyhow = "1" syn = "1" quote = "1" proc-macro2 = "1" -indexmap = "1.6" \ No newline at end of file +indexmap = "1.6" +indoc = "1.0" diff --git a/xtask/src/docs/mod.rs b/xtask/src/docs/mod.rs index 7cc0922db..c58e4953c 100644 --- a/xtask/src/docs/mod.rs +++ b/xtask/src/docs/mod.rs @@ -5,9 +5,31 @@ use std::{ use std::{fs, io, io::Write}; +use indoc::indoc; + pub fn docs() -> Result<(), anyhow::Error> { let mut working_dir = PathBuf::from("."); + let replace = Command::new("sed") + .current_dir(&working_dir) + .args(vec![ + "-i.bak", + "s/crabby.svg/crabby_dev.svg/", + "aya/src/lib.rs", + ]) + .status() + .expect("failed to replace logo"); + assert!(replace.success()); + + let mut header_path = PathBuf::from("."); + header_path.push("header.html"); + let mut header = fs::File::create(&header_path).expect("can't create header.html"); + header + .write(r#""#.as_bytes()) + .expect("can't write header.html contents"); + header.flush().expect("couldn't flush contents"); + + let abs_header_path = fs::canonicalize(&header_path).unwrap(); let args = vec![ "+nightly", "doc", @@ -18,27 +40,73 @@ pub fn docs() -> Result<(), anyhow::Error> { let status = Command::new("cargo") .current_dir(&working_dir) + .env( + "RUSTDOCFLAGS", + format!("--html-in-header {}", abs_header_path.to_str().unwrap()), + ) .args(&args) .status() .expect("failed to build aya docs"); assert!(status.success()); working_dir.push("bpf"); + + let replace = Command::new("sed") + .current_dir(&working_dir) + .args(vec![ + "-i.bak", + "s/crabby.svg/crabby_dev.svg/", + "aya-bpf/src/lib.rs", + ]) + .status() + .expect("failed to replace logo"); + assert!(replace.success()); + let status = Command::new("cargo") .current_dir(&working_dir) + .env( + "RUSTDOCFLAGS", + format!("--html-in-header {}", abs_header_path.to_str().unwrap()), + ) .args(&args) .status() .expect("failed to build aya-bpf docs"); assert!(status.success()); - copy_dir_all("./bpf/target/doc", "./target/doc")?; + copy_dir_all("./target/doc", "site/user")?; + copy_dir_all("./bpf/target/doc", "site/bpf")?; + + let mut robots = fs::File::create("site/robots.txt").expect("can't create robots.txt"); + robots + .write( + indoc! {r#" + User-Agent:* + Disallow: / + "#} + .as_bytes(), + ) + .expect("can't write robots.txt"); + + let mut index = fs::File::create("site/index.html").expect("can't create index.html"); + index + .write( + indoc! {r#" + + + + + + + "#} + .as_bytes(), + ) + .expect("can't write index.html"); - let crates_js = b"window.ALL_CRATES = [\"aya\", \"aya_bpf\", \"aya_bpf_bindings\", \"aya_bpf_cty\", \"aya_bpf_macros\", \"aya_gen\"];\n"; - let mut file = fs::File::options() - .read(true) - .write(true) - .open("./target/doc/crates.js")?; - file.write_all(crates_js)?; + fs::rename("aya/src/lib.rs.bak", "aya/src/lib.rs").unwrap(); + fs::rename("bpf/aya-bpf/src/lib.rs.bak", "bpf/aya-bpf/src/lib.rs").unwrap(); Ok(()) } From 2b98259be73865cf6b213de1b73d0b7b0086a22f Mon Sep 17 00:00:00 2001 From: Dave Tucker Date: Mon, 13 Jun 2022 18:06:15 +0100 Subject: [PATCH 3/3] readme: Add crabby, sync with aya/README.md Signed-off-by: Dave Tucker --- README.md | 6 +- assets/logo.svg | 279 ++++++++++++++++++++++++++++++++++++++++++++++++ aya/README.md | 43 +++++--- 3 files changed, 310 insertions(+), 18 deletions(-) create mode 100644 assets/logo.svg diff --git a/README.md b/README.md index cc069b1fe..c4f1fca8a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Aya +# [![Aya](assets/logo.svg)](https://aya-rs.dev) [![Crates.io][crates-badge]][crates-url] ![License][license-badge] @@ -11,14 +11,14 @@ [license-badge]: https://img.shields.io/badge/license-MIT%2FApache--2.0-blue?style=for-the-badge [build-badge]: https://img.shields.io/github/workflow/status/aya-rs/aya/build-aya?style=for-the-badge&logo=github [book-badge]: https://img.shields.io/badge/read%20the-book-9cf.svg?style=for-the-badge&logo=mdbook -[book-url]: http://aya-rs.github.io/book/ +[book-url]: https://aya-rs.dev/book ## API Documentation [![Unreleased Documentation][git-docs-badge]][git-api-docs] [![Documentaiton][api-docs-badge]][api-docs] [git-docs-badge]: https://img.shields.io/badge/docs-unreleased-red.svg?style=for-the-badge&logo=docsdotrs -[git-api-docs]: https://aya-rs.netlify.app +[git-api-docs]: https://docs.aya-rs.dev [api-docs-badge]: https://img.shields.io/badge/docs-released-blue.svg?style=for-the-badge&logo=docsdotrs [api-docs]: https://docs.rs/aya diff --git a/assets/logo.svg b/assets/logo.svg new file mode 100644 index 000000000..979851769 --- /dev/null +++ b/assets/logo.svg @@ -0,0 +1,279 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/aya/README.md b/aya/README.md index e7798ca5f..d396b3f9e 100644 --- a/aya/README.md +++ b/aya/README.md @@ -1,21 +1,38 @@ -# Aya +# [![Aya](../assets/logo.svg)](https://aya-rs.dev) [![Crates.io][crates-badge]][crates-url] ![License][license-badge] ![Build status][build-badge] -[![Documentaiton][docs-badge]][docs-url] +[![Book][book-badge]][book-url] -[crates-badge]: https://img.shields.io/crates/v/aya.svg + +[crates-badge]: https://img.shields.io/crates/v/aya.svg?style=for-the-badge&logo=rust [crates-url]: https://crates.io/crates/aya -[license-badge]: https://img.shields.io/badge/license-MIT%2FApache--2.0-blue -[build-badge]: https://github.com/aya-rs/aya/actions/workflows/build-test.yml/badge.svg -[docs-badge]: https://img.shields.io/badge/docs-website-blue.svg -[docs-url]: http://aya-rs.github.io/book/ +[license-badge]: https://img.shields.io/badge/license-MIT%2FApache--2.0-blue?style=for-the-badge +[build-badge]: https://img.shields.io/github/workflow/status/aya-rs/aya/build-aya?style=for-the-badge&logo=github +[book-badge]: https://img.shields.io/badge/read%20the-book-9cf.svg?style=for-the-badge&logo=mdbook +[book-url]: https://aya-rs.dev/book + +## API Documentation -[API docs][api-docs] | [Chat][chat-url] +[![Unreleased Documentation][git-docs-badge]][git-api-docs] [![Documentaiton][api-docs-badge]][api-docs] +[git-docs-badge]: https://img.shields.io/badge/docs-unreleased-red.svg?style=for-the-badge&logo=docsdotrs +[git-api-docs]: https://docs.aya-rs.dev +[api-docs-badge]: https://img.shields.io/badge/docs-released-blue.svg?style=for-the-badge&logo=docsdotrs [api-docs]: https://docs.rs/aya + +## Community + +[![Discord][discord-badge]][chat-url] [![Awesome][awesome-badge]][awesome-aya] + +Join [the conversation on Discord][chat-url] to discuss anything related to Aya, or discover +and contribute to a list of [Awesome Aya][awesome-aya] projects. + +[discord-badge]: https://img.shields.io/badge/Discord-chat-5865F2?style=for-the-badge&logo=discord [chat-url]: https://discord.gg/xHW2cb2N6G +[awesome-aya]: https://github.com/aya-rs/awesome-aya +[awesome-badge]: https://img.shields.io/badge/Awesome-Aya-FC60A8?style=for-the-badge&logo=awesomelists ## Overview @@ -46,7 +63,7 @@ Some of the major features provided include: [libbpf]: https://github.com/libbpf/libbpf [bcc]: https://github.com/iovisor/bcc [libc]: https://docs.rs/libc -[co-re]: https://facebookmicrosites.github.io/bpf/blog/2020/02/19/bpf-portability-and-co-re.html +[co-re]: https://facebookmicrosites.github.io/bpf/blog/2020/02/19/bpf-portability-and-co-re.html [tokio]: https://docs.rs/tokio [async-std]: https://docs.rs/async-std @@ -65,7 +82,7 @@ use aya::programs::{CgroupSkb, CgroupSkbAttachType}; // load the BPF code let mut bpf = Bpf::load_file("bpf.o")?; -// get the `ingress_filter` program compiled into `bpf.o`. +// get the `ingress_filter` program compiled into `bpf.o`. let ingress: &mut CgroupSkb = bpf.program_mut("ingress_filter")?.try_into()?; // load the program into the kernel @@ -77,10 +94,6 @@ let cgroup = File::open("/sys/fs/cgroup/unified")?; ingress.attach(cgroup, CgroupSkbAttachType::Ingress)?; ``` -## Community - -Join [the conversation on Discord][chat-url] to discuss anything related to aya. - ## Contributing Please see the [contributing guide](https://github.com/aya-rs/aya/blob/main/CONTRIBUTING.md). @@ -89,7 +102,7 @@ Please see the [contributing guide](https://github.com/aya-rs/aya/blob/main/CONT Aya is distributed under the terms of either the [MIT license] or the [Apache License] (version 2.0), at your option. -Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. +Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. [MIT license]: https://github.com/aya-rs/aya/blob/main/LICENSE-MIT [Apache license]: https://github.com/aya-rs/aya/blob/main/LICENSE-APACHE