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
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def add_graalpython_core():
l = []
l.append("polyglot.arrow : polyglot.arrow = " + os.path.join(lib_graalpython, "modules/_polyglot_arrow.py"))
for name in [
"modules/_sysconfigdata",
"modules/_polyglot",
"modules/_polyglot_time",
]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.util.ArrayList;
Expand All @@ -66,6 +67,7 @@ public final class PythonResource implements InternalResource {
private static final int PYTHON_MINOR;
private static final int GRAALVM_MAJOR;
private static final int GRAALVM_MINOR;
private static final String PYTHON_ABIFLAGS;

/**
* The version generated at build time is stored in an ASCII-compatible way. Add build time, we
Expand All @@ -82,6 +84,13 @@ public final class PythonResource implements InternalResource {
is.read(); // skip python micro version
GRAALVM_MAJOR = is.read() - VERSION_BASE;
GRAALVM_MINOR = is.read() - VERSION_BASE;
is.read(); // skip GraalVM micro version
is.read(); // skip release level
int ch;
while ((ch = is.read()) != '\n' && ch != -1) {
// skip ABI version
}
PYTHON_ABIFLAGS = ch == -1 ? "" : new String(is.readAllBytes(), StandardCharsets.US_ASCII).strip();
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -117,7 +126,7 @@ public void unpackFiles(Env env, Path targetDirectory) throws IOException {
env.unpackResourceFiles(BASE_PATH.resolve(LIBPYTHON_FILES), targetDirectory.resolve("lib").resolve(pythonMajMin), BASE_PATH.resolve(LIBPYTHON), filter);
env.unpackResourceFiles(BASE_PATH.resolve(LIBGRAALPY_FILES), targetDirectory.resolve("lib").resolve("graalpy" + GRAALVM_MAJOR + "." + GRAALVM_MINOR), BASE_PATH.resolve(LIBGRAALPY),
filter);
env.unpackResourceFiles(BASE_PATH.resolve(INCLUDE_FILES), targetDirectory.resolve("include").resolve(pythonMajMin), BASE_PATH.resolve(INCLUDE), filter);
env.unpackResourceFiles(BASE_PATH.resolve(INCLUDE_FILES), targetDirectory.resolve("include").resolve(pythonMajMin + PYTHON_ABIFLAGS), BASE_PATH.resolve(INCLUDE), filter);
}
// ni files are in the same place on all platforms
env.unpackResourceFiles(BASE_PATH.resolve(NI_FILES), targetDirectory, BASE_PATH, filter);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2025, 2025, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -47,7 +47,12 @@ def test_sysconfig():
# must not fail


@unittest.skipIf(sys.implementation.name != 'graalpy', "GraalPy-only test")
def test_sysconfigdata():
# Maturin loads this directly, make sure the import works
import _sysconfigdata
def test_platform_sysconfigdata():
import importlib
import sysconfig
mod = importlib.import_module(sysconfig._get_sysconfigdata_name())
# These flags are parsed directly from the file by maturin
for key in ("ABIFLAGS", "EXT_SUFFIX", "SOABI", "VERSION"):
assert key in mod.build_time_vars
assert mod.build_time_vars["ABIFLAGS"] == sys.abiflags
assert sys.abiflags in sysconfig.get_config_var("INCLUDEPY")
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ public final class PythonLanguage extends TruffleLanguage<PythonContext> {

/** See {@code mx_graalpython.py:abi_version} */
public static final String GRAALPY_ABI_VERSION;
public static final String GRAALPY_ABIFLAGS;

/* Magic number used to mark pyc files */
public static final int MAGIC_NUMBER = 21000 + Compiler.BYTECODE_VERSION * 10;
Expand Down Expand Up @@ -252,7 +253,9 @@ public final class PythonLanguage extends TruffleLanguage<PythonContext> {
default:
RELEASE_LEVEL_STRING = tsLiteral("final");
}
GRAALPY_ABI_VERSION = new String(is.readAllBytes(), StandardCharsets.US_ASCII).strip();
String[] abiParts = new String(is.readAllBytes(), StandardCharsets.US_ASCII).split("\\R", 2);
GRAALPY_ABI_VERSION = abiParts[0].strip();
GRAALPY_ABIFLAGS = abiParts.length > 1 ? abiParts[1].strip() : "";
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ public final class SysModuleBuiltins extends PythonBuiltins {

public static final TruffleString T_CACHE_TAG = tsLiteral("cache_tag");
public static final TruffleString T__MULTIARCH = tsLiteral("_multiarch");
public static final TruffleString T_ABIFLAGS = tsLiteral("abiflags");

static {
String compile_time;
Expand Down Expand Up @@ -497,7 +498,7 @@ public void initialize(Python3Core core) {
StructSequence.initType(core, THREAD_INFO_DESC);
StructSequence.initType(core, UNRAISABLEHOOK_ARGS_DESC);

addBuiltinConstant("abiflags", T_EMPTY_STRING);
addBuiltinConstant(T_ABIFLAGS, toTruffleStringUncached(PythonLanguage.GRAALPY_ABIFLAGS));
addBuiltinConstant("byteorder", ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN ? T_LITTLE : T_BIG);
addBuiltinConstant("copyright", T_LICENSE);
addBuiltinConstant(T_MODULES, PFactory.createDict(language));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ private static final class Map {
private static final PythonFrozenModule __PHELLO___SPAM = new PythonFrozenModule("__PHELLO___SPAM", "__phello__.spam", false);
private static final PythonFrozenModule FROZEN_ONLY = new PythonFrozenModule("FROZEN_ONLY", null, false);
private static final PythonFrozenModule POLYGLOT_ARROW = new PythonFrozenModule("POLYGLOT_ARROW", null, false);
private static final PythonFrozenModule _SYSCONFIGDATA = new PythonFrozenModule("_SYSCONFIGDATA", null, false);
private static final PythonFrozenModule _POLYGLOT = new PythonFrozenModule("_POLYGLOT", null, false);
private static final PythonFrozenModule _POLYGLOT_TIME = new PythonFrozenModule("_POLYGLOT_TIME", null, false);
private static final PythonFrozenModule GRAALPY___GRAALPYTHON__ = new PythonFrozenModule("GRAALPY___GRAALPYTHON__", null, false);
Expand Down Expand Up @@ -223,8 +222,6 @@ public static final PythonFrozenModule lookup(String name) {
return Map.FROZEN_ONLY;
case "polyglot.arrow":
return Map.POLYGLOT_ARROW;
case "_sysconfigdata":
return Map._SYSCONFIGDATA;
case "_polyglot":
return Map._POLYGLOT;
case "_polyglot_time":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static com.oracle.graal.python.annotations.PythonOS.PLATFORM_DARWIN;
import static com.oracle.graal.python.annotations.PythonOS.PLATFORM_WIN32;
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.SystemError;
import static com.oracle.graal.python.builtins.modules.SysModuleBuiltins.T_ABIFLAGS;
import static com.oracle.graal.python.builtins.modules.SysModuleBuiltins.T_CACHE_TAG;
import static com.oracle.graal.python.builtins.modules.SysModuleBuiltins.T__MULTIARCH;
import static com.oracle.graal.python.builtins.modules.io.IONodes.T_CLOSED;
Expand Down Expand Up @@ -2918,6 +2919,7 @@ public TruffleString getSoAbi() {
Object implementationObj = ReadAttributeFromModuleNode.getUncached().execute(sysModule, T_IMPLEMENTATION);
// sys.implementation.cache_tag
TruffleString cacheTag = (TruffleString) PyObjectGetAttr.executeUncached(implementationObj, T_CACHE_TAG);
TruffleString abiFlags = (TruffleString) ReadAttributeFromModuleNode.getUncached().execute(sysModule, T_ABIFLAGS);
// sys.implementation._multiarch
TruffleString multiArch = (TruffleString) PyObjectGetAttr.executeUncached(implementationObj, T__MULTIARCH);

Expand All @@ -2933,7 +2935,7 @@ public TruffleString getSoAbi() {
soExt = T_EXT_SO;
}

soABI = cat(T_DOT, cacheTag, T_DASH, T_NATIVE, T_DASH, multiArch, soExt);
soABI = cat(T_DOT, cacheTag, abiFlags, T_DASH, T_NATIVE, T_DASH, multiArch, soExt);
}
return soABI;
}
Expand Down
112 changes: 112 additions & 0 deletions graalpython/graalpy-pyconfig/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,23 @@ include(CheckSymbolExists)
include(CheckIncludeFile)
include (TestBigEndian)

if(NOT DEFINED GRAALPY_SYSCONFIGDATA_NAME)
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(GRAALPY_SYSCONFIG_PLATFORM "darwin")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(GRAALPY_SYSCONFIG_PLATFORM "win32")
else()
set(GRAALPY_SYSCONFIG_PLATFORM "linux")
endif()

string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" GRAALPY_SYSCONFIG_ARCH)
if(GRAALPY_SYSCONFIG_ARCH STREQUAL "amd64")
set(GRAALPY_SYSCONFIG_ARCH "x86_64")
endif()
set(GRAALPY_SYSCONFIG_MULTIARCH "${GRAALPY_SYSCONFIG_ARCH}-${GRAALPY_SYSCONFIG_PLATFORM}")
set(GRAALPY_SYSCONFIGDATA_NAME "_sysconfigdata__${GRAALPY_SYSCONFIG_PLATFORM}_${GRAALPY_SYSCONFIG_MULTIARCH}")
endif()

test_big_endian(IS_BIG_ENDIAN)

set(CMAKE_REQUIRED_LINK_OPTIONS "-lm")
Expand Down Expand Up @@ -70,4 +87,99 @@ else()
set(DOUBLE_IS_LITTLE_ENDIAN_IEEE754 1)
endif()

function(graalpy_sysconfig_value name default_value)
if(DEFINED ENV{GRAALPY_SYSCONFIG_${name}})
set(GRAALPY_SYSCONFIG_${name} "$ENV{GRAALPY_SYSCONFIG_${name}}" PARENT_SCOPE)
else()
set(GRAALPY_SYSCONFIG_${name} "${default_value}" PARENT_SCOPE)
endif()
endfunction()

function(graalpy_sysconfig_empty name)
graalpy_sysconfig_value("${name}" "")
endfunction()

function(graalpy_sysconfig_env_value name)
if(DEFINED ENV{GRAALPY_SYSCONFIG_${name}})
set(GRAALPY_SYSCONFIG_${name} "$ENV{GRAALPY_SYSCONFIG_${name}}" PARENT_SCOPE)
else()
set(GRAALPY_SYSCONFIG_${name} "" PARENT_SCOPE)
endif()
endfunction()

function(graalpy_sysconfig_python_string name)
set(value "${${name}}")
string(REPLACE "\\" "\\\\" value "${value}")
string(REPLACE "\"" "\\\"" value "${value}")
string(REPLACE "\n" "\\n" value "${value}")
string(REPLACE "\r" "\\r" value "${value}")
set(${name}_PYTHON_STRING "${value}" PARENT_SCOPE)
endfunction()

graalpy_sysconfig_value("OPT" "-DNDEBUG")
graalpy_sysconfig_value("ARFLAGS" "rc")
graalpy_sysconfig_value("USE_GNU_SOURCE" "-D_GNU_SOURCE=1")
set(GRAALPY_SYSCONFIG_CFLAGS_DEFAULT_VALUE "${GRAALPY_SYSCONFIG_OPT}")
if(WIN32)
set(GRAALPY_SYSCONFIG_CFLAGS_DEFAULT_VALUE "${GRAALPY_SYSCONFIG_CFLAGS_DEFAULT_VALUE} -DMS_WINDOWS -DPy_ENABLE_SHARED -DHAVE_DECLSPEC_DLL")
endif()
graalpy_sysconfig_value("CFLAGS_DEFAULT" "${GRAALPY_SYSCONFIG_CFLAGS_DEFAULT_VALUE}")
graalpy_sysconfig_value("CFLAGS" "${GRAALPY_SYSCONFIG_CFLAGS_DEFAULT} ${GRAALPY_SYSCONFIG_USE_GNU_SOURCE}")
graalpy_sysconfig_env_value("AR")
graalpy_sysconfig_env_value("CC")
graalpy_sysconfig_env_value("CXX")
graalpy_sysconfig_env_value("LD")
graalpy_sysconfig_env_value("NM")
graalpy_sysconfig_env_value("RANLIB")
if(APPLE)
graalpy_sysconfig_value("LDFLAGS" "-bundle -undefined dynamic_lookup")
graalpy_sysconfig_value("MACOSX_DEPLOYMENT_TARGET" "11")
else()
graalpy_sysconfig_empty("LDFLAGS")
graalpy_sysconfig_empty("MACOSX_DEPLOYMENT_TARGET")
endif()
if(WIN32)
graalpy_sysconfig_empty("CCSHARED")
graalpy_sysconfig_value("SHLIB_SUFFIX" ".pyd")
graalpy_sysconfig_value("EXE" ".exe")
else()
graalpy_sysconfig_value("CCSHARED" "-fPIC")
graalpy_sysconfig_value("SHLIB_SUFFIX" ".so")
graalpy_sysconfig_empty("EXE")
endif()
graalpy_sysconfig_env_value("LDCXXSHARED")
graalpy_sysconfig_env_value("LDSHARED")
graalpy_sysconfig_value("LDLIBRARY" "libpython.${GRAALPY_SYSCONFIG_SOABI}${GRAALPY_SYSCONFIG_SHLIB_SUFFIX}")

set(GRAALPY_SYSCONFIG_STRING_NAMES
ABIFLAGS
AR
ARFLAGS
CC
CCSHARED
CFLAGS
CFLAGS_DEFAULT
CXX
EXE
EXT_SUFFIX
LD
LDCXXSHARED
LDLIBRARY
LDFLAGS
LDSHARED
MACOSX_DEPLOYMENT_TARGET
MULTIARCH
NM
OPT
RANLIB
SHLIB_SUFFIX
SOABI
USE_GNU_SOURCE
VERSION
)
foreach(name IN LISTS GRAALPY_SYSCONFIG_STRING_NAMES)
graalpy_sysconfig_python_string("GRAALPY_SYSCONFIG_${name}")
endforeach()

configure_file("pyconfig_template.h" "pyconfig.h" @ONLY)
configure_file("_sysconfigdata_template.py" "${GRAALPY_SYSCONFIGDATA_NAME}.py" @ONLY)
80 changes: 80 additions & 0 deletions graalpython/graalpy-pyconfig/_sysconfigdata_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# The Universal Permissive License (UPL), Version 1.0
#
# Subject to the condition set forth below, permission is hereby granted to any
# person obtaining a copy of this software, associated documentation and/or
# data (collectively the "Software"), free of charge and under any and all
# copyright rights in the Software, and any and all patent rights owned or
# freely licensable by each licensor hereunder covering either (i) the
# unmodified Software as contributed to or provided by such licensor, or (ii)
# the Larger Works (as defined below), to deal in both
#
# (a) the Software, and
#
# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
# one is included with the Software each a "Larger Work" to which the Software
# is contributed by such licensors),
#
# without restriction, including without limitation the rights to copy, create
# derivative works of, display, perform, and distribute the Software and make,
# use, sell, offer for sale, import, export, have made, and have sold the
# Software and the Larger Work(s), and to sublicense the foregoing rights on
# either these or other terms.
#
# This license is subject to the following condition:
#
# The above copyright notice and either this complete permission notice or at a
# minimum a reference to the UPL must be included in all copies or substantial
# portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# system configuration generated and used by the sysconfig module

build_time_vars = {
"ABIFLAGS": "@GRAALPY_SYSCONFIG_ABIFLAGS_PYTHON_STRING@",
"ARFLAGS": "@GRAALPY_SYSCONFIG_ARFLAGS_PYTHON_STRING@",
"CCSHARED": "@GRAALPY_SYSCONFIG_CCSHARED_PYTHON_STRING@",
"CFLAGS": "@GRAALPY_SYSCONFIG_CFLAGS_PYTHON_STRING@",
"CFLAGS_DEFAULT": "@GRAALPY_SYSCONFIG_CFLAGS_DEFAULT_PYTHON_STRING@",
"EXE": "@GRAALPY_SYSCONFIG_EXE_PYTHON_STRING@",
"EXT_SUFFIX": "@GRAALPY_SYSCONFIG_EXT_SUFFIX_PYTHON_STRING@",
"LDLIBRARY": "@GRAALPY_SYSCONFIG_LDLIBRARY_PYTHON_STRING@",
"LDFLAGS": "@GRAALPY_SYSCONFIG_LDFLAGS_PYTHON_STRING@",
"LIBPYTHON": "",
"LIBS": "",
"MACOSX_DEPLOYMENT_TARGET": "@GRAALPY_SYSCONFIG_MACOSX_DEPLOYMENT_TARGET_PYTHON_STRING@",
"MULTIARCH": "@GRAALPY_SYSCONFIG_MULTIARCH_PYTHON_STRING@",
"OPT": "@GRAALPY_SYSCONFIG_OPT_PYTHON_STRING@",
"Py_GIL_DISABLED": @GRAALPY_SYSCONFIG_GIL_DISABLED@,
"Py_DEBUG": 0,
"Py_ENABLE_SHARED": 0,
"Py_HASH_ALGORITHM": 0,
"SHLIB_SUFFIX": "@GRAALPY_SYSCONFIG_SHLIB_SUFFIX_PYTHON_STRING@",
"SO": "@GRAALPY_SYSCONFIG_EXT_SUFFIX_PYTHON_STRING@",
"SOABI": "@GRAALPY_SYSCONFIG_SOABI_PYTHON_STRING@",
"SYSLIBS": "",
"USE_GNU_SOURCE": "@GRAALPY_SYSCONFIG_USE_GNU_SOURCE_PYTHON_STRING@",
"VERSION": "@GRAALPY_SYSCONFIG_VERSION_PYTHON_STRING@",
}

for _key, _value in {
"AR": "@GRAALPY_SYSCONFIG_AR_PYTHON_STRING@",
"CC": "@GRAALPY_SYSCONFIG_CC_PYTHON_STRING@",
"CXX": "@GRAALPY_SYSCONFIG_CXX_PYTHON_STRING@",
"LD": "@GRAALPY_SYSCONFIG_LD_PYTHON_STRING@",
"LDCXXSHARED": "@GRAALPY_SYSCONFIG_LDCXXSHARED_PYTHON_STRING@",
"LDSHARED": "@GRAALPY_SYSCONFIG_LDSHARED_PYTHON_STRING@",
"NM": "@GRAALPY_SYSCONFIG_NM_PYTHON_STRING@",
"RANLIB": "@GRAALPY_SYSCONFIG_RANLIB_PYTHON_STRING@",
}.items():
if _value:
build_time_vars[_key] = _value
5 changes: 4 additions & 1 deletion graalpython/graalpy-versions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ project(graalpy-versions LANGUAGES NONE)
if (NOT DEFINED GRAALPY_VER)
message(FATAL_ERROR "GRAALPY_VER needs to be set")
endif()
if (NOT DEFINED GRAALPY_ABIFLAGS)
set(GRAALPY_ABIFLAGS "")
endif()

# Generates file 'graalpy_versions' with the given content.
# The file will be created if it does not exist and will only be updated if the
# content changes.
file(GENERATE OUTPUT "graalpy_versions" CONTENT "${GRAALPY_VER}")
file(GENERATE OUTPUT "graalpy_versions" CONTENT "${GRAALPY_VER}\n${GRAALPY_ABIFLAGS}")
Loading
Loading