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

bindgen generation wrapper for cli use #74

Closed
wants to merge 2 commits into from
Closed

Conversation

dginev
Copy link
Member

@dginev dginev commented May 13, 2020

Bundles in a script that allows for directly regenerating src/bindings.rs via:

bindgen scripts/bindgen_wrapper.h -o src/bindings.rs -- `xml2-config --cflags`

Some steps towards #73

@ignatenkobrain
Copy link

So I have tried using this approach, but it does not really work on my laptop (x86_64):

error[E0308]: mismatched types
   --> src/c_helpers.rs:109:57
    |
109 |     xmlSetStructuredErrorFunc(ctxt as *mut c_void, Some(_ignoreInvalidTagsErrorFunc));
    |                                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected "C" fn, found "Rust" fn
    |
    = note: expected fn pointer `unsafe extern "C" fn(_, _)`
                  found fn item `fn(_, _) {c_helpers::_ignoreInvalidTagsErrorFunc}`

error[E0308]: mismatched types
  --> src/schemas/parser.rs:82:14
   |
82 |         Some(common::structured_error_handler),
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected "C" fn, found "Rust" fn
   |
   = note: expected fn pointer `unsafe extern "C" fn(_, _)`
                 found fn item `fn(_, _) {schemas::common::structured_error_handler}`

error[E0308]: mismatched types
   --> src/schemas/validation.rs:104:14
    |
104 |         Some(common::structured_error_handler),
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected "C" fn, found "Rust" fn
    |
    = note: expected fn pointer `unsafe extern "C" fn(_, _)`
                  found fn item `fn(_, _) {schemas::common::structured_error_handler}`

@ignatenkobrain
Copy link

and also:

error[E0425]: cannot find value `HACKY_WELL_FORMED` in this scope
   --> src/c_helpers.rs:101:7
    |
101 |       HACKY_WELL_FORMED = true;
    |       ^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find value `HACKY_WELL_FORMED` in this scope
   --> src/c_helpers.rs:108:5
    |
108 |     HACKY_WELL_FORMED = false;
    |     ^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find value `HACKY_WELL_FORMED` in this scope
   --> src/c_helpers.rs:114:59
    |
114 |   unsafe { (!ctxt.is_null() && (*ctxt).wellFormed > 0) || HACKY_WELL_FORMED }
    |                                                           ^^^^^^^^^^^^^^^^^ not found in this scope

@ignatenkobrain
Copy link

FYI, I use libxml2-2.9.10-4.fc33.x86_64

@ignatenkobrain
Copy link

It seems that HACKY_WELL_FORMED is something what exists just in your copy of libxml2. Google does not seem to know about such constant anywhere else :)

@ignatenkobrain
Copy link

bindgen --raw-line "#![allow(non_camel_case_types)]" --raw-line "/* helper var until we figure out well-formedness checks */" --raw-line "pub static mut HACKY_WELL_FORMED: bool = false;" --whitelist-function "(xml|html|xlink).+" --whitelist-var "(XML|HTML).+" --whitelist-type "(xml|html).+" --ctypes-prefix libc scripts/bindgen_wrapper.h -o src/bindings.rs -- -I/usr/include/libxml2 is able to give something actually meaningful :)

@ignatenkobrain
Copy link

With this bindgen command, I am down to just one relevant failure:

error[E0308]: mismatched types
   --> src/c_helpers.rs:109:57
    |
109 |     xmlSetStructuredErrorFunc(ctxt as *mut c_void, Some(_ignoreInvalidTagsErrorFunc));
    |                                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected "C" fn, found "Rust" fn
    |
    = note: expected fn pointer `unsafe extern "C" fn(_, _)`
                  found fn item `fn(_, _) {c_helpers::_ignoreInvalidTagsErrorFunc}`

error[E0308]: mismatched types
  --> src/schemas/parser.rs:82:14
   |
82 |         Some(common::structured_error_handler),
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected "C" fn, found "Rust" fn
   |
   = note: expected fn pointer `unsafe extern "C" fn(_, _)`
                 found fn item `fn(_, _) {schemas::common::structured_error_handler}`

error[E0308]: mismatched types
   --> src/schemas/validation.rs:104:14
    |
104 |         Some(common::structured_error_handler),
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected "C" fn, found "Rust" fn
    |
    = note: expected fn pointer `unsafe extern "C" fn(_, _)`
                  found fn item `fn(_, _) {schemas::common::structured_error_handler}`

error: aborting due to 3 previous errors

@dginev
Copy link
Member Author

dginev commented May 15, 2020

Hi @ignatenkobrain ,

I realize the PR is not completed, as I mentioned just "some steps" towards a solution. The traces are a bit distracting here to be honest, as much as I like the friendly messages of rustc. As you noticed, c_helpers.rs needs to receive some of the non-bindgen content from bindings.rs, at which point we can hope it's a simple swap.

@dginev dginev force-pushed the master branch 3 times, most recently from 935747d to 456cdf0 Compare September 29, 2020 01:17
@dginev
Copy link
Member Author

dginev commented Mar 26, 2022

Actually I'll close to avoid the wrong impression that I'm planning on working on this further myself. The general problem remains unsolved.

@dginev dginev closed this Mar 26, 2022
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

Successfully merging this pull request may close these issues.

2 participants