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

new binding for libclang-v17 #183

Open
Newbluecake opened this issue Mar 1, 2024 · 7 comments
Open

new binding for libclang-v17 #183

Newbluecake opened this issue Mar 1, 2024 · 7 comments

Comments

@Newbluecake
Copy link

Hi, I'm using this library to parse c/c++ code. Everying is good until I need a new api in v17. I try to gen binding for this version, but there seems to be some error. Could you support this version?

@anatol
Copy link

anatol commented May 24, 2024

The same request. Is this library planned to be ported to the latest LLVM release?

@Newbluecake
Copy link
Author

Newbluecake commented May 27, 2024

I have ported one https://github.com/Newbluecake/bootstrap/tree/clang-v17, but not latest version

@anatol
Copy link

anatol commented May 29, 2024

Thank you @Newbluecake for your work.

I am trying to compile this code with your library https://gist.githubusercontent.com/josharian/54b2268af5792ff0e62f06437f28a8c9/raw/f4d07e7340ae0bf84991deaa9d2cb478b7909d4a/gen_git2go_enum.go

and I have a warning:

# github.com/Newbluecake/bootstrap/clang
cgo-gcc-prolog: In function ‘_cgo_19b11e5eef9a_Cfunc_clang_getDiagnosticCategoryName’:
cgo-gcc-prolog:269:2: warning: ‘clang_getDiagnosticCategoryName’ is deprecated [-Wdeprecated-declarations]
In file included from ../../../go/pkg/mod/github.com/!newbluecake/[email protected]/clang/clang_gen.go:4:
../../../go/pkg/mod/github.com/!newbluecake/[email protected]/clang/./clang-c/CXDiagnostic.h:314:1: note: declared here
  314 | clang_getDiagnosticCategoryName(unsigned Category);
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

it seems harmless. But then I run the tool with ./tool -fname ~/sources/libgit2/include/git2/oid.h but it fails:

/usr/include/time.h:29:10: fatal error: 'stddef.h' file not found
PROBLEM: 'stddef.h' file not found

which seems comes from

tu := idx.ParseTranslationUnit(*fname, []string{"-DDOCURIUM=1"}, nil, 0)

line. Do you have any idea why does it fail to find clang's stddef.h file?

My system is Arch Linux up-to-date with clang v17:

$ clang --version
clang version 17.0.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

@Newbluecake
Copy link
Author

Newbluecake commented May 29, 2024

Yeah, it seems that libclang did't automatically add system dir for header search. I add following code in my project to fix this problem:

	cmd := exec.Command("bash", "-c", "echo | clang -E -v -")
	output, err := cmd.CombinedOutput()
	if err != nil {
		return utils.LogError("exec clang err: %v", err)
	}

	outputStr := string(output)
	lines := strings.Split(outputStr, "\n")
	var start, end int
	for i, line := range lines {
		if line == "#include <...> search starts here:" {
			start = i + 1
		} else if line == "End of search list." {
			end = i - 1
			break
		}
	}

	for i := start; i <= end; i++ {
		dir := strings.TrimSpace(lines[i])
		if dir == "" {
			continue
		}

		psr.SysInclude = append(psr.SysInclude, dir)
	}

@anatol
Copy link

anatol commented May 30, 2024

It is a bit strange that libclang is unable to detect the clang's sysinclude dir automatically.

BTW @Newbluecake is there any chance you can update the bindings to clang-v18?

@Newbluecake
Copy link
Author

@anatol Sorry about that, you may checkout https://github.com/Newbluecake/gen and try it. If you have any question, I can help you.

@lilili87222
Copy link

Can this generate libtooling binding of clang?

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

3 participants