Skip to content

Commit

Permalink
set up julia_bindings structure
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnychen94 committed Mar 27, 2021
1 parent bc42da9 commit c45be97
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 0 deletions.
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
message(STATUS "Building Python bindings disabled")
endif ()

option(WITH_JULIA_BINDINGS "Build Julia bindings" ON)
if (WITH_JULIA_BINDINGS)
if (BUILD_SHARED_LIBS AND Halide_SHARED_LLVM)
message(STATUS "Building Julia bindings enabled")
add_subdirectory(julia_bindings)
else ()
message(WARNING "Building Julia bindings disabled: must compile with BUILD_SHARED_LIBS and Halide_SHARED_LLVM")
set(WITH_JULIA_BINDINGS OFF CACHE BOOL "Build Julia bindings" FORCE)
endif ()
else ()
message(STATUS "Building Julia bindings disabled")
endif ()

option(WITH_TUTORIALS "Build tutorials" ON)
if (WITH_TUTORIALS)
message(STATUS "Building tutorials enabled")
Expand Down
26 changes: 26 additions & 0 deletions julia_bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
##
# Load Julia dependencies, including external JlCxx
##
cmake_minimum_required(VERSION 3.16)

project(libhalide-julia)

set(JLCXX_VER 0.8.2)
find_package(jlcxx ${JLCXX_VER} QUIET)
if (NOT jlcxx_FOUND)
include(FetchContent)
FetchContent_Declare(jlcxx
GIT_REPOSITORY https://github.com/JuliaInterop/libcxxwrap-julia.git
GIT_TAG v${JLCXX_VER})
FetchContent_MakeAvailable(jlcxx)
endif ()

# ##
# # Add our sources to this sub-tree.
# ##

add_subdirectory(src)

option(WITH_TEST_JULIA "Build Julia tests" ON)
if (WITH_TESTS AND WITH_TEST_JULIA)
endif ()
13 changes: 13 additions & 0 deletions julia_bindings/Halide/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name = "Halide"
uuid = "26cb47bb-16f4-45b8-86ca-ecaeb6ea8cd7"
authors = ["Johnny Chen <johnnychen94@hotmail.com>"]
version = "0.1.0"

[deps]
CxxWrap = "1f15a43c-97ca-5a2a-ae31-89f07a497df4"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
13 changes: 13 additions & 0 deletions julia_bindings/Halide/src/Halide.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Halide

using CxxWrap
# TODO: wrap this with jll package provided by BinaryBuilder to avoid hardcoded path
artifacts_root = joinpath(@__DIR__, "../../../build/julia_bindings/src")
@wrapmodule(joinpath(artifacts_root, "libhalide"), :define_func)


function __init__()
@initcxx
end

end # module
23 changes: 23 additions & 0 deletions julia_bindings/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
set(SOURCES
JlHalide.cpp
JlFunc.cpp
)

# CxxWrap requires this to be built as shared library
add_library(Halide_Julia SHARED ${SOURCES})
add_library(Halide::Julia ALIAS Halide_Julia)
set_target_properties(Halide_Julia
PROPERTIES
LIBRARY_OUTPUT_NAME halide
EXPORT_NAME Julia)

target_include_directories(Halide_Julia PRIVATE ${jlcxx_SOURCE_DIR}/include)
target_link_libraries(Halide_Julia PRIVATE Halide::Halide)
target_link_libraries(Halide_Julia PUBLIC cxxwrap_julia)

install(TARGETS
Halide_Julia
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION lib
)
18 changes: 18 additions & 0 deletions julia_bindings/src/JlFunc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "JlFunc.h"

#include <string>
#include <vector>

namespace Halide {
namespace JuliaBindings {


JLCXX_MODULE define_func(jlcxx::Module& m) {
m.add_type<Func>("Func")
.constructor<const std::string&>()
.constructor<>()
.method("name", &Func::name);
}

} // namespace JuliaBindings
} // namespace Halide
14 changes: 14 additions & 0 deletions julia_bindings/src/JlFunc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef HALIDE_JULIA_BINDINGS_JLFUNC_H
#define HALIDE_JULIA_BINDINGS_JLFUNC_H

#include "JlHalide.h"

namespace Halide {
namespace JuliaBindings {

JLCXX_MODULE define_func(jlcxx::Module& m);

} // namespace JuliaBindings
} // namespace Halide

#endif // HALIDE_JULIA_BINDINGS_JLFUNC_H
11 changes: 11 additions & 0 deletions julia_bindings/src/JlHalide.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "JlHalide.h"

static_assert(JLCXX_VERSION_MAJOR == 0 && JLCXX_VERSION_MINOR == 8 && JLCXX_VERSION_PATCH >= 2,
"Halide requires JlCxx 0.8.2+");

namespace Halide {
namespace JuliaBindings {


} // namespace JuliaBindings
} // namespace Halide
10 changes: 10 additions & 0 deletions julia_bindings/src/JlHalide.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef HALIDE_JULIA_BINDINGS_JLHALIDE_H
#define HALIDE_JULIA_BINDINGS_JLHALIDE_H

#include <jlcxx/jlcxx_config.hpp> // For compatibility check
#include <jlcxx/jlcxx.hpp>

// Everyone needs Halide.h
#include "Halide.h"

#endif // HALIDE_JULIA_BINDINGS_JLHALIDE_H

0 comments on commit c45be97

Please sign in to comment.