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

Stable API for wrapper generators #17

Open
haxscramper opened this issue Oct 13, 2021 · 2 comments
Open

Stable API for wrapper generators #17

haxscramper opened this issue Oct 13, 2021 · 2 comments

Comments

@haxscramper
Copy link
Owner

haxscramper commented Oct 13, 2021

Stable documented API for automatically writing wrapper generators scripts using multiple parsing frontends and code expansion logic. Ideally it should not be necessary in large number of cases (for simpler libraries), but something like this libgit wrappers

let resultGrouped = wrapCSharedLibViaTsWave(
  inDir       = AbsDir"/usr/include/git2",
  outDir      = currentAbsSourceDir(),
  tmpDir      = getAppTempDir() / "v4",
  libName     = "git2",
  packageName = package,
  ignoreIn    = @["stdint"],
  depDirs     = @[ssh2],
  extraTypes  = @{
    cxxName("git_iterator"): cxxLibImport(package, @["libgit2_config"])
  }
)

or this libssh2 wrappers

let
  dir     = AbsDir"/usr/include"
  tmpDir  = getAppTempDir() / "libssh2"
  package = "hlibssh2"
  files   = @[
    dir /. "libssh2.h",
    dir /. "libssh2_sftp.h",
    dir /. "libssh2_publickey.h"
  ]
  map     = expandViaWave(files, tmpDir, baseCParseConf)
  conf    = initCSharedLibFixConf("ssh2", package, false, dir, map)
  wrapped = tmpDir.wrapViaTs(conf)
  outDir  = currentAbsSourceDir()
  grouped = writeFiles(outDir, wrapped, cCodegenConf, extraTypes = @{
    cxxName("_LIBSSH2_SESSION"): cxxLibImport(package, @["libssh2_config"])
  })

is necessary. This API can further be expanded on, to automate handling of the conan packages, git and github repositories, automatic tracking of changes (#9) and so on.

@haxscramper
Copy link
Owner Author

haxscramper commented Nov 16, 2021

Need to add support for interfacing with C++ package managers, at least with conan. Tried using it in CI builds - absolutely awesome, amounts to several very simple commands and one (not really obvious though) flag passed to the gcc - @$(pwd)/conanbuildinfo.gcc allows reading list of flags from the conanbuildinfo.gcc file generated by conan.

pip install conan
conan install . --build=missing
nimble -y develop
nim c -r \
	  --passL:"@$(pwd)/conanbuildinfo.gcc" \
	  --passC:"@$(pwd)/conanbuildinfo.gcc" \
	  -d:libgit2LinkMode=dlink \
	  -d:libssh2LinkMode=dlink \
	  tests/test1.nim

@haxscramper
Copy link
Owner Author

In addition to the API wrapper generation, it is also necessary to properly reuse all the type import maps from the dependencies. For example, libssh2 contains a file with all the types encountered when wrapping this library. When libgit wrapper is generated, it must know a list of dependencies to be able to properly read import maps. In an ideal world, this could've been solved by asking package manager to list the locations of all the dependencies, and then simply searching for the hcparse_type_imports.xml file in the repositories. Nimble cannot do this at all, but with nimph I can at least try and read the environment in which wrapper generation is performed, and find all target import maps.

haxscramper added a commit that referenced this issue Nov 17, 2021
- ADDED ::
  - Find absolute paths to type import maps using list of paths (expected
    to be derived from the `nim dump` command, but any source would work)
- RELATED ::
  - #17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant