mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-25 00:12:56 +00:00
openbsd.{compat,compatHook}: init
OpenBSD does not provide a compatibility library for running build tools on other OSes, but we still need one. `openbsd.compat` inspired by the `freebsd.compat` package and provides a header-only compatibility layer that can be used across multiple openbsd build packages. The source is included in the nixpkgs tree because it functions similarly to per-package patches. `openbsd.compatHook` provides a build hook that can be added into `extraNativeBuildInputs` to include `compat` in the library search path as a system library.
This commit is contained in:
parent
51a07b20cd
commit
d48f526db3
30
pkgs/os-specific/bsd/openbsd/pkgs/compat/include/err.h
Normal file
30
pkgs/os-specific/bsd/openbsd/pkgs/compat/include/err.h
Normal file
@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
#include_next <err.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
static inline void __attribute__((__format__(printf, 3, 4)))
|
||||
errc(int eval, int code, const char *fmt, ...) {
|
||||
// verr uses the error code from errno
|
||||
// No need to keep the old value since this is noreturn anyway
|
||||
errno = code;
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
verr(eval, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
static inline void __attribute__((__format__(printf, 2, 3)))
|
||||
warnc(int code, const char *fmt, ...) {
|
||||
// verr uses the error code from errno
|
||||
int old_errno = errno;
|
||||
errno = code;
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vwarn(fmt, args);
|
||||
va_end(args);
|
||||
|
||||
errno = old_errno;
|
||||
}
|
6
pkgs/os-specific/bsd/openbsd/pkgs/compat/include/fcntl.h
Normal file
6
pkgs/os-specific/bsd/openbsd/pkgs/compat/include/fcntl.h
Normal file
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
#include_next <fcntl.h>
|
||||
|
||||
// Linux doesn't let you lock during open, make these do nothing
|
||||
#define O_EXLOCK 0
|
||||
#define O_SHLOCK 0
|
@ -0,0 +1,4 @@
|
||||
#include_next <sys/cdefs.h>
|
||||
|
||||
#define __packed __attribute__((__packed__))
|
||||
#define __aligned(x) __attribute__((__aligned__(x)))
|
@ -0,0 +1 @@
|
||||
#include <dirent.h>
|
@ -0,0 +1,2 @@
|
||||
// Seems to be the only header for htonl
|
||||
#include <netinet/in.h>
|
10
pkgs/os-specific/bsd/openbsd/pkgs/compat/include/sys/types.h
Normal file
10
pkgs/os-specific/bsd/openbsd/pkgs/compat/include/sys/types.h
Normal file
@ -0,0 +1,10 @@
|
||||
#include_next <sys/types.h>
|
||||
|
||||
// for makedev, major, minor
|
||||
#include <sys/sysmacros.h>
|
||||
|
||||
// For htonl, htons, etc.
|
||||
#include <arpa/inet.h>
|
||||
|
||||
// for uint32_t etc.
|
||||
#include <stdint.h>
|
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include_next <unistd.h>
|
||||
|
||||
// Reimplementing pledge and unvail with seccomp would be a pain,
|
||||
// so do nothing but claim they succeeded
|
||||
static int pledge(const char *, const char *) { return 0; }
|
||||
static int unveil(const char *, const char *) { return 0; }
|
1
pkgs/os-specific/bsd/openbsd/pkgs/compat/include/util.h
Normal file
1
pkgs/os-specific/bsd/openbsd/pkgs/compat/include/util.h
Normal file
@ -0,0 +1 @@
|
||||
#include <sys/types.h>
|
16
pkgs/os-specific/bsd/openbsd/pkgs/compat/package.nix
Normal file
16
pkgs/os-specific/bsd/openbsd/pkgs/compat/package.nix
Normal file
@ -0,0 +1,16 @@
|
||||
{ runCommand, lib }:
|
||||
|
||||
runCommand "openbsd-compat"
|
||||
{
|
||||
include = ./include;
|
||||
|
||||
meta = with lib; {
|
||||
description = "A header-only library for running OpenBSD software on Linux";
|
||||
platforms = lib.platforms.linux;
|
||||
maintainers = with lib.maintainers; [ artemist ];
|
||||
};
|
||||
}
|
||||
''
|
||||
mkdir -p $out
|
||||
cp -R $include $out/include
|
||||
''
|
13
pkgs/os-specific/bsd/openbsd/pkgs/compatHook/package.nix
Normal file
13
pkgs/os-specific/bsd/openbsd/pkgs/compatHook/package.nix
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
stdenv,
|
||||
makeSetupHook,
|
||||
compat,
|
||||
}:
|
||||
|
||||
makeSetupHook {
|
||||
name = "openbsd-compat-hook";
|
||||
substitutions = {
|
||||
inherit compat;
|
||||
inherit (stdenv.cc) suffixSalt;
|
||||
};
|
||||
} ./setup-hook.sh
|
@ -0,0 +1,5 @@
|
||||
useOpenBSDCompat () {
|
||||
export NIX_CFLAGS_COMPILE_@suffixSalt@+="-I@compat@/include"
|
||||
}
|
||||
|
||||
postHooks+=(useOpenBSDCompat)
|
Loading…
Reference in New Issue
Block a user