mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-06-24 18:07:01 +00:00
Fix compilation on systems that dont have the memfd_create syscall
This commit is contained in:
parent
ac98b85157
commit
7750a461aa
3 changed files with 14 additions and 8 deletions
2
glfw/memfd.h
vendored
2
glfw/memfd.h
vendored
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#if defined(__linux__)
|
||||
#ifdef HAS_MEMFD_CREATE
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#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)
|
||||
{
|
||||
int ret;
|
||||
#if defined(__linux__)
|
||||
#ifdef HAS_MEMFD_CREATE
|
||||
int fd = memfd_create("glfw-shared", MFD_CLOEXEC | MFD_ALLOW_SEALING);
|
||||
if (fd < 0) return -1;
|
||||
// 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 sys
|
||||
import sysconfig
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
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):
|
||||
with tempfile.NamedTemporaryFile(suffix='.c') as f:
|
||||
src = src or 'int main(void) { return 0; }'
|
||||
f.write(src.encode('utf-8'))
|
||||
f.flush()
|
||||
return subprocess.Popen([cc] + list(cflags) + [f.name, '-o', os.devnull]).wait() == 0
|
||||
src = src or 'int main(void) { return 0; }'
|
||||
p = subprocess.Popen([cc] + list(cflags) + ['-x', 'c', '-o', os.devnull, '-'], stdin=subprocess.PIPE)
|
||||
p.stdin.write(src.encode('utf-8')), p.stdin.close()
|
||||
return p.wait() == 0
|
||||
|
||||
|
||||
def first_successful_compile(cc, *cflags, src=None):
|
||||
|
|
@ -171,6 +169,12 @@ def init_env(
|
|||
cc, ccver = cc_version()
|
||||
print('CC:', cc, ccver)
|
||||
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 = ''
|
||||
if ccver < (5, 2) and cc == 'gcc':
|
||||
missing_braces = '-Wno-missing-braces'
|
||||
|
|
@ -220,6 +224,8 @@ def init_env(
|
|||
cflags.append('-g3')
|
||||
ldflags.append('-lprofiler')
|
||||
ldpaths = []
|
||||
if has_memfd_create:
|
||||
cppflags.append('-DHAS_MEMFD_CREATE')
|
||||
return Env(cc, cppflags, cflags, ldflags, ldpaths=ldpaths)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue