diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index dae3375..c569b13 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -18,3 +18,12 @@ jobs: - uses: actions/checkout@v1 - run: xbps-install -Sy clang make bearssl-devel - run: CC=clang ci/run.sh + clang-musl-meson: + runs-on: ubuntu-latest + container: voidlinux/voidlinux-musl + steps: + - uses: actions/checkout@v1 + - run: | + xbps-install -Syu || xbps-install -yu xbps + xbps-install -y clang meson ninja bearssl-devel + - run: CC=clang ci/run-meson.sh diff --git a/.gitignore b/.gitignore index 2dd9280..39a3f1a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ purr tests gemi +build/ *.o *.a *.d diff --git a/README.md b/README.md index beb44f6..d754f29 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,15 @@ You can build and install the project with the commands below: ``` $ ./configure # creates config.mk $ make -$ make install PREFIX=$HOME/.local/bin +$ make install PREFIX=$HOME/.local +``` + +Alternatively, you can use the Meson build system: + +``` +$ meson build --prefix $HOME/.local +$ ninja -C build +$ ninja -C install ``` ## Programs diff --git a/ci/run-meson.sh b/ci/run-meson.sh new file mode 100755 index 0000000..2f1bc67 --- /dev/null +++ b/ci/run-meson.sh @@ -0,0 +1,4 @@ +#!/bin/sh -x +meson build/ +ninja -C build/ all +RATELIMIT=1 ninja -C build/ test diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..61d0672 --- /dev/null +++ b/meson.build @@ -0,0 +1,72 @@ +project('purr-c', 'c', + version : '0.1', + default_options : ['warning_level=3']) + +compiler = meson.get_compiler('c') + +bearssl = compiler.find_library('bearssl', required: true) + +gnu_source = '#define _GNU_SOURCE' +getrandom = compiler.has_header_symbol('sys/random.h', 'getrandom') +arc4random = compiler.has_header_symbol('stdlib.h', 'arc4random') +gnu_progname = compiler.has_header_symbol( + 'errno.h', + 'program_invocation_short_name', + prefix: gnu_source +) +bsd_progname = compiler.has_header_symbol('stdlib.h', 'getprogname') +sock_cloexec = compiler.has_header_symbol('sys/socket.h', 'SOCK_CLOEXEC') +pipe2 = compiler.has_header_symbol('unistd.h', 'pipe2', prefix: gnu_source) + +args = [] +if arc4random + args += '-DHAVE_ARC4RANDOM' +elif getrandom + args += '-DHAVE_GETRANDOM' +else + error('no random buf impl') +endif +if bsd_progname + args += '-DHAVE_GETPROGNAME' +elif gnu_progname + args += '-DHAVE_PROG_INVOCATION' +elif + error('no progname impl') +endif +if sock_cloexec + args += '-DHAVE_SOCK_CLOEXEC_H' +endif +if pipe2 + args += '-DHAVE_PIPE2' +endif +add_project_arguments(args, language: 'c') + +purrlib = static_library( + 'purrlib', + 'mmap_file.c', + 'gemini.c', + 'read_certs.c', + 'urls.c', + 'files.c', + 'pager.c', + 'comm.c', + 'formats.c', + 'encrypt.c', + 'socket.c', +) + +executable('purr', 'purr.c', link_with: purrlib, dependencies: bearssl, install: true) +executable('gemi', 'gemi.c', link_with: purrlib, dependencies: bearssl, install: true) + +command = 'ln -sf purr ${DESTDIR}/${MESON_INSTALL_PREFIX}/@0@/@1@' +meson.add_install_script('sh', '-c', command.format(get_option('bindir'), 'meow')) +meson.add_install_script('sh', '-c', command.format(get_option('bindir'), 'meowd')) + +tests = executable('tests', 'tests.c', link_with: purrlib, dependencies: bearssl, install: false) +test('library-tests', tests) +test( + 'executable-tests', + find_program('test.sh'), + args: meson.current_source_dir() / 'README.md', + workdir: meson.current_build_dir() +) diff --git a/test.sh b/test.sh index 5e9c0b6..59afd38 100755 --- a/test.sh +++ b/test.sh @@ -1,4 +1,5 @@ #!/bin/sh +readme="${1:-README.md}" EXIT= assert () { if [ "$1" != "$2" ]; then @@ -21,15 +22,15 @@ r="$(./purr r https://www.wikipedia.org | xbps-digest)" assert "$e" "$r" echo "Pastebin and retrieve - unencrypted" -e="$(xbps-digest README.md)" -r="$(./purr r $(./purr s README.md) | xbps-digest)" +e="$(xbps-digest "$readme")" +r="$(./purr r $(./purr s "$readme") | xbps-digest)" assert "$e" "$r" rate_limit echo "Pastebin and retrieve - encrypted" -e="$(xbps-digest README.md)" -r="$(./purr -e r $(./purr -e s README.md) | xbps-digest)" +e="$(xbps-digest "$readme")" +r="$(./purr -e r $(./purr -e s "$readme") | xbps-digest)" assert "$e" "$r" # TODO: find some reliable way of testing gemi