-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fa988dd
commit 361ebae
Showing
11 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FROM julia:1.10.4 | ||
|
||
RUN apt-get update && apt-get install -y --no-install-recommends build-essential cmake \ | ||
&& apt-get clean && rm -rf /var/lib/apt/lists/* | ||
|
||
RUN julia -e 'using Pkg; Pkg.add("CxxWrap"); Pkg.precompile()' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# This file is machine-generated - editing it directly is not advised | ||
|
||
julia_version = "1.10.3" | ||
manifest_format = "2.0" | ||
project_hash = "ccf1a3757eeb779bee7bfa161a032801f22b27b7" | ||
|
||
[[deps.Artifacts]] | ||
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" | ||
|
||
[[deps.Base64]] | ||
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" | ||
|
||
[[deps.CxxWrap]] | ||
deps = ["Libdl", "MacroTools", "libcxxwrap_julia_jll"] | ||
git-tree-sha1 = "ba1a559afd562447710513525030d6ad83e5868a" | ||
uuid = "1f15a43c-97ca-5a2a-ae31-89f07a497df4" | ||
version = "0.15.1" | ||
|
||
[[deps.Dates]] | ||
deps = ["Printf"] | ||
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" | ||
|
||
[[deps.JLLWrappers]] | ||
deps = ["Artifacts", "Preferences"] | ||
git-tree-sha1 = "7e5d6779a1e09a36db2a7b6cff50942a0a7d0fca" | ||
uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210" | ||
version = "1.5.0" | ||
|
||
[[deps.Libdl]] | ||
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" | ||
|
||
[[deps.MacroTools]] | ||
deps = ["Markdown", "Random"] | ||
git-tree-sha1 = "2fa9ee3e63fd3a4f7a9a4f4744a52f4856de82df" | ||
uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" | ||
version = "0.5.13" | ||
|
||
[[deps.Markdown]] | ||
deps = ["Base64"] | ||
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" | ||
|
||
[[deps.Preferences]] | ||
deps = ["TOML"] | ||
git-tree-sha1 = "9306f6085165d270f7e3db02af26a400d580f5c6" | ||
uuid = "21216c6a-2e73-6563-6e65-726566657250" | ||
version = "1.4.3" | ||
|
||
[[deps.Printf]] | ||
deps = ["Unicode"] | ||
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" | ||
|
||
[[deps.Random]] | ||
deps = ["SHA"] | ||
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" | ||
|
||
[[deps.SHA]] | ||
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" | ||
version = "0.7.0" | ||
|
||
[[deps.TOML]] | ||
deps = ["Dates"] | ||
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76" | ||
version = "1.0.3" | ||
|
||
[[deps.Unicode]] | ||
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" | ||
|
||
[[deps.libcxxwrap_julia_jll]] | ||
deps = ["Artifacts", "JLLWrappers", "Libdl"] | ||
git-tree-sha1 = "0f10092db771939e29fd13a67967f5c63212fdfe" | ||
uuid = "3eaa8342-bff7-56a5-9981-c04077f7cee7" | ||
version = "0.12.3+0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name = "MyCxxWrap4" | ||
uuid = "f679af86-966e-4c5a-832e-308363b94463" | ||
authors = ["Satoshi Terasaki <[email protected]>"] | ||
version = "0.1.0" | ||
|
||
[deps] | ||
CxxWrap = "1f15a43c-97ca-5a2a-ae31-89f07a497df4" | ||
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" | ||
|
||
[extras] | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
||
[targets] | ||
test = ["Test"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Usage | ||
|
||
```sh | ||
$ docker build -t cxxwrap4 . | ||
$ docker run --rm -it -v $PWD:/work -w /work cxxwrap4 bash -c 'julia --project -e "using Pkg; Pkg.build(); Pkg.test()"' | ||
``` | ||
|
||
# Reference | ||
|
||
[my gist](https://gist.github.com/terasakisatoshi/b6a7121cd570f6739992345095b07d62) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
project(cxxwrap3) | ||
add_subdirectory(src) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
run(`bash build.sh`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Get Julia installation paths | ||
CXXWRAP_PREFIX=`julia --project -e 'using CxxWrap; CxxWrap.prefix_path() |> print'` | ||
rm -rf ./build | ||
cmake -S . -B ./build -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=$CXXWRAP_PREFIX | ||
cmake --build ./build --config Release -j `nproc` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
find_package(JlCxx) | ||
find_package(Eigen3) | ||
get_target_property(JlCxx_location JlCxx::cxxwrap_julia LOCATION) | ||
get_filename_component(JlCxx_location ${JlCxx_location} DIRECTORY) | ||
|
||
add_library(hello SHARED hello.cpp) | ||
|
||
message(STATUS "Found JlCxx at ${JlCxx_location}") | ||
|
||
target_link_libraries(hello JlCxx::cxxwrap_julia JlCxx::cxxwrap_julia_stl ${Julia_LIBRARY} Eigen3::Eigen) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <string> | ||
#include "jlcxx/jlcxx.hpp" | ||
#include "jlcxx/stl.hpp" | ||
#include "jlcxx/array.hpp" | ||
#include <Eigen/Dense> | ||
auto twice(jlcxx::ArrayRef<double, 1> v){ | ||
static Eigen::VectorXd x; | ||
x.resize(v.size()); | ||
for (int i = 0; i < v.size(); i++){ | ||
x[i] = v[i]; | ||
} | ||
x = 2 * x; | ||
return jlcxx::make_julia_array(x.data(), x.size()); | ||
} | ||
|
||
JLCXX_MODULE define_julia_module(jlcxx::Module &mod) { | ||
mod.method("twice", twice); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Load the module and generate the functions | ||
module MyCxxWrap4 | ||
using Libdl: dlext | ||
|
||
using CxxWrap | ||
@wrapmodule(() -> joinpath(pkgdir(@__MODULE__), "deps", "build", "src", "libhello.$(dlext)")) | ||
|
||
function __init__() | ||
@initcxx | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Test | ||
using MyCxxWrap4 | ||
|
||
@testset "greet" begin | ||
x = rand(10) | ||
v= MyCxxWrap4.twice(x) | ||
@test 2x == v | ||
end |