-
Notifications
You must be signed in to change notification settings - Fork 215
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 Wrap: Kafel #1917
base: master
Are you sure you want to change the base?
New Wrap: Kafel #1917
Conversation
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 haven't fully reviewed this, but I have some comments for you.
run_command(flex, '--outfile=lexer.c', 'src/lexer.l', check: true) | ||
run_command(bison, '-o=parser.c', 'src/parser.y', check: true) |
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.
You don't want to use run_command
for this, this is what custom_target
is for:
lexer = custom_target(
command : [flex, '--outfile=@OUTPUT0@', '--header-file=@OUTPUT1@', '@INPUT@'],
input : 'src/lexer.l',
output : ['@[email protected]', '@[email protected]'],
)
parser = custom_target(
command : [bison, '-o', '@OUTPUT0@', '--defines=@OUTPUT1@', '@INPUT@'],
input : 'src/parser.y',
output : ['@[email protected]', '@[email protected]'],
)
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, I had already tried it that way, but it didn't work, so I resorted to using run_command. Many people who use flex and bison seem to face the same issue and end up resorting to this method.
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.
With this method it simply does not generate the .c files.
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 won’t generate the c file if you don’t add the parser variable to the target, because custom targets are not built by default.
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 am adding it, and it still doesn't work.
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.
Here's an example of how to do it: https://github.com/dcbaker/meson-plus-plus/blob/main/src/frontend/meson.build
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, I had already tried using custom_target
before, but without success. It fails to generate the files at the exact moment they are needed, resulting in file not found errors. I attempted to fix this but was unable to resolve the issue.
However, after researching, I found an approach using run_command
, which is used in similar contexts to mine.
Some examples:
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.
Neither of those projects are doing the right thing. There are two problems with the run_target approach you're taking,
- it writes files into the source directory. Meson generally promises not to do this, because it causes issues, many cmake projects specifically go out of their way to turn off in-tree builds
- the flex and bison files get written at configure time instead of build time, which means that their inputs are not properly tracked (so among other things ninja clean cant erase them), and to regenerate them a user needs to manually re-run meson, since Meson doesn't know those command write files
The critical thing here is that the output of the assigned variable from the custom_target needs to be in the sources list of the target that requires it:
x = custom_target(...)
library(
'foo',
'foo.c', 'lib..c', x,
)
That is how Meson knows that libfoo
depends on the output of x
, and properly orders it so that x
is generated before any files in libfoo
start compiling. the Meson++ example I pointed you to demonstrates how to write this as a custom_target
, which is the right way to do this.
run_target
isn't for codegen, it's for things like running linters or code formatters.
'lexer.c', | ||
'parser.c' |
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.
Then you'll want to use the parser
and lexer
variables instead of these.
kafel_lib = library('kafel', | ||
sources: kafel_sources, | ||
include_directories: kafel_inc, | ||
install: true |
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.
gnu_symbol_visibility : 'hidden',
soversion : 1,
is also needed to match the makefile.
You'll need to double check that soversion though, and make sure it matches the makefile.
name : 'kafel', | ||
description : 'Kafel - seccomp filter generator', | ||
version : meson.project_version(), | ||
filebase : 'kafel', | ||
subdirs : 'kafel', | ||
libraries : kafel_lib |
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.
you can pass kafel_lib
as a positional argument here, which will eliminate some of the need to repeat yourself, at least name
, filebase
, and libraries
can be dropped if you do that.
No description provided.