Skip to content

Commit

Permalink
add cxxwrap1
Browse files Browse the repository at this point in the history
  • Loading branch information
terasakisatoshi committed May 6, 2024
1 parent 60b5704 commit 6092c55
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 0 deletions.
1 change: 1 addition & 0 deletions cxxwrap1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libhello*
6 changes: 6 additions & 0 deletions cxxwrap1/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM julia:1.10.3

RUN apt-get update && apt-get install -y --no-install-recommends g++ \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

RUN julia -e 'using Pkg; Pkg.add("CxxWrap"); Pkg.precompile()'
72 changes: 72 additions & 0 deletions cxxwrap1/Manifest.toml
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 = "1b0a6b6d81b3045788b43b329bfad98437353c80"

[[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"
2 changes: 2 additions & 0 deletions cxxwrap1/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[deps]
CxxWrap = "1f15a43c-97ca-5a2a-ae31-89f07a497df4"
10 changes: 10 additions & 0 deletions cxxwrap1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Usage

```
$ docker build -t cxxwrap1 .
$ docker run --rm -it -v $PWD:/work -w /work cxxwrap1 bash -c 'bash build.sh && julia callcxx.jl'
```

# Reference

[my gist](https://gist.github.com/terasakisatoshi/b6a7121cd570f6739992345095b07d62)
9 changes: 9 additions & 0 deletions cxxwrap1/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
JL=`julia -e 'joinpath(Sys.BINDIR, "..") |> abspath |> print'`
PREFIX=`julia -e 'using CxxWrap; CxxWrap.prefix_path() |> print'`

g++ -fPIC -shared -std=c++17 \
-I${PREFIX}/include/ \
-L${PREFIX}/lib/ \
-I${JL}/include/julia \
-L${JL}/lib \
hello.cpp -o libhello.so
12 changes: 12 additions & 0 deletions cxxwrap1/callcxx.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Load the module and generate the functions
module CppHello
using CxxWrap
@wrapmodule(()->joinpath(".","libhello.so"))

function __init__()
@initcxx
end
end

# Call greet and show the result
@show CppHello.greet()
13 changes: 13 additions & 0 deletions cxxwrap1/hello.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <string>

#include "jlcxx/jlcxx.hpp"

std::string greet()
{
return "hello, world";
}

JLCXX_MODULE define_julia_module(jlcxx::Module& mod)
{
mod.method("greet", &greet);
}

0 comments on commit 6092c55

Please sign in to comment.