Skip to content

Commit

Permalink
Successfully compile on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Taaitaaiger committed Oct 30, 2021
1 parent 0dccc24 commit 85591f7
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
22 changes: 16 additions & 6 deletions examples/ccall/callrust.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
x = ccall((:add, "libccall"), Int32, (Int32, Int32), 1, 2)
println(1, " + ", 2, " = ", x)
if Sys.iswindows()
x = ccall((:add, "ccall"), Int32, (Int32, Int32), 1, 2)
println(1, " + ", 2, " = ", x)

y = [1.0 2.0 3.0; 4.0 5.0 6.0; 7.0 8.0 9.0]
println("Before increment: ", y)
ccall((:incr_array, "libccall"), Cvoid, (Array{Float64},), y)
println("After increment: ", y)
y = [1.0 2.0 3.0; 4.0 5.0 6.0; 7.0 8.0 9.0]
println("Before increment: ", y)
ccall((:incr_array, "ccall"), Cvoid, (Array{Float64},), y)
println("After increment: ", y)
else
x = ccall((:add, "libccall"), Int32, (Int32, Int32), 1, 2)
println(1, " + ", 2, " = ", x)

y = [1.0 2.0 3.0; 4.0 5.0 6.0; 7.0 8.0 9.0]
println("Before increment: ", y)
ccall((:incr_array, "libccall"), Cvoid, (Array{Float64},), y)
println("After increment: ", y)
end
12 changes: 9 additions & 3 deletions examples/ccall_with_threads/callrust.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
task = @async begin
condition = Base.AsyncCondition()
output::Ref{UInt32} = C_NULL
joinhandle = ccall((:multithreaded, "libccall_with_threads"), Ptr{Cvoid}, (Ref{UInt32}, Ptr{Cvoid}), output, condition.handle)
wait(condition)
ccall((:drop_handle, "libccall_with_threads"), Cvoid, (Ptr{Cvoid},), joinhandle)
if Sys.iswindows()
joinhandle = ccall((:multithreaded, "ccall_with_threads"), Ptr{Cvoid}, (Ref{UInt32}, Ptr{Cvoid}), output, condition.handle)
wait(condition)
ccall((:drop_handle, "ccall_with_threads"), Cvoid, (Ptr{Cvoid},), joinhandle)
else
joinhandle = ccall((:multithreaded, "libccall_with_threads"), Ptr{Cvoid}, (Ref{UInt32}, Ptr{Cvoid}), output, condition.handle)
wait(condition)
ccall((:drop_handle, "libccall_with_threads"), Cvoid, (Ptr{Cvoid},), joinhandle)
end

output[]
end
Expand Down
37 changes: 21 additions & 16 deletions jl_sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,22 @@ fn flags() -> Vec<String> {
let flags = match find_julia() {
Some(julia_dir) => {
let jl_include_path = format!("-I{}/include/julia/", julia_dir);
let jl_lib_path = format!("-L{}/lib/", julia_dir);

println!("cargo:rustc-flags={}", &jl_lib_path);

#[cfg(target_os = "windows")]
#[cfg(target_os = "linux")]
{
let jl_internal_lib_path = format!("-L{}/lib/julia", julia_dir);
println!("cargo:rustc-flags={}", &jl_internal_lib_path);
let jl_lib_path = format!("-L{}/lib/", julia_dir);
println!("cargo:rustc-flags={}", &jl_lib_path);

if env::var("CARGO_FEATURE_UV").is_ok() {
let jl_internal_lib_path = format!("-L{}/lib/julia", julia_dir);
println!("cargo:rustc-flags={}", &jl_internal_lib_path);
}
}

if env::var("CARGO_FEATURE_UV").is_ok() {
let jl_internal_lib_path = format!("-L{}/lib/julia", julia_dir);
println!("cargo:rustc-flags={}", &jl_internal_lib_path);
#[cfg(target_os = "windows")]
{
let jl_lib_path = format!("-L{}/bin/", julia_dir);
println!("cargo:rustc-flags={}", &jl_lib_path);
}

vec![jl_include_path]
Expand All @@ -40,15 +43,19 @@ fn flags() -> Vec<String> {
if env::var("CARGO_FEATURE_DEBUG").is_ok() {
println!("cargo:rustc-link-lib=julia-debug");
} else {
#[cfg(target_os = "windows")]
println!("cargo:rustc-link-lib=static=julia");

#[cfg(target_os = "linux")]
println!("cargo:rustc-link-lib=julia");
}

if env::var("CARGO_FEATURE_UV").is_ok() {
println!("cargo:rustc-link-lib=uv");
#[cfg(target_os = "windows")]
{
println!("cargo:rustc-link-lib=uv-2");
}

#[cfg(target_os = "linux")]
{
println!("cargo:rustc-link-lib=uv");
}
}

flags
Expand All @@ -70,13 +77,11 @@ fn main() {

let mut c = cc::Build::new();
c.file("src/jlrs_c.c");
c.static_flag(true);

if flags.len() == 1 {
c.include(&flags[0][2..]);
}


c.compile("jlrs_c");

#[cfg(feature = "use-bindgen")]
Expand Down
7 changes: 5 additions & 2 deletions jlrs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ readme = "../README.md"
keywords = ["Julia", "math", "mathematics", "bindings", "ffi"]
categories = ["api-bindings", "mathematics"]
license = "MIT"
edition = "2021"
edition = "2018"

[lib]
doctest = false

[features]
default = []
Expand All @@ -31,8 +34,8 @@ use-bindgen = ["jl-sys/use-bindgen"]

[dependencies]
jl-sys = {version = "0.13", path = "../jl_sys" }
jlrs-derive = { version = "0.3", optional = true, path = "../jlrs_derive" }
smallvec = "1"
jlrs-derive = { version = "0.3", optional = true, path = "../jlrs_derive" }
futures = { version = "0.3", optional = true }
crossbeam-channel = { version = "0.5", optional = true }
async-trait = { version = "0.1", optional = true }
Expand Down

0 comments on commit 85591f7

Please sign in to comment.