Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various fixes for cmake based find_package #10

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions .src/box.inl
Expand Up @@ -3,8 +3,8 @@
// Created on 31.01.22 by clem (mail@clemens-cords.com)
//

#include <include/julia_extension.hpp>
#include <include/cppcall.hpp>
#include "julia_extension.hpp"
#include "cppcall.hpp"

#include <iostream>

Expand Down Expand Up @@ -274,4 +274,4 @@ namespace jluna
{
return register_unnamed_function<T>(lambda);
}
}
}
2 changes: 1 addition & 1 deletion .src/c_adapter.cpp
Expand Up @@ -4,7 +4,7 @@

#include <iostream>

#include <.src/c_adapter.hpp>
#include "c_adapter.hpp"
Comment on lines 6 to +7
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm misunderstanding the purpose of replacing <> with "" everywhere, but the reason I intentionally kept the .src/ and include/ prefix was, so that when a user types in their IDE something like:

#include <

then I don't want my .src files showing up in the recommended completions (the thingy where when you press tab it auto-completes the statement). This is especially true with c_adapter, I don't want any of the users to even be aware what functions are in there, as it can break things in very odd ways. All files in .src and the entire c_adapter should be as hidden from end-users as possible.
Idk if this is true, but it feels like your restructuring made it, so users would have an easier time accessing the source and inline files, which I don't like. Correct me if I am wrong, though, as I'm not super sure what the full reason for the switch to "" was

Copy link
Author

@robertu94 robertu94 Mar 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In gcc, clang, (and I think msvc) " based brackets search the current directory of the current file before searching the global include path. Where as < doesn't search locally first.

I moved them because they have to be installed some where to build a downstream library based on libjluna. When using a package manager, you can't assume that you have the cloned repo available, only the files explicitly installed.

Unfortunately, even with the < style includes, I still get auto complete suggestions for things in .src it's kind of unavoidable. There might be some other way to hide them, but it doesn't for me.

In the case where I don't want user's touching things, I typically use the PIMPL idiom to hide the implemenation and leave the details in the shared object as much as possible. Unfortunately that can be difficult with highly templatized code like this. I can't wait for wide support for modules when this can be a thing of the past.


extern "C"
{
Expand Down
6 changes: 3 additions & 3 deletions .src/cppcall.inl
Expand Up @@ -3,9 +3,9 @@
// Created on 31.01.22 by clem (mail@clemens-cords.com)
//

#include <include/julia_extension.hpp>
#include <include/exceptions.hpp>
#include <.src/c_adapter.hpp>
#include "julia_extension.hpp"
#include "exceptions.hpp"
#include "c_adapter.hpp"

namespace jluna
{
Expand Down
4 changes: 2 additions & 2 deletions .src/exceptions.cpp
Expand Up @@ -3,8 +3,8 @@
// Created on 30.01.22 by clem (mail@clemens-cords.com)
//

#include <include/exceptions.hpp>
#include <include/julia_extension.hpp>
#include "exceptions.hpp"
#include "julia_extension.hpp"

#include <sstream>
#include <vector>
Expand Down
2 changes: 1 addition & 1 deletion .src/expression.cpp
Expand Up @@ -3,7 +3,7 @@
// Created on 01.02.22 by clem (mail@clemens-cords.com)
//

#include <include/expression.hpp>
#include "expression.hpp"

namespace jluna
{
Expand Down
4 changes: 2 additions & 2 deletions .src/function.cpp
Expand Up @@ -3,7 +3,7 @@
// Created on 10.02.22 by clem (mail@clemens-cords.com)
//

#include <include/function.hpp>
#include "function.hpp"

namespace jluna
{}
{}
4 changes: 2 additions & 2 deletions .src/generator_expression.cpp
Expand Up @@ -3,8 +3,8 @@
// Created on 16.02.22 by clem (mail@clemens-cords.com)
//

#include <include/generator_expression.hpp>
#include <include/state.hpp>
#include "generator_expression.hpp"
#include "state.hpp"

namespace jluna
{
Expand Down
11 changes: 2 additions & 9 deletions .src/include_julia.inl.in
Expand Up @@ -5,12 +5,5 @@

#pragma once

#cmakedefine RESOURCE_PATH "@RESOURCE_PATH@"

namespace jluna::detail
{
///@brief allow julia to load jluna by using C++ #import statement
static inline const char* include = R"(
include("@RESOURCE_PATH@/include/jluna.jl")
)";
}
#define RUN_RESOURCE_DIR "@CMAKE_INSTALL_FULL_INCLUDEDIR@"
#define BUILD_RESOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@"
4 changes: 2 additions & 2 deletions .src/module.cpp
Expand Up @@ -3,8 +3,8 @@
// Created on 07.02.22 by clem (mail@clemens-cords.com)
//

#include <include/module.hpp>
#include <include/state.hpp>
#include "module.hpp"
#include "state.hpp"

namespace jluna
{
Expand Down
8 changes: 4 additions & 4 deletions .src/proxy.cpp
Expand Up @@ -8,9 +8,9 @@
#include <sstream>
#include <iostream>

#include <include/state.hpp>
#include <include/proxy.hpp>
#include <include/type.hpp>
#include "state.hpp"
#include "proxy.hpp"
#include "type.hpp"

namespace jluna
{
Expand Down Expand Up @@ -215,4 +215,4 @@ namespace jluna
static jl_function_t* isa = jl_get_function(jl_base_module, "isa");
return unbox<bool>(jluna::safe_call(isa, this->operator const _jl_value_t *(), type.operator const _jl_value_t *()));
}
}
}
48 changes: 38 additions & 10 deletions .src/state.cpp
Expand Up @@ -5,18 +5,18 @@

#include <julia.h>

#include <memory>
#include <sstream>
#include <iostream>
#include <fstream>

#include <include/state.hpp>
#include <include/exceptions.hpp>
#include <include/julia_extension.hpp>
#include <include/proxy.hpp>
#include <.src/include_julia.inl>
#include <include/module.hpp>
#include <include/type.hpp>

#include "state.hpp"
#include "exceptions.hpp"
#include "julia_extension.hpp"
#include "proxy.hpp"
#include "include_julia.inl"
#include "module.hpp"
#include "type.hpp"

namespace jluna::detail
{
Expand All @@ -42,7 +42,28 @@ namespace jluna::State
else
jl_init_with_image(path.c_str(), NULL);

jl_eval_string(jluna::detail::include);
const char* julia_lib_load_template = R"julia(
begin
local dev_path = "%s/include/jluna.jl"
local prod_path = "%s/jluna/jluna.jl"
if isfile(dev_path)
include(dev_path)
else isfile(prod_path)
include(prod_path)
end
end
)julia";
std::vector<char> buf (
/* no need to account for null since %s takes 4 bytes accounted for
* which is double counted by BUILD_RESOURCE_DIR and RUN_RESOURCE_DIR */
strlen(julia_lib_load_template) +
strlen(BUILD_RESOURCE_DIR) +
strlen(RUN_RESOURCE_DIR),
/*c strings are null terminated*/
'\0'
);
snprintf(buf.data(), buf.size(), julia_lib_load_template, BUILD_RESOURCE_DIR, RUN_RESOURCE_DIR);
jl_eval_string(buf.data());
Comment on lines +45 to +66
Copy link
Owner

@Clemapfel Clemapfel Mar 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While std::format would be nice, I feel like assembling this with std::stringstream and then calling jl_eval_string(stringstream_var.str().c_str() would've been a lot easier, but fair play to you for doing it C-style (no reason not to do it this way, it just sounds needlessly hard)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also how come std::format is the single feature where clang is further than gcc, very odd, usually gcc is much faster at implementing the new stuff.

forward_last_exception();


Expand All @@ -57,7 +78,14 @@ namespace jluna::State
)");
forward_last_exception();

jl_eval_string(("jluna._cppcall.eval(:(_library_name = \"" + std::string(RESOURCE_PATH) + "/libjluna_c_adapter.so\"))").c_str());
jl_eval_string(
R"julia(
begin
import Libdl
local lib_path = Libdl.dlpath("libjluna_c_adapter")
jluna._cppcall._set_library_name(lib_path)
end
)julia");
forward_last_exception();

jl_eval_string(R"(
Expand Down
10 changes: 5 additions & 5 deletions .src/state.inl
Expand Up @@ -3,10 +3,10 @@
// Created on 02.02.22 by clem (mail@clemens-cords.com)
//

#include <include/julia_extension.hpp>
#include <include/proxy.hpp>
#include <include/array.hpp>
#include <include/module.hpp>
#include "julia_extension.hpp"
#include "proxy.hpp"
#include "array.hpp"
#include "module.hpp"

namespace jluna::State
{
Expand Down Expand Up @@ -292,4 +292,4 @@ namespace jluna::State

return Proxy(res);
}
}
}
2 changes: 1 addition & 1 deletion .src/symbol.cpp
Expand Up @@ -3,7 +3,7 @@
// Created on 07.02.22 by clem (mail@clemens-cords.com)
//

#include <include/symbol.hpp>
#include "symbol.hpp"

namespace jluna
{
Expand Down
4 changes: 2 additions & 2 deletions .src/type.cpp
Expand Up @@ -3,8 +3,8 @@
// Created on 07.02.22 by clem (mail@clemens-cords.com)
//

#include <include/type.hpp>
#include <include/symbol.hpp>
#include "type.hpp"
#include "symbol.hpp"

namespace jluna
{
Expand Down
4 changes: 2 additions & 2 deletions .src/usertype.inl
Expand Up @@ -3,7 +3,7 @@
// Created on 25.02.22 by clem (mail@clemens-cords.com)
//

#include <include/exceptions.hpp>
#include "exceptions.hpp"

namespace jluna
{
Expand Down Expand Up @@ -134,4 +134,4 @@ namespace jluna
{
return Usertype<T>::box(in);
}
}
}