Skip to content

Commit

Permalink
Moved bp3d-tracing to its own workspace member to prepare for new mul…
Browse files Browse the repository at this point in the history
…ti-crate design
  • Loading branch information
Yuri6037 committed Jul 9, 2024
1 parent 3af5b94 commit 95a4c26
Show file tree
Hide file tree
Showing 18 changed files with 112 additions and 61 deletions.
21 changes: 2 additions & 19 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,2 @@
[package]
name = "bp3d-tracing"
version = "1.0.0-rc.2.1.0"
authors = ["Yuri Edward <[email protected]>"]
edition = "2021"
description = "Tracing subscriber implementations for use with BP3D software. Supports traditional logging through bp3d-logger and supports remote profiling through TCP."
license = "BSD-3-Clause"
repository = "https://gitlab.com/bp3d/tracing/tracing"
readme = "./README.MD"
keywords = ["bp3d", "tracing"]
categories = ["development-tools", "development-tools::debugging", "development-tools::profiling"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bp3d-logger = "2.0.0-rc.2.0.0"

[build-dependencies]
semver = "1.0.7"
[workspace]
members = ["tracing"]
42 changes: 0 additions & 42 deletions build.rs

This file was deleted.

70 changes: 70 additions & 0 deletions tracer/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (c) 2024, BlockProject 3D
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of BlockProject 3D nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use semver::Version;
use std::fs::File;
use std::io::BufWriter;
use std::io::Write;
use std::path::PathBuf;

const WRITE_FAIL: &str = "Failed to write verision_inject file";

fn main() {
let path = std::env::var_os("OUT_DIR")
.map(PathBuf::from)
.expect("Couldn't obtain cargo OUT_DIR")
.join("version_inject.rs");
let file = File::create(path).expect("Couldn't create version_inject file");
let mut writer = BufWriter::new(file);
let version = std::env::var("CARGO_PKG_VERSION").expect("Unable to read package version");
let version = Version::parse(&version).expect("Failed to parse package version");
if !version.pre.is_empty() {
write!(&mut writer, "const VERSION_DATA: [u8; 24] = [").expect(WRITE_FAIL);
let len = std::cmp::min(24, version.pre.as_bytes().len());
for v in 0..len {
write!(&mut writer, "0x{:X}, ", version.pre.as_bytes()[v]).expect(WRITE_FAIL);
}
for _ in 0..24 - len {
write!(&mut writer, "0x0, ").expect(WRITE_FAIL);
}
writeln!(&mut writer, "];").expect(WRITE_FAIL);
writeln!(
&mut writer,
"pub const HELLO_PACKET: Hello = Hello::new({}, Some(VERSION_DATA));",
version.major
)
.expect(WRITE_FAIL);
} else {
writeln!(
&mut writer,
"pub const HELLO_PACKET: Hello = Hello::new({}, None);",
version.major
)
.expect(WRITE_FAIL);
}
}
File renamed without changes.
19 changes: 19 additions & 0 deletions tracing/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "bp3d-tracing"
version = "1.0.0-rc.2.1.0"
authors = ["Yuri Edward <[email protected]>"]
edition = "2021"
description = "Tracing subscriber implementations for use with BP3D software. Supports traditional logging through bp3d-logger and supports remote profiling through TCP."
license = "BSD-3-Clause"
repository = "https://gitlab.com/bp3d/tracing/tracing"
readme = "./README.MD"
keywords = ["bp3d", "tracing"]
categories = ["development-tools", "development-tools::debugging", "development-tools::profiling"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bp3d-logger = "2.0.0-rc.2.0.0"

[build-dependencies]
semver = "1.0.7"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ pub trait Profiler {
fn section_register(&self, section: &'static Section) -> NonZeroU32;
fn section_record<F: FieldSet>(&self, id: NonZeroU32, start: u64, end: u64, fields: &F);
}

extern "Rust" {
pub fn profiler_section_register(section: &'static Section) -> NonZeroU32;
}
File renamed without changes.
17 changes: 17 additions & 0 deletions src/profiler/section.rs → tracing/src/profiler/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,25 @@ impl Section {
mod tests {
use crate::{field, fields, location};
use crate::field::D;
use crate::profiler::profiler_section_register;
use crate::profiler::section::{Level, Section};

mod whatever {
use std::num::NonZeroU32;
use crate::profiler::section::Section;

/*#[no_mangle]
pub extern "Rust" fn profiler_section_register(section: &'static Section) -> NonZeroU32 {
unsafe { NonZeroU32::new_unchecked(1) }
}*/
}

#[test]
fn basic() {
static SECTION: Section = Section::new("api_test", location!(), Level::Event);
unsafe { profiler_section_register(&SECTION) };
}

#[test]
fn api_test() {
static SECTION: Section = Section::new("api_test", location!(), Level::Event);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 95a4c26

Please sign in to comment.