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
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions subprojects/kafel.wrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[wrap-file]
directory = kafel-20231004
source_url = https://github.com/google/kafel/archive/20231004.tar.gz
source_filename = 231004.tar.gz
source_hash = b5fe85ad72070844dc24474a036f3b909c3f604b69c616d124793c37df7a9d7f
patch_directory = kafel

[provide]
dependency_names = kafel
program_names = dump_policy_bpf
72 changes: 72 additions & 0 deletions subprojects/packagefiles/kafel/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
project('kafel', 'c',
version: '2023.10.10',
default_options: [
'c_std=gnu11',
])

flex = find_program('flex')
bison = find_program('bison')
pkgconf = import('pkgconfig')

run_command(flex, '--outfile=lexer.c', 'src/lexer.l', check: true)
run_command(bison, '-o=parser.c', 'src/parser.y', check: true)
Comment on lines +11 to +12
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.


kafel_sources = files(
'src/kafel.c',
'src/context.c',
'src/codegen.c',
'src/expression.c',
'src/includes.c',
'src/parser_types.c',
'src/policy.c',
'src/range_rules.c',
'src/syscall.c',
'src/syscalls/amd64_syscalls.c',
'src/syscalls/i386_syscalls.c',
'src/syscalls/aarch64_syscalls.c',
'src/syscalls/mipso32_syscalls.c',
'src/syscalls/mips64_syscalls.c',
'src/syscalls/riscv64_syscalls.c',
'src/syscalls/arm_syscalls.c',
'lexer.c',
'parser.c'
Comment on lines +31 to +32
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_inc = include_directories('include', 'src')

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.

)

kafel_dep = declare_dependency(
include_directories: kafel_inc,
link_with: kafel_lib
)

dump_policy_bpf_sources = files(
'tools/dump_policy_bpf/disasm.c',
'tools/dump_policy_bpf/main.c',
'tools/dump_policy_bpf/print.c',
)

dump_policy_bpf_exe = executable('dump_policy_bpf',
sources: dump_policy_bpf_sources,
dependencies: [kafel_dep],
install: true
)

install_headers('include/kafel.h', subdir: 'kafel')

meson.override_find_program('dump_policy_bpf', dump_policy_bpf_exe)
meson.override_dependency('kafel', kafel_dep)

pkgconf.generate(
name : 'kafel',
description : 'Kafel - seccomp filter generator',
version : meson.project_version(),
filebase : 'kafel',
subdirs : 'kafel',
libraries : kafel_lib
Comment on lines +66 to +71
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.

)
Loading