mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-28 03:01:57 +02:00
Fix compilation on systems that dont have the memfd_create syscall
This commit is contained in:
2
glfw/memfd.h
vendored
2
glfw/memfd.h
vendored
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#if defined(__linux__)
|
#ifdef HAS_MEMFD_CREATE
|
||||||
|
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|||||||
2
glfw/wl_window.c
vendored
2
glfw/wl_window.c
vendored
@@ -140,7 +140,7 @@ static int
|
|||||||
createAnonymousFile(off_t size)
|
createAnonymousFile(off_t size)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
#if defined(__linux__)
|
#ifdef HAS_MEMFD_CREATE
|
||||||
int fd = memfd_create("glfw-shared", MFD_CLOEXEC | MFD_ALLOW_SEALING);
|
int fd = memfd_create("glfw-shared", MFD_CLOEXEC | MFD_ALLOW_SEALING);
|
||||||
if (fd < 0) return -1;
|
if (fd < 0) return -1;
|
||||||
// We can add this seal before calling posix_fallocate(), as the file
|
// We can add this seal before calling posix_fallocate(), as the file
|
||||||
|
|||||||
18
setup.py
18
setup.py
@@ -13,7 +13,6 @@ import shutil
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import sysconfig
|
import sysconfig
|
||||||
import tempfile
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
base = os.path.dirname(os.path.abspath(__file__))
|
base = os.path.dirname(os.path.abspath(__file__))
|
||||||
@@ -141,11 +140,10 @@ def get_sanitize_args(cc, ccver):
|
|||||||
|
|
||||||
|
|
||||||
def test_compile(cc, *cflags, src=None):
|
def test_compile(cc, *cflags, src=None):
|
||||||
with tempfile.NamedTemporaryFile(suffix='.c') as f:
|
src = src or 'int main(void) { return 0; }'
|
||||||
src = src or 'int main(void) { return 0; }'
|
p = subprocess.Popen([cc] + list(cflags) + ['-x', 'c', '-o', os.devnull, '-'], stdin=subprocess.PIPE)
|
||||||
f.write(src.encode('utf-8'))
|
p.stdin.write(src.encode('utf-8')), p.stdin.close()
|
||||||
f.flush()
|
return p.wait() == 0
|
||||||
return subprocess.Popen([cc] + list(cflags) + [f.name, '-o', os.devnull]).wait() == 0
|
|
||||||
|
|
||||||
|
|
||||||
def first_successful_compile(cc, *cflags, src=None):
|
def first_successful_compile(cc, *cflags, src=None):
|
||||||
@@ -171,6 +169,12 @@ def init_env(
|
|||||||
cc, ccver = cc_version()
|
cc, ccver = cc_version()
|
||||||
print('CC:', cc, ccver)
|
print('CC:', cc, ccver)
|
||||||
stack_protector = first_successful_compile(cc, '-fstack-protector-strong', '-fstack-protector')
|
stack_protector = first_successful_compile(cc, '-fstack-protector-strong', '-fstack-protector')
|
||||||
|
has_memfd_create = test_compile(cc, '-Werror', src='''#define _GNU_SOURCE
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/syscall.h>
|
||||||
|
int main(void) {
|
||||||
|
return syscall(__NR_memfd_create, "test", 0);
|
||||||
|
}''')
|
||||||
missing_braces = ''
|
missing_braces = ''
|
||||||
if ccver < (5, 2) and cc == 'gcc':
|
if ccver < (5, 2) and cc == 'gcc':
|
||||||
missing_braces = '-Wno-missing-braces'
|
missing_braces = '-Wno-missing-braces'
|
||||||
@@ -220,6 +224,8 @@ def init_env(
|
|||||||
cflags.append('-g3')
|
cflags.append('-g3')
|
||||||
ldflags.append('-lprofiler')
|
ldflags.append('-lprofiler')
|
||||||
ldpaths = []
|
ldpaths = []
|
||||||
|
if has_memfd_create:
|
||||||
|
cppflags.append('-DHAS_MEMFD_CREATE')
|
||||||
return Env(cc, cppflags, cflags, ldflags, ldpaths=ldpaths)
|
return Env(cc, cppflags, cflags, ldflags, ldpaths=ldpaths)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user