-
Notifications
You must be signed in to change notification settings - Fork 7
Reuse generated bindings #140
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
Conversation
bc0fea7
to
e698e7f
Compare
1242546
to
49be660
Compare
11fcf04
to
4735226
Compare
200ab75
to
85fedc2
Compare
81de677
to
bfa9529
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good although I hope we can figure out a way to make this change work with the PR to use bindings options in the sbt plugin.
bindgen/Main.cpp
Outdated
@@ -26,6 +26,10 @@ int main(int argc, const char *argv[]) { | |||
llvm::cl::opt<std::string> LinkName( | |||
"link", llvm::cl::cat(Category), | |||
llvm::cl::desc("Library to link with, e.g. -luv for libuv")); | |||
llvm::cl::opt<std::string> ReuseBindingsConfig( | |||
"integrate-bindings", llvm::cl::cat(Category), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--binding-config might be better
@@ -62,6 +66,11 @@ int main(int argc, const char *argv[]) { | |||
std::string resolved = getRealPath(op.getSourcePathList()[0].c_str()); | |||
LocationManager locationManager(resolved); | |||
|
|||
auto reuseBindingsConfig = ReuseBindingsConfig.getValue(); | |||
if (!reuseBindingsConfig.empty()) { | |||
locationManager.loadConfig(reuseBindingsConfig); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any thoughts on also providing a built-in default config to ease use of the standard library bindings from Scala Native
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be a separate option, for example, useStandardScalaNativeBindings: Boolean
I looked through native
package and found types only in stdio
and in complex
(but bindgen fails to translate float complex
, double complex
etc types, so currently it's not possible to reuse complex
).
The easiest solution would be to hard code standard config in C++ code and "activate" it by passing use-standard-scala-native-bindings
option.
Or it is possible to support multiple config files, so sbt plugin can pass to bindgen a user-defined config(s) and a standard config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created an issue #147
bindgen/ir/IR.cpp
Outdated
@@ -462,13 +461,21 @@ IR::~IR() { | |||
} | |||
|
|||
template <typename T> | |||
bool IR::hasOutputtedDeclaration( | |||
bool IR::hasOutputtedType( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldOutoutType for consistency?
s << line; | ||
} | ||
config = json::parse(s.str()); | ||
validateConfig(config); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great that you put validation of the configuration. ❤️
bindgen/ir/LocationManager.cpp
Outdated
std::string object = headerEntry.get<std::string>(); | ||
if (object.empty()) { | ||
throw std::invalid_argument("Invalid configuration. Each header " | ||
"entry should contain non empty " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it is "non-empty'
bindgen/ir/TypeDef.cpp
Outdated
} | ||
if (!type) { | ||
if (startsWith(name, "struct_")) { | ||
return "struct " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we still encode the name with an underscore internally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that it's better to store types with spaces
@@ -111,6 +118,11 @@ object Bindgen { | |||
copy(extraArgBefore = extraArgBefore ++ args) | |||
} | |||
|
|||
def integrateBindings(config: File): Bindgen = { | |||
require(config.exists()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a proper error message here.
@@ -130,6 +142,9 @@ object Bindgen { | |||
withArgs("--exclude-prefix", excludePrefix) ++ | |||
withArgs("--extra-arg", extraArg) ++ | |||
withArgs("--extra-arg-before", extraArgBefore) ++ | |||
integrateBindingsConfig | |||
.flatMap(c => Option(Seq("--integrate-bindings", c.getAbsolutePath))) | |||
.getOrElse(Seq[String]()) ++ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't withArgs work here?
withArgs("--...", integrateBindingsConfig)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
withArgs("--binding-config", bindingConfig.map(_.getAbsolutePath))
does work
fe73222
to
04a5d59
Compare
Use json format for config file Update documentation
04a5d59
to
4b91635
Compare
Closes #2
Compilation requires https://github.com/nlohmann/json library.
Format of config file changed to json. It is very similar to previous stdHeaders file, but it provides a way to specify custom names mapping:
To do:
struct s
->s
instead ofstruct_s
)