Skip to content

Commit

Permalink
Improve checking for incompatible versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Taaitaaiger committed Jul 10, 2024
1 parent d7d7e68 commit d8b86c3
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 11 deletions.
24 changes: 21 additions & 3 deletions jl_sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,32 @@ fn compile_jlrs_cc(julia_dir: &str, target: Option<Target>) {
#[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"));
// // 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"),
Expand Down
4 changes: 4 additions & 0 deletions jl_sys/src/jlrs_cc/jlrs_cc.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#include <julia_version.h>
#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 <julia.h>
Expand Down
2 changes: 1 addition & 1 deletion jlrs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion jlrs/src/data/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
12 changes: 7 additions & 5 deletions jlrs/src/data/types/primitive_type.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {}

Expand Down
55 changes: 54 additions & 1 deletion jlrs_macros/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d8b86c3

Please sign in to comment.