Skip to content

Commit

Permalink
PyO3 dependency as a feature (#240)
Browse files Browse the repository at this point in the history
* python as optional dep

* if we're not symlinking, just use the full ugly name

* address clippy warning

* remove build.rs since we arent using it

* dupe cfg check in src
  • Loading branch information
mik90 authored Feb 10, 2025
1 parent 3c95378 commit 47254bc
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 38 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,12 @@ jobs:
run: |
Add-Content -Path $env:GITHUB_ENV -Value "RELEASE_FLAG=--release"
- name: Set features (Linux / MacOS)
if: runner.os != 'Windows'
- name: Set features (Linux)
if: runner.os == 'Linux'
run: echo "FEATURES_FLAG=$([[ '${{ matrix.mode }}' == 'cuda-release' ]] && echo '--all-features' || echo '--features macro_debug,mock,image,kornia,python')" >> $GITHUB_ENV

- name: Set features (MacOS)
if: runner.os == 'macOS'
run: echo "FEATURES_FLAG=$([[ '${{ matrix.mode }}' == 'cuda-release' ]] && echo '--all-features' || echo '--features macro_debug,mock,image,kornia')" >> $GITHUB_ENV

- name: Set features (Windows)
Expand All @@ -148,7 +152,7 @@ jobs:
$features = if ($env:matrix_mode -eq 'cuda-release') {
'--all-features'
} else {
'--features macro_debug,mock,image,kornia'
'--features macro_debug,mock,image,kornia,python'
}
Add-Content -Path $env:GITHUB_ENV -Value "FEATURES_FLAG=$features"
Expand Down
9 changes: 7 additions & 2 deletions core/cu29_export/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,22 @@ repository.workspace = true

# This is a python binding
[lib]
name = "cu29_export"
crate-type = ["cdylib", "rlib"]

[dependencies]
cu29 = { workspace = true }
clap = { workspace = true }
bincode = { workspace = true }

[target.'cfg(not(target_os = "macos"))'.dependencies]
pyo3 = { version = "0.23.3", features = ["extension-module"] }
# PyO3 is not supported for macOS at the moment, don't allow people to opt-in since it won't work
pyo3 = { version = "0.23.3", optional = true, features = ["extension-module"] }

[dev-dependencies]
cu29-log-runtime = { workspace = true }
tempfile = { workspace = true }
fs_extra = "1.3.0"

[features]
default = []
python = ["pyo3"]
25 changes: 0 additions & 25 deletions core/cu29_export/build.rs

This file was deleted.

7 changes: 4 additions & 3 deletions core/cu29_export/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ pub fn textlog_dump(mut src: impl Read, index: &Path) -> CuResult<()> {
Ok(())
}

// only for not macos platforms
#[cfg(not(target_os = "macos"))]
// only for users opting into python interface, not supported on macOS at the moment
#[cfg(all(feature = "python", not(target_os = "macos")))]
mod python {
use bincode::config::standard;
use bincode::decode_from_std_read;
Expand Down Expand Up @@ -276,7 +276,8 @@ mod python {
}
}

#[pymodule]
/// This needs to match the name of the generated '.so'
#[pymodule(name = "libcu29_export")]
fn cu29_export(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<PyCuLogEntry>()?;
m.add_class::<PyLogIterator>()?;
Expand Down
12 changes: 9 additions & 3 deletions examples/cu_caterpillar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ homepage.workspace = true
repository.workspace = true

[package.metadata.cargo-machete]
ignored = ["cu29-log", "cu29-log-runtime", "cu29-unifiedlog", "cu-consolemon", "copper-traits"] # proc macro and console
ignored = [
"cu29-log",
"cu29-log-runtime",
"cu29-unifiedlog",
"cu-consolemon",
"copper-traits",
] # proc macro and console

[[bin]]
name = "cu-caterpillar"
Expand All @@ -27,10 +33,10 @@ path = "src/logreader.rs"
[dependencies]
cu29 = { workspace = true }
cu29-helpers = { workspace = true }
cu29-export = { workspace = true }
cu29-export = { workspace = true, features = ["python"] }
bincode = { workspace = true }
# cu-consolemon = { path = "../../components/monitors/cu_consolemon", default-features = false, version = "0.6" } # needed
cu-consolemon = { path = "../../components/monitors/cu_consolemon", version = "0.6" } # needed
cu-consolemon = { path = "../../components/monitors/cu_consolemon", version = "0.6" } # needed
cu-rp-gpio = { path = "../../components/sinks/cu_rp_gpio", version = "0.6.0" }
tempfile = "3.14.0"

Expand Down
4 changes: 2 additions & 2 deletions examples/cu_standalone_structlog/readlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
sys.path.append(str(target_dir))


import cu29_export
import libcu29_export

log_file_path = "logfile.bin"
index_file_path = target_dir / "cu29_log_index"

log_iterator, all_strings = cu29_export.struct_log_iterator_bare(log_file_path, str(index_file_path))
log_iterator, all_strings = libcu29_export.struct_log_iterator_bare(log_file_path, str(index_file_path))


for log_entry in log_iterator:
Expand Down

0 comments on commit 47254bc

Please sign in to comment.