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 Wrap: Kafel #1917

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Conversation

manipuladordedados
Copy link

No description provided.

Copy link
Member

@dcbaker dcbaker left a 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.

Comment on lines +11 to +12
run_command(flex, '--outfile=lexer.c', 'src/lexer.l', check: true)
run_command(bison, '-o=parser.c', 'src/parser.y', check: true)
Copy link
Member

@dcbaker dcbaker Feb 12, 2025

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]'],
)

Copy link
Author

@manipuladordedados manipuladordedados Feb 12, 2025

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.

Copy link
Author

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.

Copy link
Member

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.

Copy link
Author

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.

Copy link
Member

@dcbaker dcbaker Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

@manipuladordedados manipuladordedados Feb 14, 2025

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:

Copy link
Member

@dcbaker dcbaker Feb 14, 2025

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,

  1. 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
  2. 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.

Comment on lines +31 to +32
'lexer.c',
'parser.c'
Copy link
Member

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
Copy link
Member

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.

Comment on lines +66 to +71
name : 'kafel',
description : 'Kafel - seccomp filter generator',
version : meson.project_version(),
filebase : 'kafel',
subdirs : 'kafel',
libraries : kafel_lib
Copy link
Member

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.

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