Skip to content

Commit

Permalink
YAJL to Jansson
Browse files Browse the repository at this point in the history
Signed-off-by: Sourav Moitra <[email protected]>
  • Loading branch information
xw19 committed Dec 30, 2024
1 parent a48818a commit a010d12
Show file tree
Hide file tree
Showing 38 changed files with 518 additions and 776 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

- run: |
sudo apt-get update
sudo apt-get install -y make git gcc build-essential pkgconf libtool libsystemd-dev libcap-dev libseccomp-dev libyajl-dev go-md2man libtool autoconf python3 automake libprotobuf-c-dev
sudo apt-get install -y make git gcc build-essential pkgconf libtool libsystemd-dev libcap-dev libseccomp-dev libjansson-dev go-md2man libtool autoconf python3 automake libprotobuf-c-dev
./autogen.sh
./configure
make -j $(nproc)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

- run: sudo apt-get update

- run: sudo apt-get install -y make git gcc build-essential pkgconf libtool libsystemd-dev libcap-dev libseccomp-dev libyajl-dev go-md2man libtool autoconf python3 automake libprotobuf-c-dev
- run: sudo apt-get install -y make git gcc libc6-dev build-essential pkgconf libtool libsystemd-dev libcap-dev libseccomp-dev libjansson-dev go-md2man libtool autoconf python3 automake libprotobuf-c-dev

- run: |
set -ex
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:

install: |
apt-get update -q -y
apt-get install -q -y automake libtool autotools-dev libseccomp-dev git make libcap-dev cmake pkg-config gcc wget go-md2man libsystemd-dev gperf clang-format libyajl-dev libprotobuf-c-dev
apt-get install -q -y automake libtool autotools-dev libseccomp-dev git make libcap-dev cmake pkg-config gcc wget go-md2man libsystemd-dev gperf clang-format libjansson-dev libprotobuf-c-dev
run: |
find $(pwd) -name '.git' -exec bash -c 'git config --global --add safe.directory ${0%/.git}' {} \;
Expand Down Expand Up @@ -91,7 +91,7 @@ jobs:
sudo add-apt-repository -y ppa:criu/ppa
# add-apt-repository runs apt-get update so we don't have to.
sudo apt-get install -q -y criu automake libtool autotools-dev libseccomp-dev git make libcap-dev cmake pkg-config gcc wget go-md2man libsystemd-dev gperf clang-format libyajl-dev containerd runc libasan6 libprotobuf-c-dev
sudo apt-get install -q -y criu automake libtool autotools-dev libseccomp-dev git make libcap-dev cmake pkg-config gcc wget go-md2man libsystemd-dev gperf clang-format libjansson-dev containerd runc libasan6 libprotobuf-c-dev
- name: run autogen.sh
run: |
Expand Down Expand Up @@ -203,7 +203,7 @@ jobs:
- name: install dependencies
run: |
sudo apt-get update -q -y
sudo apt-get install -q -y automake libtool autotools-dev libseccomp-dev git make libcap-dev cmake pkg-config gcc wget go-md2man libsystemd-dev gperf clang-format libyajl-dev libprotobuf-c-dev
sudo apt-get install -q -y automake libtool autotools-dev libseccomp-dev git make libcap-dev cmake pkg-config gcc wget go-md2man libsystemd-dev gperf clang-format libjansson-dev libprotobuf-c-dev
- uses: lumaxis/shellcheck-problem-matchers@v2
- name: shellcheck
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "libocispec"]
path = libocispec
url = https://github.com/containers/libocispec.git
branch = switch-to-jansson
6 changes: 0 additions & 6 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ libcrun_SOURCES = src/libcrun/utils.c \
src/libcrun/status.c \
src/libcrun/terminal.c

if HAVE_EMBEDDED_YAJL
maybe_libyajl.la = libocispec/yajl/libyajl.la
else
maybe_libyajl.la =
endif

libocispec/libocispec.la:
$(MAKE) $(AM_MAKEFLAGS) -C libocispec libocispec.la

Expand Down
10 changes: 8 additions & 2 deletions build-aux/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,19 @@ mkdir -p /nix
NIX_ARGS="--extra-experimental-features nix-command --print-build-logs --option cores $(nproc) --option max-jobs $(nproc)"

for ARCH in amd64 arm64 ppc64le riscv64 s390x; do
$RUNTIME run --init --rm $RUNTIME_EXTRA_ARGS --privileged -v /nix:/nix -v ${PWD}:${PWD} -w ${PWD} ${NIX_IMAGE} \
$RUNTIME run --init --rm $RUNTIME_EXTRA_ARGS --privileged \
-v /nix:/nix \
-v ${PWD}:${PWD} \
-w ${PWD} ${NIX_IMAGE} \
nix $NIX_ARGS build --max-jobs auto --file nix/default-${ARCH}.nix
cp ./result/bin/crun $OUTDIR/crun-$VERSION-linux-${ARCH}

rm -rf result

$RUNTIME run --init --rm $RUNTIME_EXTRA_ARGS --privileged -v /nix:/nix -v ${PWD}:${PWD} -w ${PWD} ${NIX_IMAGE} \
$RUNTIME run --init --rm $RUNTIME_EXTRA_ARGS --privileged \
-v /nix:/nix \
-v ${PWD}:${PWD} \
-w ${PWD} ${NIX_IMAGE} \
nix $NIX_ARGS build --max-jobs auto --file nix/default-${ARCH}.nix --arg enableSystemd false
cp ./result/bin/crun $OUTDIR/crun-$VERSION-linux-${ARCH}-disable-systemd

Expand Down
16 changes: 1 addition & 15 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,7 @@ esac
[enable_libcrun=true])
AM_CONDITIONAL([ENABLE_LIBCRUN], [test "x${enable_libcrun}" = xtrue])

dnl embedded yajl
AC_ARG_ENABLE(embedded-yajl,
AS_HELP_STRING([--enable-embedded-yajl], [Statically link a modified yajl version]),
[
case "${enableval}" in
yes) embedded_yajl=true ;;
no) embedded_yajl=false ;;
*) AC_MSG_ERROR(bad value ${enableval} for --enable-embedded-yajl) ;;
esac],[embedded_yajl=false])
AC_SEARCH_LIBS(json_object, [jansson], [AC_DEFINE([HAVE_JANSSON], 1, [Define if libjansson is available])], [AC_MSG_ERROR([*** libjansson headers not found])])

AC_ARG_ENABLE(dynload-libcrun,
AS_HELP_STRING([--enable-dynload-libcrun], [Dynamically load libcrun]),
Expand All @@ -75,12 +67,6 @@ case "${enableval}" in
esac],[dynload_libcrun=false])
AM_CONDITIONAL([DYNLOAD_LIBCRUN], [test x"$dynload_libcrun" = xtrue])

AM_CONDITIONAL([HAVE_EMBEDDED_YAJL], [test x"$embedded_yajl" = xtrue])
AM_COND_IF([HAVE_EMBEDDED_YAJL], [], [
AC_SEARCH_LIBS(yajl_tree_get, [yajl], [AC_DEFINE([HAVE_YAJL], 1, [Define if libyajl is available])], [AC_MSG_ERROR([*** libyajl headers not found])])
PKG_CHECK_MODULES([YAJL], [yajl >= 2.0.0])
])

dnl libcap
AC_ARG_ENABLE([caps],
AS_HELP_STRING([--disable-caps], [Ignore libcap and disable support]))
Expand Down
8 changes: 4 additions & 4 deletions lua/lua_crun.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,20 +658,20 @@ luacrun_ctx_update_container (lua_State *S)
const char *content = luaL_checkstring (S, 3);
luaL_checkstack (S, 2, NULL);

char errbuf[1024] = {};
yajl_val parsed_json = yajl_tree_parse (content, errbuf, sizeof (errbuf));
json_error_t *error;
json_t *parsed_json = json_loads (content, 0, error);
if (parsed_json == NULL)
{
lua_pushboolean (S, false);
lua_pushfstring (S, "cannot parse the data: \"%s\"", errbuf);
lua_pushfstring (S, "cannot parse the data: \"%s\"", error->text);
return 2;
}

struct parser_context parser_ctx = { .options = 0, .errfile = stderr };
runtime_spec_schema_config_schema_process *rt_spec_process;
parser_error p_err = NULL;
rt_spec_process = make_runtime_spec_schema_config_schema_process (parsed_json, &parser_ctx, &p_err);
yajl_tree_free (parsed_json);
json_decref (parsed_json);
if (rt_spec_process == NULL)
{
lua_pushboolean (S, false);
Expand Down
4 changes: 2 additions & 2 deletions nix/derivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ with pkgs; stdenv.mkDerivation {
libcap
libseccomp
libsystemd
yajl
jansson
] ++ lib.optionals enableCriu [ criu ];
configureFlags = [ "--enable-static" ] ++ lib.optional (!enableSystemd) [ "--disable-systemd" ];
prePatch = ''
export CFLAGS='-static -pthread'
export LDFLAGS='-s -w -static-libgcc -static'
export EXTRA_LDFLAGS='-s -w -linkmode external -extldflags "-static -lm"'
export CRUN_LDFLAGS='-all-static'
export LIBS='${lib.optionalString enableCriu "${criu}/lib/libcriu.a"} ${if stdenv.hostPlatform.isMusl then "${musl}/lib/libc.a ${musl}/lib/libpthread.a ${musl}/lib/librt.a" else "${glibc.static}/lib/libc.a ${glibc.static}/lib/libpthread.a ${glibc.static}/lib/librt.a"} ${lib.getLib libcap}/lib/libcap.a ${lib.getLib libseccomp}/lib/libseccomp.a ${lib.optionalString enableSystemd "${lib.getLib libsystemd}/lib/libsystemd.a"} ${yajl}/lib/libyajl.a'
export LIBS='${lib.optionalString enableCriu "${criu}/lib/libcriu.a"} ${if stdenv.hostPlatform.isMusl then "${musl}/lib/libc.a ${musl}/lib/libpthread.a ${musl}/lib/librt.a" else "${glibc.static}/lib/libc.a ${glibc.static}/lib/libpthread.a ${glibc.static}/lib/librt.a"} ${lib.getLib libcap}/lib/libcap.a ${lib.getLib libseccomp}/lib/libseccomp.a ${lib.optionalString enableSystemd "${lib.getLib libsystemd}/lib/libsystemd.a"} ${jansson}/lib/libjansson.a'
'';
buildPhase = ''
patchShebangs .
Expand Down
10 changes: 5 additions & 5 deletions nix/nixpkgs.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"url": "https://github.com/nixos/nixpkgs",
"rev": "ae320512e63598cd4b272c86b6875762e28e87da",
"date": "2024-12-13T11:04:07+01:00",
"path": "/nix/store/xr99s9lss6hc484ybvx2pcbml2rpswal-nixpkgs",
"sha256": "1gh14qf23b7lz273zkqrpidq4j39vqzyifsr4hrsrdzxqg6sl5g2",
"hash": "sha256-4hWqzcP9t6wzJFm76D/eaUiCW7wZzz+O+PSsIRwmAb4=",
"rev": "75ed009f22af3b8439d2f426a793f26e5cd4cf77",
"date": "2024-10-07T14:46:56+02:00",
"path": "/nix/store/kdqcyq2g9skx5y5vdh08wg5kfqrdgb0a-nixpkgs",
"sha256": "0vnxh80kbkc5lxdndbxr31pnvi0xj8shyyi8s75c58n3c0nfr6bc",
"hash": "sha256-bJnsLGDDosLK0Sh6DzWSHcRtbxi5r2Zbp4XNNQGC3W4=",
"fetchLFS": false,
"fetchSubmodules": false,
"deepClone": false,
Expand Down
6 changes: 1 addition & 5 deletions nix/overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ self: super:
libassuan = (static super.libassuan);
libgpgerror = (static super.libgpgerror);
libseccomp = (static super.libseccomp);
jansson = (static super.jansson);
libcap = (static super.libcap).overrideAttrs (x: {
postInstall = ''
mkdir -p "$doc/share/doc/${x.pname}-${x.version}"
Expand All @@ -30,11 +31,6 @@ self: super:
export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -Wno-error=format-overflow"
'';
});
yajl = super.yajl.overrideAttrs (x: {
cmakeFlags = (x.cmakeFlags or [ ]) ++ [
"-DBUILD_SHARED_LIBS=OFF"
];
});
zstd = super.zstd.overrideAttrs (x: {
cmakeFlags = x.cmakeFlags ++ [ "-DZSTD_BUILD_CONTRIB:BOOL=OFF" ];
preInstall = "";
Expand Down
14 changes: 7 additions & 7 deletions python/crun_python.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,15 @@ container_status (PyObject *self arg_unused, PyObject *args)
}

static int
load_json_file (yajl_val *out, const char *jsondata, struct parser_context *ctx arg_unused, libcrun_error_t *err)
load_json_file (json_t *out, const char *jsondata, struct parser_context *ctx arg_unused, libcrun_error_t *err)
{
char errbuf[1024];
json_error_t *error;

*err = NULL;

*out = yajl_tree_parse (jsondata, errbuf, sizeof (errbuf));
*out = json_loads (jsondata, 0, error);
if (*out == NULL)
return libcrun_make_error (err, 0, "cannot parse the data: `%s`", errbuf);
return libcrun_make_error (err, 0, "cannot parse the data: `%s`", error->text);

return 0;
}
Expand All @@ -380,7 +380,7 @@ container_update (PyObject *self arg_unused, PyObject *args)
libcrun_context_t *ctx;
char *id = NULL;
char *content = NULL;
yajl_val tree = NULL;
json_t *tree = NULL;
int ret;
parser_error parser_err = NULL;
struct parser_context parser_ctx = { 0, stderr };
Expand All @@ -393,12 +393,12 @@ container_update (PyObject *self arg_unused, PyObject *args)
if (ctx == NULL)
return NULL;

ret = load_json_file (&tree, content, &parser_ctx, &err);
ret = load_json_file (tree, content, &parser_ctx, &err);
if (UNLIKELY (ret < 0))
return set_error (&err);

process = make_runtime_spec_schema_config_schema_process (tree, &parser_ctx, &parser_err);
yajl_tree_free (tree);
json_decref (tree);
if (process == NULL)
{
cleanup_free char *msg = NULL;
Expand Down
4 changes: 1 addition & 3 deletions rpm/crun.spec
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ BuildRequires: libcap-devel
BuildRequires: libkrun-devel
%endif
BuildRequires: systemd-devel
%if %{defined system_yajl}
BuildRequires: yajl-devel
%endif
BuildRequires: jansson-devel
BuildRequires: libseccomp-devel
BuildRequires: python3-libmount
BuildRequires: libtool
Expand Down
2 changes: 0 additions & 2 deletions src/create.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ crun_command_create (struct crun_global_arguments *global_args, int argc, char *
container = libcrun_container_load_from_file (config_file, err);
if (container == NULL)
libcrun_fail_with_error (0, "error loading config.json");

libcrun_debug ("Using bundle: %s", bundle);
crun_context.bundle = bundle;
if (getenv ("LISTEN_FDS"))
{
Expand Down
2 changes: 1 addition & 1 deletion src/crun.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ print_version (FILE *stream, struct argp_state *state arg_unused)

libcrun_handler_manager_print_feature_tags (libcrun_get_handler_manager (), stream);

fprintf (stream, "+YAJL\n");
fprintf (stream, "+JANSSON\n");
}

static error_t
Expand Down
Loading

0 comments on commit a010d12

Please sign in to comment.