diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index 62107f74..d8524f37 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -16,21 +16,8 @@ jobs: toolchain: stable override: true components: clippy - - name: Cache cargo registry - uses: actions/cache@v2 - with: - path: ~/.cargo/registry - key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} - - name: Cache cargo index - uses: actions/cache@v2 - with: - path: ~/.cargo/git - key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} - - name: Cache cargo build - uses: actions/cache@v2 - with: - path: target - key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} + - name: Cache Rust Dependencies + uses: Swatinem/rust-cache@v2 - uses: actions-rs/cargo@v1 with: command: clippy diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0547afba..b9884307 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,21 +15,8 @@ jobs: profile: minimal toolchain: stable override: true - - name: Cache cargo registry - uses: actions/cache@v2 - with: - path: ~/.cargo/registry - key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} - - name: Cache cargo index - uses: actions/cache@v2 - with: - path: ~/.cargo/git - key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} - - name: Cache cargo build - uses: actions/cache@v2 - with: - path: target - key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} + - name: Cache Rust Dependencies + uses: Swatinem/rust-cache@v2 - uses: actions-rs/cargo@v1 with: command: test diff --git a/.gitmodules b/.gitmodules index 598ce43c..ae189012 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "crates/opencascade-sys/OCCT"] - path = crates/opencascade-sys/OCCT + path = crates/occt-sys/OCCT url = https://github.com/Open-Cascade-SAS/OCCT.git diff --git a/crates/occt-sys/Cargo.toml b/crates/occt-sys/Cargo.toml new file mode 100644 index 00000000..9d1f7e1b --- /dev/null +++ b/crates/occt-sys/Cargo.toml @@ -0,0 +1,52 @@ +[package] +name = "occt-sys" +description = "Static build of the C++ OpenCascade CAD Kernel for use as a Rust dependency" +authors = ["Brian Schwind ", "Matěj Laitl "] +license = "LGPL-2.1" +version = "0.1.0" +edition = "2021" +repository = "https://github.com/bschwind/opencascade-rs" + +# Desperately trying to reduce the crate size here... +exclude = [ + "OCCT/adm/*", + "OCCT/data/*", + "OCCT/dox/*", + "OCCT/samples/*", + "OCCT/src/AdvApp2Var/*", + "OCCT/src/AIS/*", + "OCCT/src/AppCont/*", + "OCCT/src/BRepTest/*", + "OCCT/src/Draw/*", + "OCCT/src/Graphic3d/*", + "OCCT/src/HLRBRep/*", + "OCCT/src/IFSelect/*", + "OCCT/src/IGESAppli/*", + "OCCT/src/IGESData/*", + "OCCT/src/IGESDimen/*", + "OCCT/src/IGESDraw/*", + "OCCT/src/IGESGeom/*", + "OCCT/src/IGESSolid/*", + "OCCT/src/MeshVS/*", + "OCCT/src/OpenGl/*", + "OCCT/src/PrsDim/*", + "OCCT/src/QABugs/*", + "OCCT/src/Resource/*", + "OCCT/src/SelectMgr/*", + "OCCT/src/Shaders/*", + "OCCT/src/StepVisual/*", + "OCCT/src/TDataStd/*", + "OCCT/src/Textures/*", + "OCCT/src/ViewerTest/*", + "OCCT/src/Vrml/*", + "OCCT/src/VrmlData/*", + "OCCT/src/XCAFDoc/*", + "OCCT/src/XDEDRAW/*", + "OCCT/tests/*", + "OCCT/tools/*", +] + +[dependencies] + +[build-dependencies] +cmake = "0.1" diff --git a/crates/opencascade-sys/OCCT b/crates/occt-sys/OCCT similarity index 100% rename from crates/opencascade-sys/OCCT rename to crates/occt-sys/OCCT diff --git a/crates/occt-sys/build.rs b/crates/occt-sys/build.rs new file mode 100644 index 00000000..8fd159fa --- /dev/null +++ b/crates/occt-sys/build.rs @@ -0,0 +1,30 @@ +const LIB_DIR: &str = "lib"; +const INCLUDE_DIR: &str = "include"; + +fn main() { + let dst = cmake::Config::new("OCCT") + .define("BUILD_LIBRARY_TYPE", "Static") + .define("BUILD_MODULE_Draw", "FALSE") + .define("USE_OPENGL", "FALSE") + .define("USE_GLES2", "FALSE") + .define("USE_D3D", "FALSE") + .define("USE_VTK", "FALSE") + .define("USE_TCL", "FALSE") + .define("USE_XLIB", "FALSE") + .define("USE_FREETYPE", "FALSE") + .define("USE_FREEIMAGE", "FALSE") + .define("USE_OPENVR", "FALSE") + .define("USE_FFMPEG", "FALSE") + .define("INSTALL_DIR_LIB", LIB_DIR) + .define("INSTALL_DIR_INCLUDE", INCLUDE_DIR) + .build(); + + println!( + "cargo:rustc-env=OCCT_LIB_PATH={}", + dst.join(LIB_DIR).to_str().expect("path is valid Unicode") + ); + println!( + "cargo:rustc-env=OCCT_INCLUDE_PATH={}", + dst.join(INCLUDE_DIR).to_str().expect("path is valid Unicode") + ); +} diff --git a/crates/occt-sys/examples/print_paths.rs b/crates/occt-sys/examples/print_paths.rs new file mode 100644 index 00000000..516e63ab --- /dev/null +++ b/crates/occt-sys/examples/print_paths.rs @@ -0,0 +1,6 @@ +use occt_sys::{occt_include_path, occt_lib_path}; + +fn main() { + println!("occt_lib_path: {}", occt_lib_path().to_str().unwrap()); + println!("occt_include_path: {}", occt_include_path().to_str().unwrap()); +} diff --git a/crates/occt-sys/src/lib.rs b/crates/occt-sys/src/lib.rs new file mode 100644 index 00000000..96c05178 --- /dev/null +++ b/crates/occt-sys/src/lib.rs @@ -0,0 +1,16 @@ +use std::path::Path; + +/// Get path to OCCT library directory with built static libraries. To be used in build scripts +/// with the `cargo:rustc-link-search` command. +/// +/// Only valid during build (`cargo clean` removes these files). +pub fn occt_lib_path() -> &'static Path { + Path::new(env!("OCCT_LIB_PATH")) +} + +/// Get path to OCCT header files. +/// +/// Only valid during build (`cargo clean` removes these files). +pub fn occt_include_path() -> &'static Path { + Path::new(env!("OCCT_INCLUDE_PATH")) +} diff --git a/crates/opencascade-sys/Cargo.toml b/crates/opencascade-sys/Cargo.toml index 9434c8fd..c3bdc0b6 100644 --- a/crates/opencascade-sys/Cargo.toml +++ b/crates/opencascade-sys/Cargo.toml @@ -7,48 +7,10 @@ version = "0.1.0" edition = "2021" repository = "https://github.com/bschwind/opencascade-rs" -# Desperately trying to reduce the crate size here... -exclude = [ - "OCCT/adm/*", - "OCCT/data/*", - "OCCT/dox/*", - "OCCT/samples/*", - "OCCT/src/AdvApp2Var/*", - "OCCT/src/AIS/*", - "OCCT/src/AppCont/*", - "OCCT/src/BRepTest/*", - "OCCT/src/Draw/*", - "OCCT/src/Graphic3d/*", - "OCCT/src/HLRBRep/*", - "OCCT/src/IFSelect/*", - "OCCT/src/IGESAppli/*", - "OCCT/src/IGESData/*", - "OCCT/src/IGESDimen/*", - "OCCT/src/IGESDraw/*", - "OCCT/src/IGESGeom/*", - "OCCT/src/IGESSolid/*", - "OCCT/src/MeshVS/*", - "OCCT/src/OpenGl/*", - "OCCT/src/PrsDim/*", - "OCCT/src/QABugs/*", - "OCCT/src/Resource/*", - "OCCT/src/SelectMgr/*", - "OCCT/src/Shaders/*", - "OCCT/src/StepVisual/*", - "OCCT/src/TDataStd/*", - "OCCT/src/Textures/*", - "OCCT/src/ViewerTest/*", - "OCCT/src/Vrml/*", - "OCCT/src/VrmlData/*", - "OCCT/src/XCAFDoc/*", - "OCCT/src/XDEDRAW/*", - "OCCT/tests/*", - "OCCT/tools/*", -] - [dependencies] cxx = "1" [build-dependencies] cmake = "0.1" cxx-build = "1" +occt-sys = { path = "../occt-sys" } diff --git a/crates/opencascade-sys/build.rs b/crates/opencascade-sys/build.rs index df7e50f6..b3b6c82b 100644 --- a/crates/opencascade-sys/build.rs +++ b/crates/opencascade-sys/build.rs @@ -1,26 +1,11 @@ +use occt_sys::{occt_include_path, occt_lib_path}; + fn main() { let target = std::env::var("TARGET").expect("No TARGET environment variable defined"); let is_windows = target.to_lowercase().contains("windows"); let is_windows_gnu = target.to_lowercase().contains("windows-gnu"); - let dst = cmake::Config::new("OCCT") - .define("BUILD_LIBRARY_TYPE", "Static") - .define("BUILD_MODULE_Draw", "FALSE") - .define("USE_OPENGL", "FALSE") - .define("USE_GLES2", "FALSE") - .define("USE_D3D", "FALSE") - .define("USE_VTK", "FALSE") - .define("USE_TCL", "FALSE") - .define("USE_XLIB", "FALSE") - .define("USE_FREETYPE", "FALSE") - .define("USE_FREEIMAGE", "FALSE") - .define("USE_OPENVR", "FALSE") - .define("USE_FFMPEG", "FALSE") - .define("INSTALL_DIR_LIB", "lib") - .define("INSTALL_DIR_INCLUDE", "include") - .build(); - - println!("cargo:rustc-link-search=native={}", dst.join("lib").display()); + println!("cargo:rustc-link-search=native={}", occt_lib_path().to_str().unwrap()); println!("cargo:rustc-link-lib=static=TKMath"); println!("cargo:rustc-link-lib=static=TKernel"); println!("cargo:rustc-link-lib=static=TKFeat"); @@ -60,7 +45,7 @@ fn main() { .cpp(true) .flag_if_supported("-std=c++11") .define("_USE_MATH_DEFINES", "TRUE") - .include(format!("{}", dst.join("include").display())) + .include(occt_include_path()) .include("include") .compile("wrapper"); diff --git a/docs/writing_bindings.md b/docs/writing_bindings.md index b2a4ab13..ae064009 100644 --- a/docs/writing_bindings.md +++ b/docs/writing_bindings.md @@ -10,9 +10,9 @@ For that we use [CXX](https://cxx.rs/), by dtolnay. CXX itself is also somewhat ### `build.rs` -At the very bottom, we have the [opencascade-sys crate](../crates/opencascade-sys), which includes the OpenCascade source code in the [OCCT directory](../crates/opencascade-sys/OCCT). +At the very bottom, we have the [occt-sys crate](../crates/occt-sys/), which builds OpenCascade C++ project statically without any modifications. -This sys crate has a [build.rs](../crates/opencascade-sys/build.rs) file which calls out to `cmake` to configure and build the project. I've tried to disable as many features as possible which are unrelated to model building (such as FFMPEG, OpenGL, Tcl, basically anything related to visualization or infrastructure as we'll be building that ourselves in Rust). +Right above this is [opencascade-sys crate](../crates/opencascade-sys), which has a [build.rs](../crates/opencascade-sys/build.rs) file with necessary `cxx` infrastructure to compile its wrapper and C++ bindings to OpenCascade. In the theme of keeping it minimal, the OpenCascade libraries we statically link to are all explicitly laid out with `cargo:rustc-link-lib=static=LIB_NAME_HERE` cargo directives.