Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

### Added

- **openkal-posix 0.1.0。** 写在 POSIX C 库之上的 openkal 实现,为没有自身实现的系统服务;提供十五个接口(net、datagram、
prof、debug 不提供,名字不定义);声明 `requires = ["mcpp:c-abi"]`。新增成员 `tests/examples/openkal-posix`(Linux、macOS)。
- **openkal-musl 0.29.0 与 openkal-llvm-runtime 0.20.0,一次变更。** musl 的 `execvp`、`execvpe`、`execlp` 与 `posix_spawnp`
按 `kal_env_system` 所述系统的约定查找程序(Windows:PATH 以 `;` 分隔,无后缀的名字依次试 `PATHEXT` 各后缀);`link`、`linkat`
经 `kal_fs_hard_link` 实现;声明 `requires = ["mcpp:kernel-abi=openkal"]`;依赖改为 openkal 0.25 一族。llvm-runtime 依赖
Expand Down
1 change: 1 addition & 0 deletions mcpp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ members = [
"tests/examples/mcr",
"tests/examples/openkal",
"tests/examples/openkal-kit",
"tests/examples/openkal-posix",
"tests/examples/openkal-musl",
"tests/examples/openkal-platform",
"tests/examples/compiler-rt-builtins",
Expand Down
52 changes: 52 additions & 0 deletions pkgs/o/openkal-posix.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-- openkal-posix --- openkal written above a POSIX C library.
--
-- No descriptor-level `deps`: the source manifest names the openkal contract.
-- The implementation calls the system's own C library and states
-- `requires = ["mcpp:c-abi"]`, so it is placed above that C library and never
-- beneath one written above openkal. It provides fifteen of openkal's
-- interfaces; net, datagram, prof and debug are absent.
--
-- The package is listed for every platform because a descriptor's platform
-- table describes availability rather than applicability. A project selects
-- this implementation with a conditional dependency on the systems it serves,
-- and a project that selects it where no POSIX C library exists fails at
-- compile time, which is the correct place for that failure.
package = {
spec = "1",
namespace = "mcpplibs",
name = "openkal-posix",
description = "An implementation of openkal written above a POSIX C library, for the systems that have no implementation of their own",
licenses = {"Apache-2.0"},
repo = "https://github.com/mcpplibs/openkal-posix",
type = "package",

xpm = {
linux = {
["0.1.0"] = {
url = {
GLOBAL = "https://github.com/mcpplibs/openkal-posix/archive/refs/tags/0.1.0.tar.gz",
CN = "https://gitcode.com/mcpp-res/openkal-posix/releases/download/0.1.0/openkal-posix-0.1.0.tar.gz",
},
sha256 = "09878176d163b44675712f0bb285b87f9a8e0f9688b23c0aa4d0ab627f5ebeae",
},
},
macosx = {
["0.1.0"] = {
url = {
GLOBAL = "https://github.com/mcpplibs/openkal-posix/archive/refs/tags/0.1.0.tar.gz",
CN = "https://gitcode.com/mcpp-res/openkal-posix/releases/download/0.1.0/openkal-posix-0.1.0.tar.gz",
},
sha256 = "09878176d163b44675712f0bb285b87f9a8e0f9688b23c0aa4d0ab627f5ebeae",
},
},
windows = {
["0.1.0"] = {
url = {
GLOBAL = "https://github.com/mcpplibs/openkal-posix/archive/refs/tags/0.1.0.tar.gz",
CN = "https://gitcode.com/mcpp-res/openkal-posix/releases/download/0.1.0/openkal-posix-0.1.0.tar.gz",
},
sha256 = "09878176d163b44675712f0bb285b87f9a8e0f9688b23c0aa4d0ab627f5ebeae",
},
},
},
}
17 changes: 17 additions & 0 deletions tests/examples/openkal-posix/mcpp.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# openkal-posix test project: openkal above the system's own C library, on the
# systems this index's runners have one (Linux, macOS). The observation is of
# behaviour through the C surface (tests/kal.cpp): the interfaces it states, a
# write to a stream, the environment and the system's name, a file written and
# read back. On Windows nothing is named and the program observes nothing.
[package]
name = "openkal-posix-tests"
version = "0.1.0"

[target.'cfg(any(os = "linux", os = "macos"))'.dependencies.mcpplibs]
openkal = "0.25.0"
openkal-posix = "0.1.0"

# This member names mcpplibs packages, which the workspace root's single
# redirect does not carry, so it states its own.
[indices]
mcpplibs = { path = "../../.." }
43 changes: 43 additions & 0 deletions tests/examples/openkal-posix/tests/kal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// openkal-posix through the index, observed through the C surface.
#include <cstdio>
#include <cstring>
#if defined(__linux__) || defined(__APPLE__)
#include <openkal.h>

int main() {
int failures = 0;
auto check = [&](bool held, const char* what) {
if (!held) { std::printf("FAIL: %s\n", what); ++failures; }
};
const kal_u64 stated = kal_interfaces();
check((stated & KAL_IFACE_FS) && (stated & KAL_IFACE_PROCESS) && (stated & KAL_IFACE_TASK),
"the interfaces it provides are stated");
check(!(stated & KAL_IFACE_NET) && !(stated & KAL_IFACE_PROF), "and those it does not are not");
check(kal_stream_write(kal_stdout(), "openkal-posix\n", 14) == 14, "a stream is written");
char sys[32] = {};
const kal_intptr n = kal_env_system(sys, sizeof sys - 1);
check(n > 0, "the system is named");
kal_dir here{};
check(kal_fs_preopen_count() > 0 && kal_fs_preopen(0, &here, nullptr, 0, nullptr) == kal_ok,
"a directory is granted");
kal_file f{};
if (kal_fs_open(here, "okp-index.tmp", 13,
KAL_OPEN_WRITE | KAL_OPEN_CREATE | KAL_OPEN_TRUNCATE, &f) == kal_ok) {
kal_stream_write(kal_fs_stream(f), "abc", 3);
kal_fs_close_file(f);
char b[4] = {};
kal_file g{};
check(kal_fs_open(here, "okp-index.tmp", 13, KAL_OPEN_READ, &g) == kal_ok
&& kal_stream_read(kal_fs_stream(g), b, 3) == 3 && std::memcmp(b, "abc", 3) == 0,
"a file is written and read back");
if (g.h) kal_fs_close_file(g);
kal_fs_remove(here, "okp-index.tmp", 13);
} else {
check(false, "a file is created");
}
if (failures == 0) std::printf("openkal-posix: the C surface answers\n");
return failures == 0 ? 0 : 1;
}
#else
int main() { std::printf("openkal-posix: no POSIX C library is named on this system\n"); return 0; }
#endif
Loading