Skip to content

Commit

Permalink
fix: allow cross compilation under builtin flag v2 (#185)
Browse files Browse the repository at this point in the history
* fix: allow cross compilation under builtin flag

* undo sys changes

---------

Co-authored-by: Dominick Schroer <[email protected]>
  • Loading branch information
fidoriel and DSchroer authored Nov 30, 2024
1 parent ba2a149 commit c754f4f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 41 deletions.
8 changes: 0 additions & 8 deletions crates/occt-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,4 @@ exclude = [
]

[dependencies]

[build-dependencies]
cmake = "0.1"

# Adding an empty workspace table so occt-sys doesn't believe
# it's in the parent workspace. This crate is excluded from
# the top-level workspace because it takes quite awhile to
# build and the crate doesn't change very often.
[workspace]
39 changes: 9 additions & 30 deletions crates/occt-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,12 @@
const LIB_DIR: &str = "lib";
const INCLUDE_DIR: &str = "include";
use std::{env::var, path::Path};

fn main() {
let current_dir = std::env::current_dir().expect("Should have a 'current' directory");
let patch_dir = current_dir.join("patch");

let dst = cmake::Config::new("OCCT")
.define("BUILD_PATCH", patch_dir)
.define("BUILD_LIBRARY_TYPE", "Static")
.define("BUILD_MODULE_ApplicationFramework", "FALSE")
.define("BUILD_MODULE_Draw", "FALSE")
.define("USE_D3D", "FALSE")
.define("USE_DRACO", "FALSE")
.define("USE_EIGEN", "FALSE")
.define("USE_FFMPEG", "FALSE")
.define("USE_FREEIMAGE", "FALSE")
.define("USE_FREETYPE", "FALSE")
.define("USE_GLES2", "FALSE")
.define("USE_OPENGL", "FALSE")
.define("USE_OPENVR", "FALSE")
.define("USE_RAPIDJSON", "FALSE")
.define("USE_TBB", "FALSE")
.define("USE_TCL", "FALSE")
.define("USE_TK", "FALSE")
.define("USE_VTK", "FALSE")
.define("USE_XLIB", "FALSE")
.define("INSTALL_DIR_LIB", LIB_DIR)
.define("INSTALL_DIR_INCLUDE", INCLUDE_DIR)
.build();

println!("cargo:rustc-env=OCCT_PATH={}", dst.to_str().expect("path is valid Unicode"));
println!(
"cargo:rustc-env=OCCT_SRC_DIR={}",
Path::new(&var("CARGO_MANIFEST_DIR").unwrap()).join("OCCT").to_string_lossy()
);
println!(
"cargo:rustc-env=OCCT_PATCH_DIR={}",
Path::new(&var("CARGO_MANIFEST_DIR").unwrap()).join("patch").to_string_lossy()
);
}
43 changes: 40 additions & 3 deletions crates/occt-sys/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
use std::path::Path;
use std::{
env::var,
path::{Path, PathBuf},
};

const LIB_DIR: &str = "lib";
const INCLUDE_DIR: &str = "include";

/// Get the path to the OCCT library installation directory to be
/// used in build scripts.
///
/// Only valid during build (`cargo clean` removes these files).
pub fn occt_path() -> &'static Path {
Path::new(env!("OCCT_PATH"))
pub fn occt_path() -> PathBuf {
// moves the output into target/TARGET/OCCT
// this way its less likely to be rebuilt without a cargo clean
Path::new(&var("OUT_DIR").expect("missing OUT_DIR")).join("../../../../OCCT")
}

/// Build the OCCT library.
pub fn build_occt() {
cmake::Config::new(Path::new(env!("OCCT_SRC_DIR")))
.define("BUILD_PATCH", Path::new(env!("OCCT_PATCH_DIR")))
.define("BUILD_LIBRARY_TYPE", "Static")
.define("BUILD_MODULE_ApplicationFramework", "FALSE")
.define("BUILD_MODULE_Draw", "FALSE")
.define("USE_D3D", "FALSE")
.define("USE_DRACO", "FALSE")
.define("USE_EIGEN", "FALSE")
.define("USE_FFMPEG", "FALSE")
.define("USE_FREEIMAGE", "FALSE")
.define("USE_FREETYPE", "FALSE")
.define("USE_GLES2", "FALSE")
.define("USE_OPENGL", "FALSE")
.define("USE_OPENVR", "FALSE")
.define("USE_RAPIDJSON", "FALSE")
.define("USE_TBB", "FALSE")
.define("USE_TCL", "FALSE")
.define("USE_TK", "FALSE")
.define("USE_VTK", "FALSE")
.define("USE_XLIB", "FALSE")
.define("INSTALL_DIR_LIB", LIB_DIR)
.define("INSTALL_DIR_INCLUDE", INCLUDE_DIR)
.profile("Release")
.out_dir(occt_path())
.build();
}

0 comments on commit c754f4f

Please sign in to comment.