diff --git a/jl_sys/build.rs b/jl_sys/build.rs index 98f22df..3bb5012 100644 --- a/jl_sys/build.rs +++ b/jl_sys/build.rs @@ -242,15 +242,29 @@ fn compile_jlrs_cc(julia_dir: &str, target: Option) { #[cfg(feature = "lto")] c.flag("-flto=thin"); + cfg_if! { + if #[cfg(feature = "julia-1-6")] { + c.define("JLRS_EXPECTED_MINOR_VERSION", Some("6")); + } else if #[cfg(feature = "julia-1-7")] { + c.define("JLRS_EXPECTED_MINOR_VERSION", Some("7")); + } else if #[cfg(feature = "julia-1-8")] { + c.define("JLRS_EXPECTED_MINOR_VERSION", Some("8")); + } else if #[cfg(feature = "julia-1-9")] { + c.define("JLRS_EXPECTED_MINOR_VERSION", Some("9")); + } else if #[cfg(feature = "julia-1-10")] { + c.define("JLRS_EXPECTED_MINOR_VERSION", Some("10")); + } else if #[cfg(feature = "julia-1-11")] { + c.define("JLRS_EXPECTED_MINOR_VERSION", Some("11")); + } else if #[cfg(feature = "julia-1-12")] { + c.define("JLRS_EXPECTED_MINOR_VERSION", Some("12")); + } + }; + // Enable fast (i.e. local-exec) TLS. Only enable this feature if you're embedding Julia in a // Rust application. #[cfg(all(feature = "fast-tls", not(feature = "yggdrasil")))] c.define("JLRS_FAST_TLS", None); - // Set JULIA_VERSION_MINOR for Julia 1.6 because julia_version.h doesn't exist - #[cfg(feature = "julia-1-6")] - c.define("JULIA_VERSION_MINOR", Some("6")); - #[cfg(all( any(windows, target_os = "windows", feature = "windows"), feature = "julia-1-6" diff --git a/jl_sys/src/jlrs_cc/jlrs_cc.h b/jl_sys/src/jlrs_cc/jlrs_cc.h index 47d86e4..e716404 100644 --- a/jl_sys/src/jlrs_cc/jlrs_cc.h +++ b/jl_sys/src/jlrs_cc/jlrs_cc.h @@ -10,6 +10,10 @@ #include #endif +#if JLRS_EXPECTED_MINOR_VERSION != JULIA_VERSION_MINOR +#error Mismatch between selected Julia version and detected version +#endif + #include "jlrs_cc_windows.h" #include diff --git a/jl_sys/src/jlrs_cc/jlrs_cc_windows.h b/jl_sys/src/jlrs_cc/jlrs_cc_windows.h index c938040..551dee2 100644 --- a/jl_sys/src/jlrs_cc/jlrs_cc_windows.h +++ b/jl_sys/src/jlrs_cc/jlrs_cc_windows.h @@ -5,7 +5,7 @@ #include #include -#if JULIA_VERSION_MINOR == 6 +#if JLRS_EXPECTED_MINOR_VERSION == 6 template static inline T jl_atomic_load_relaxed(volatile T *obj) { diff --git a/jlrs/Cargo.toml b/jlrs/Cargo.toml index f494088..f92030d 100644 --- a/jlrs/Cargo.toml +++ b/jlrs/Cargo.toml @@ -33,7 +33,7 @@ julia-1-10 = ["jl-sys/julia-1-10", "jlrs-macros/julia-1-10"] # Link Julia 1.11 julia-1-11 = ["jl-sys/julia-1-11", "jlrs-macros/julia-1-11"] # Link Julia 1.12 -julia-1-12 = ["jl-sys/julia-1-11", "jlrs-macros/julia-1-12"] +julia-1-12 = ["jl-sys/julia-1-12", "jlrs-macros/julia-1-12"] # Enable all features except any version features full = ["local-rt", "tokio-rt", "jlrs-ndarray", "f16", "complex", "jlrs-derive", "ccall", "multi-rt"] diff --git a/jlrs/src/data/types/mod.rs b/jlrs/src/data/types/mod.rs index ba0227e..1931411 100644 --- a/jlrs/src/data/types/mod.rs +++ b/jlrs/src/data/types/mod.rs @@ -3,5 +3,5 @@ pub mod abstract_type; pub mod construct_type; pub mod foreign_type; -pub mod typecheck; pub mod primitive_type; +pub mod typecheck; diff --git a/jlrs/src/data/types/primitive_type.rs b/jlrs/src/data/types/primitive_type.rs index a827584..597cea1 100644 --- a/jlrs/src/data/types/primitive_type.rs +++ b/jlrs/src/data/types/primitive_type.rs @@ -1,11 +1,13 @@ //! Primitive type trait +use super::{ + abstract_type::{AbstractChar, AbstractFloat, Integer, Signed, Unsigned}, + construct_type::ConstructType, +}; use crate::prelude::{Bool, Char}; -use super::{abstract_type::{AbstractChar, AbstractFloat, Integer, Signed, Unsigned}, construct_type::ConstructType}; - /// A primitive type. -/// +/// /// Safety: must only be implemented by types that are primitive types in Julia. pub unsafe trait PrimitiveType: ConstructType { /// The size of an instance of this type in bits @@ -15,8 +17,8 @@ pub unsafe trait PrimitiveType: ConstructType { } /// A primitive type. -/// -/// Safety: must only be implemented by types that are primitive types in Julia and subtypes of +/// +/// Safety: must only be implemented by types that are primitive types in Julia and subtypes of /// `Integer`. pub unsafe trait IntegerType: PrimitiveType {} diff --git a/jlrs_macros/src/version.rs b/jlrs_macros/src/version.rs index 250759d..9ea84ba 100644 --- a/jlrs_macros/src/version.rs +++ b/jlrs_macros/src/version.rs @@ -6,7 +6,60 @@ const MAJOR_VERSION: usize = 1; const LTS_MINOR_VERSION: usize = 6; const NIGHTLY_MINOR_VERSION: usize = 12; -#[cfg(feature = "julia-1-6")] +#[cfg(not(any( + feature = "julia-1-6", + feature = "julia-1-7", + feature = "julia-1-8", + feature = "julia-1-9", + feature = "julia-1-10", + feature = "julia-1-11", + feature = "julia-1-12", +)))] +compile_error!( + "A Julia version must be selected by enabling exactly one of the following version features: + julia-1-6 + julia-1-7 + julia-1-8 + julia-1-9 + julia-1-10 + julia-1-11 + julia-1-12" +); + +#[cfg(any( + all(feature = "julia-1-6", feature = "julia-1-7"), + all(feature = "julia-1-6", feature = "julia-1-8"), + all(feature = "julia-1-6", feature = "julia-1-9"), + all(feature = "julia-1-6", feature = "julia-1-10"), + all(feature = "julia-1-6", feature = "julia-1-11"), + all(feature = "julia-1-6", feature = "julia-1-12"), + all(feature = "julia-1-7", feature = "julia-1-8"), + all(feature = "julia-1-7", feature = "julia-1-9"), + all(feature = "julia-1-7", feature = "julia-1-10"), + all(feature = "julia-1-7", feature = "julia-1-11"), + all(feature = "julia-1-7", feature = "julia-1-12"), + all(feature = "julia-1-8", feature = "julia-1-9"), + all(feature = "julia-1-8", feature = "julia-1-10"), + all(feature = "julia-1-8", feature = "julia-1-11"), + all(feature = "julia-1-8", feature = "julia-1-12"), + all(feature = "julia-1-9", feature = "julia-1-10"), + all(feature = "julia-1-9", feature = "julia-1-11"), + all(feature = "julia-1-9", feature = "julia-1-12"), + all(feature = "julia-1-10", feature = "julia-1-11"), + all(feature = "julia-1-10", feature = "julia-1-12"), + all(feature = "julia-1-11", feature = "julia-1-12"), +))] +compile_error!("Multiple Julia version features have been enabled"); + +// Avoid a second error if no version feature is enabled +#[cfg(not(any( + feature = "julia-1-7", + feature = "julia-1-8", + feature = "julia-1-9", + feature = "julia-1-10", + feature = "julia-1-11", + feature = "julia-1-12", +)))] const SELECTED_MINOR_VERSION: usize = 6; #[cfg(feature = "julia-1-7")] const SELECTED_MINOR_VERSION: usize = 7;