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

Macro constant referencing an enumerator does not generate a Rust constant #2192

Closed
doctortheemh opened this issue Apr 21, 2022 · 2 comments
Closed

Comments

@doctortheemh
Copy link

Hi all. I'm working on an issue with ffmpeg-next and ffmpeg-sys-next, which are rust bindings to ffmpeg. I'm seeing build errors for former crate on macos stemming from missing constants in the generated bindings. Curiously, linux does not seem to have this issue. I whittled down a smaller test case I believe represents the problem, however, both Linux and macos bindgen invocations are now producing the same results. I'm a bit at loss, can anyone advise if the behavior I'm seeing from bindgen makes sense?

Input C/C++ Header

enum AVChannel {
    AV_CHAN_NONE = -1,
    AV_CHAN_FRONT_LEFT,
};

#define AV_CH_FRONT_LEFT             (1ULL << AV_CHAN_FRONT_LEFT           )

Bindgen Invocation

$ bindgen test.h

Actual Results

/* automatically generated by rust-bindgen 0.59.2 */

pub const AVChannel_AV_CHAN_NONE: AVChannel = -1;
pub const AVChannel_AV_CHAN_FRONT_LEFT: AVChannel = 0;
pub type AVChannel = ::std::os::raw::c_int;

Expected Results

I'd expect to see a constant for AV_CH_FRONT_LEFT.

@kulp
Copy link
Member

kulp commented Jun 4, 2022

Curiously, linux does not seem to have this issue.

I am able to reproduce the issue both on macOS and on FreeBSD (I have no Linux hosts immediately available). If you can give evidence of platform-dependency, that would be interesting.

I think this is another case like #316 or #753. The desired AV_CH_FRONT_LEFT constant appears, if the definition is changed to avoid the reference to the AV_CHAN_FRONT_LEFT:

-#define AV_CH_FRONT_LEFT             (1ULL << AV_CHAN_FRONT_LEFT           )
+#define AV_CH_FRONT_LEFT             (1ULL << 0                            )

It would not be terribly surprising if bindgen cannot interpolate enums into macros, since bindgen would have to provide the enum values somehow to rust-cexpr's macro evaluation. If you want to look at something concrete, you might be able to estimate how feasible it would be for that to be done.

I do not have a concrete recommendation for you, besides manually coding the constant in your code; maybe @emilio would have one.

@kulp kulp changed the title Macro not generated Macro constant referencing an enumerator does not generate a Rust constant Jun 4, 2022
@kulp
Copy link
Member

kulp commented Jun 4, 2022

Sorry to say, I discovered this is a duplicate of a very old issue: #258.

@kulp kulp closed this as not planned Won't fix, can't repro, duplicate, stale Jun 4, 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

No branches or pull requests

2 participants