-
Couldn't load subscription status.
- 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
| "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
|
|
||
| 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
|
|
||
| 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
| } | ||
|
|
||
| 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.
| 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:
{ "_stdio.h": "scala.scalanative.native.stdio", "hiredis.h": { "object": "bindings.hiredis.hiredis", "names": { "struct redisContext": "RedisContext" } } }To do:
struct s->sinstead ofstruct_s)