forked from openwrt/openwrt
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
APK (Alpine Package Keeper) is the package manager of Alpine Linux and has multiple advantages over OPKG. While Alpine uses APK version 2, this commit adds version 3 with a heavily optimised database structure and additional feature making it suitable for OpenWrt. This commit will be followed by many more to add APK build capabilities to the OpenWrt build system, firstly enabling side by side builds of APK and OPKG packages, later replacing OPKG entirely. Signed-off-by: Paul Spooren <[email protected]>
- Loading branch information
Showing
5 changed files
with
238 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
include $(TOPDIR)/rules.mk | ||
|
||
PKG_NAME:=apk | ||
PKG_RELEASE:=1 | ||
|
||
PKG_SOURCE_URL=https://gitlab.alpinelinux.org/alpine/apk-tools.git | ||
PKG_SOURCE_PROTO:=git | ||
PKG_SOURCE_DATE:=2024-03-16 | ||
PKG_SOURCE_VERSION:=f2f10d7e851ed3ff2a239c89c1a6a3612adbd63f | ||
PKG_MIRROR_HASH:=964bbc71462630a5418a20ccd3e725eb0b065a6232d4aee16db745d95a04c1ff | ||
|
||
|
||
# PKG_SOURCE_DATE:=2024-03-16 | ||
# PKG_SOURCE_VERSION:=f2f10d7e851ed3ff2a239c89c1a6a3612adbd63f | ||
# PKG_HASH:=964bbc71462630a5418a20ccd3e725eb0b065a6232d4aee16db745d95a04c1ff | ||
|
||
# # PKG_VERSION:=3.0.0_pre0 | ||
# PKG_SOURCE:=apk-tools-v$(PKG_SOURCE_VERSION).tar.gz | ||
# PKG_SOURCE_URL:=https://gitlab.alpinelinux.org/alpine/apk-tools/-/archive/$(PKG_SOURCE_VERSION) | ||
# PKG_BUILD_DIR:=$(BUILD_DIR)/apk-tools-$(PKG_SOURCE_VERSION) | ||
# HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/apk-tools-$(PKG_SOURCE_VERSION) | ||
|
||
PKG_MAINTAINER:=Paul Spooren <[email protected]> | ||
PKG_LICENSE:=GPL-2.0-only | ||
PKG_LICENSE_FILES:=LICENSE | ||
PKG_INSTALL:=1 | ||
|
||
HOST_BUILD_PREFIX:=$(STAGING_DIR_HOST) | ||
HOST_BUILD_DEPENDS:=lua/host | ||
PKG_BUILD_DEPENDS:=$(HOST_BUILD_DEPENDS) | ||
|
||
include $(INCLUDE_DIR)/package.mk | ||
include $(INCLUDE_DIR)/host-build.mk | ||
include $(INCLUDE_DIR)/meson.mk | ||
|
||
define Package/apk | ||
SECTION:=base | ||
CATEGORY:=Base system | ||
TITLE:=apk package manager | ||
DEPENDS:=+zlib +libopenssl @!arc | ||
URL:=$(PKG_SOURCE_URL) | ||
endef | ||
|
||
MESON_HOST_ARGS += \ | ||
-Dlua_version=5.1 \ | ||
-Dcompressed-help=false \ | ||
-Ddocs=disabled \ | ||
-Dzstd=False \ | ||
-Dversion=3.0.$(subst -,.,$(PKG_SOURCE_DATE))_pre0 | ||
|
||
MESON_ARGS += \ | ||
-Dlua_version=5.1 \ | ||
-Dcompressed-help=false \ | ||
-Ddocs=disabled \ | ||
-Dzstd=False \ | ||
-Dversion=3.0.$(subst -,.,$(PKG_SOURCE_DATE))_pre0 | ||
|
||
|
||
define Package/apk/install | ||
$(INSTALL_DIR) $(1)/lib/apk/db | ||
|
||
$(INSTALL_DIR) $(1)/usr/bin | ||
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/apk $(1)/usr/bin/apk | ||
|
||
$(INSTALL_DIR) $(1)/usr/lib | ||
$(CP) $(PKG_INSTALL_DIR)/usr/lib/libapk.so.* $(1)/usr/lib/ | ||
endef | ||
|
||
$(eval $(call BuildPackage,apk)) | ||
$(eval $(call HostBuild)) |
21 changes: 21 additions & 0 deletions
21
package/system/apk/patches/0001-openwrt-move-layer-db-to-temp-folder.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
From 9918c683fcc2f148328332d58d030ec5750a1473 Mon Sep 17 00:00:00 2001 | ||
From: Paul Spooren <[email protected]> | ||
Date: Sat, 19 Feb 2022 17:20:37 +0100 | ||
Subject: [PATCH 1/4] openwrt: move layer db to temp folder | ||
|
||
Signed-off-by: Paul Spooren <[email protected]> | ||
--- | ||
src/database.c | 2 +- | ||
1 file changed, 1 insertion(+), 1 deletion(-) | ||
|
||
--- a/src/database.c | ||
+++ b/src/database.c | ||
@@ -1604,7 +1604,7 @@ const char *apk_db_layer_name(int layer) | ||
{ | ||
switch (layer) { | ||
case APK_DB_LAYER_ROOT: return "lib/apk/db"; | ||
- case APK_DB_LAYER_UVOL: return "lib/apk/db-uvol"; | ||
+ case APK_DB_LAYER_UVOL: return "tmp/run/uvol/.meta/apk"; | ||
default: | ||
assert("invalid layer"); | ||
return 0; |
60 changes: 60 additions & 0 deletions
60
package/system/apk/patches/0002-change-naming-to-name-_-version-_-arch-.apk.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
From 091488909354d3f6aabb3fe98379be9025ad04c1 Mon Sep 17 00:00:00 2001 | ||
From: Paul Spooren <[email protected]> | ||
Date: Tue, 1 Feb 2022 09:30:20 +0100 | ||
Subject: [PATCH 2/4] change naming to <name>_<version>_<arch>.apk | ||
|
||
OpenWrt allows dashes in package names but no underlines. The current | ||
cleanup mechanism in the build system uses those underlines to find | ||
suiting packages to cleanup via `<pkgname>_*.apk`. | ||
|
||
Also add the package architecture to package filenames. This allows a | ||
better overview when downloading packages manually i.e. from a CI. | ||
|
||
Signed-off-by: Paul Spooren <[email protected]> | ||
--- | ||
src/apk_package.h | 4 ++-- | ||
src/app_mkpkg.c | 2 +- | ||
src/database.c | 6 ++++-- | ||
3 files changed, 7 insertions(+), 5 deletions(-) | ||
|
||
--- a/src/apk_package.h | ||
+++ b/src/apk_package.h | ||
@@ -103,8 +103,8 @@ APK_ARRAY(apk_package_array, struct apk_ | ||
#define APK_PROVIDER_FROM_PACKAGE(pkg) (struct apk_provider){(pkg),(pkg)->version} | ||
#define APK_PROVIDER_FROM_PROVIDES(pkg,p) (struct apk_provider){(pkg),(p)->version} | ||
|
||
-#define PKG_VER_FMT "%s-" BLOB_FMT | ||
-#define PKG_VER_PRINTF(pkg) pkg->name->name, BLOB_PRINTF(*pkg->version) | ||
+#define PKG_VER_FMT "%s_" BLOB_FMT "_" BLOB_FMT | ||
+#define PKG_VER_PRINTF(pkg) pkg->name->name, BLOB_PRINTF(*pkg->version), BLOB_PRINTF(*pkg->arch) | ||
#define PKG_FILE_FMT PKG_VER_FMT ".apk" | ||
#define PKG_FILE_PRINTF(pkg) PKG_VER_PRINTF(pkg) | ||
|
||
--- a/src/app_mkpkg.c | ||
+++ b/src/app_mkpkg.c | ||
@@ -283,7 +283,7 @@ static char *pkgi_filename(struct adb_ob | ||
{ | ||
apk_blob_t to = APK_BLOB_PTR_LEN(buf, n); | ||
apk_blob_push_blob(&to, adb_ro_blob(pkgi, ADBI_PI_NAME)); | ||
- apk_blob_push_blob(&to, APK_BLOB_STR("-")); | ||
+ apk_blob_push_blob(&to, APK_BLOB_STR("_")); | ||
apk_blob_push_blob(&to, adb_ro_blob(pkgi, ADBI_PI_VERSION)); | ||
apk_blob_push_blob(&to, APK_BLOB_STR(".apk")); | ||
apk_blob_push_blob(&to, APK_BLOB_PTR_LEN("", 1)); | ||
--- a/src/database.c | ||
+++ b/src/database.c | ||
@@ -589,10 +589,12 @@ struct apk_package *apk_db_pkg_add(struc | ||
|
||
static int apk_pkg_format_cache_pkg(apk_blob_t to, struct apk_package *pkg) | ||
{ | ||
- /* pkgname-1.0_alpha1.12345678.apk */ | ||
+ /* pkgname_1.0_alpha1.12345678.apk */ | ||
apk_blob_push_blob(&to, APK_BLOB_STR(pkg->name->name)); | ||
- apk_blob_push_blob(&to, APK_BLOB_STR("-")); | ||
+ apk_blob_push_blob(&to, APK_BLOB_STR("_")); | ||
apk_blob_push_blob(&to, *pkg->version); | ||
+ apk_blob_push_blob(&to, APK_BLOB_STR("_")); | ||
+ apk_blob_push_blob(&to, *pkg->arch); | ||
apk_blob_push_blob(&to, APK_BLOB_STR(".")); | ||
apk_blob_push_hexdump(&to, APK_BLOB_PTR_LEN((char *) pkg->csum.data, | ||
APK_CACHE_CSUM_BYTES)); |
56 changes: 56 additions & 0 deletions
56
package/system/apk/patches/0003-fix-macOS-compilation.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
From f3875f6ec84c3f7c704a8d9cc050e8a496893b1c Mon Sep 17 00:00:00 2001 | ||
From: Paul Spooren <[email protected]> | ||
Date: Sat, 16 Mar 2024 18:20:46 +0100 | ||
Subject: [PATCH] fix macOS compilation | ||
|
||
Pasting these bits together makes it work on macOS again. | ||
|
||
Signed-off-by: Paul Spooren <[email protected]> | ||
--- | ||
libfetch/common.h | 6 ++++++ | ||
src/adb.c | 12 ++++++++++++ | ||
2 files changed, 18 insertions(+) | ||
|
||
diff --git a/libfetch/common.h b/libfetch/common.h | ||
index 2c16bf7..42a8f0b 100644 | ||
--- a/libfetch/common.h | ||
+++ b/libfetch/common.h | ||
@@ -32,6 +32,12 @@ | ||
#ifndef _COMMON_H_INCLUDED | ||
#define _COMMON_H_INCLUDED | ||
|
||
+#ifndef SOCK_NONBLOCK | ||
+#include <fcntl.h> | ||
+#define SOCK_NONBLOCK O_NONBLOCK | ||
+#define SOCK_CLOEXEC O_CLOEXEC | ||
+#endif | ||
+ | ||
#define FTP_DEFAULT_PORT 21 | ||
#define HTTP_DEFAULT_PORT 80 | ||
#define HTTPS_DEFAULT_PORT 443 | ||
diff --git a/src/adb.c b/src/adb.c | ||
index fe614af..70ce75b 100644 | ||
--- a/src/adb.c | ||
+++ b/src/adb.c | ||
@@ -952,6 +952,18 @@ adb_val_t adb_wo_arr(struct adb_obj *o, unsigned i, struct adb_obj *no) | ||
return adb_wo_val(o, i, adb_w_arr(no)); | ||
} | ||
|
||
+#ifndef MUL_NO_OVERFLOW | ||
+#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4)) | ||
+#endif | ||
+void *reallocarray(void *optr, size_t nmemb, size_t size) { | ||
+ if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && | ||
+ nmemb > 0 && SIZE_MAX / nmemb < size) { | ||
+ errno = ENOMEM; | ||
+ return NULL; | ||
+ } | ||
+ return realloc(optr, size * nmemb); | ||
+} | ||
+ | ||
adb_val_t adb_wa_append(struct adb_obj *o, adb_val_t v) | ||
{ | ||
assert(o->schema->kind == ADB_KIND_ARRAY); | ||
-- | ||
2.44.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
diff --git a/meson.build b/meson.build | ||
index 6d33fc2..e60db9b 100644 | ||
--- a/meson.build | ||
+++ b/meson.build | ||
@@ -2,9 +2,15 @@ project( | ||
'apk-tools', | ||
['c'], | ||
default_options : ['c_std=gnu99', 'optimization=2'], | ||
- version: '3.0.0_pre0', | ||
meson_version: '>=0.52' | ||
) | ||
+ | ||
+version = get_option('version') | ||
+message(version) | ||
+ | ||
+conf_data = configuration_data() | ||
+conf_data.set('version', version) | ||
+ | ||
pkgc = import('pkgconfig') | ||
|
||
apk_confdir = get_option('sysconfdir') / 'apk' | ||
diff --git a/meson_options.txt b/meson_options.txt | ||
index 4ea9d83..a39332c 100644 | ||
--- a/meson_options.txt | ||
+++ b/meson_options.txt | ||
@@ -6,3 +6,5 @@ option('lua_version', description: 'Lua version to build against', type: 'string | ||
option('static_apk', description: 'Also build apk.static', type: 'boolean', value: false) | ||
option('arch_prefix', description: 'Define a custom arch prefix for default arch', type: 'string') | ||
option('zstd', description: 'Build with zstd support', type: 'boolean', value: true) | ||
+option('version', description: 'What version to store in binary', type: 'string', value: '3.0.0_pre0') | ||
+ |