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
14 changes: 13 additions & 1 deletion ci.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
(import "ci/python-gate.libsonnet") +
(import "ci/python-bench.libsonnet") +
{
overlay: "40bd8048e1a6ba45494605955ffe748ae4db20be",
overlay: "30def35dbfc43256d57ad3b9b981d92718728e2a",
specVersion: "8",
// Until buildbot issues around CI tiers are resolved, we cannot use them
// tierConfig: self.tierConfig,
Expand All @@ -30,6 +30,9 @@
BISECT_EMAIL_FROM: "",
npm_config_registry: "",
RODINIA_DATASET_ZIP: "",
GRAALPY_GRAALOS_TOOLCHAIN_URL: "",
GRAALPY_GRAALOS_RUNTIME_URL: "",
GRAALPY_GRAALOS_ARTIFACT_BASE_URL: "",
BUILDBOT_COMMIT_SERVICE: "",
INTERNET_ACCESS_ENV: {},
},
Expand Down Expand Up @@ -330,6 +333,15 @@
"tox-example": gpgate_ee + require(GPYEE_NATIVE_STANDALONE) + platform_spec(no_jobs) + platform_spec({
"linux:amd64:jdk-latest" : tier3,
}),
"python-svm-graalos-standalone-build": gpgate_ee + internet_access_env + platform_spec(no_jobs) + platform_spec({
"linux:amd64:jdk-latest": tier3 + $.ol8 + task_spec({
environment +: {
GRAALPY_GRAALOS_TOOLCHAIN_URL: $.overlay_imports.GRAALPY_GRAALOS_TOOLCHAIN_URL,
GRAALPY_GRAALOS_RUNTIME_URL: $.overlay_imports.GRAALPY_GRAALOS_RUNTIME_URL,
GRAALPY_GRAALOS_ARTIFACT_BASE_URL: $.overlay_imports.GRAALPY_GRAALOS_ARTIFACT_BASE_URL,
},
}),
}),
},

local need_pgo = task_spec({runAfter: ["python-pgo-profile-post_merge-linux-amd64-jdk-latest"]}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public final class PythonResource implements InternalResource {
while ((ch = is.read()) != '\n' && ch != -1) {
// skip ABI version
}
PYTHON_ABIFLAGS = ch == -1 ? "" : new String(is.readAllBytes(), StandardCharsets.US_ASCII).strip();
String[] abiParts = ch == -1 ? new String[0] : new String(is.readAllBytes(), StandardCharsets.US_ASCII).split("\\R", 4);
PYTHON_ABIFLAGS = abiParts.length > 0 ? abiParts[0].strip() : "";
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# 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.

import sysconfig
import unittest


def test_graalos_sqlite3_native_extension_smoke():
soabi = sysconfig.get_config_var("SOABI") or ""
if "graalos" not in soabi:
raise unittest.SkipTest(f"requires GraalOS SOABI, got {soabi!r}")

import _sqlite3
import sqlite3

assert _sqlite3.sqlite_version
conn = sqlite3.connect(":memory:")
try:
conn.execute("create table values_for_sum(value integer)")
conn.executemany("insert into values_for_sum(value) values (?)", [(1,), (2,), (3,)])
assert conn.execute("select sum(value) from values_for_sum").fetchone()[0] == 6
finally:
conn.close()
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ 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;
public static final String GRAALPY_SOABI;
public static final String GRAALPY_EXT_SUFFIX;
public static final String GRAALPY_MULTIARCH;

/* Magic number used to mark pyc files */
public static final int MAGIC_NUMBER = 21000 + Compiler.BYTECODE_VERSION * 10;
Expand Down Expand Up @@ -252,9 +255,12 @@ public final class PythonLanguage extends TruffleLanguage<PythonContext> {
default:
RELEASE_LEVEL_STRING = tsLiteral("final");
}
String[] abiParts = new String(is.readAllBytes(), StandardCharsets.US_ASCII).split("\\R", 2);
String[] abiParts = new String(is.readAllBytes(), StandardCharsets.US_ASCII).split("\\R", 5);
GRAALPY_ABI_VERSION = abiParts[0].strip();
GRAALPY_ABIFLAGS = abiParts.length > 1 ? abiParts[1].strip() : "";
GRAALPY_SOABI = abiParts.length > 2 ? abiParts[2].strip() : "";
GRAALPY_EXT_SUFFIX = abiParts.length > 3 ? abiParts[3].strip() : "";
GRAALPY_MULTIARCH = abiParts.length > 4 ? abiParts[4].strip() : "";
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ public abstract static class ExtensionSuffixesNode extends PythonBuiltinNode {
@Specialization
Object run(
@Bind PythonLanguage language) {
return PFactory.createList(language, new Object[]{PythonContext.get(this).getSoAbi(), T_EXT_SO, T_EXT_PYD});
return PFactory.createList(language, new Object[]{PythonContext.get(this).getExtensionSuffix(), T_EXT_SO, T_EXT_PYD});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import static com.oracle.graal.python.builtins.modules.io.IONodes.T_R;
import static com.oracle.graal.python.builtins.modules.io.IONodes.T_W;
import static com.oracle.graal.python.builtins.modules.io.IONodes.T_WRITE;
import static com.oracle.graal.python.builtins.objects.str.StringUtils.cat;
import static com.oracle.graal.python.lib.PyTraceBackPrint.castToString;
import static com.oracle.graal.python.lib.PyTraceBackPrint.classNameNoDot;
import static com.oracle.graal.python.lib.PyTraceBackPrint.fileFlush;
Expand Down Expand Up @@ -119,7 +118,6 @@
import static com.oracle.graal.python.nodes.StringLiterals.T_BASE_PREFIX;
import static com.oracle.graal.python.nodes.StringLiterals.T_BIG;
import static com.oracle.graal.python.nodes.StringLiterals.T_COMMA;
import static com.oracle.graal.python.nodes.StringLiterals.T_DASH;
import static com.oracle.graal.python.nodes.StringLiterals.T_DOT;
import static com.oracle.graal.python.nodes.StringLiterals.T_EMPTY_STRING;
import static com.oracle.graal.python.nodes.StringLiterals.T_JAVA;
Expand Down Expand Up @@ -561,7 +559,7 @@ public void initialize(Python3Core core) {
if (os == PLATFORM_DARWIN) {
addBuiltinConstant("_framework", FRAMEWORK);
}
final TruffleString gmultiarch = cat(PythonUtils.getPythonArch(), T_DASH, osName);
final TruffleString gmultiarch = toTruffleStringUncached(PythonLanguage.GRAALPY_MULTIARCH);
addBuiltinConstant("__gmultiarch", gmultiarch);

// Initialized later in postInitialize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ public static Object loadCExtModule(Node location, PythonContext context, Module
CApiContext cApiContext = CApiContext.ensureCapiWasLoaded(location, context, spec.name, spec.path);
NativeLibrary library;

TruffleFile realPath = context.getPublicTruffleFileRelaxed(spec.path, context.getSoAbi()).getCanonicalFile();
TruffleFile realPath = context.getPublicTruffleFileRelaxed(spec.path, context.getExtensionSuffix()).getCanonicalFile();
String loadPath = cApiContext.nativeLibraryLocator.resolve(context, realPath);
getLogger(CApiContext.class).config(String.format("loading module %s (real path: %s) as native", spec.path, loadPath));
int dlopenFlags = context.getDlopenFlags();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public static void replicate(TruffleFile venvDirectory, PythonContext context, i
"but we are preparing %d copies. The extra copies will only be used if a different value " +
"of the system property %s is set.", MAX_CEXT_COPIES, count, J_MAX_CAPI_COPIES));
}
String suffix = context.getSoAbi().toJavaStringUncached();
String suffix = context.getExtensionSuffix().toJavaStringUncached();
TruffleFile capiLibrary = context.getPublicTruffleFileRelaxed(context.getCAPIHome()).resolve(PythonContext.getSupportLibName("python-" + J_NATIVE));
for (int i = 0; i < count; i++) {
// Relocate the C API library
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,12 @@

import static com.oracle.graal.python.PythonLanguage.getPythonOS;
import static com.oracle.graal.python.PythonLanguage.throwIfUnsupported;
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;
import static com.oracle.graal.python.builtins.modules.io.IONodes.T_FLUSH;
import static com.oracle.graal.python.builtins.objects.PythonAbstractObject.NATIVE_POINTER_FREED;
import static com.oracle.graal.python.builtins.objects.PythonAbstractObject.UNINITIALIZED;
import static com.oracle.graal.python.builtins.objects.str.StringUtils.cat;
import static com.oracle.graal.python.builtins.objects.thread.PThread.GRAALPYTHON_THREADS;
import static com.oracle.graal.python.nodes.BuiltinNames.T_PYEXPAT;
import static com.oracle.graal.python.nodes.BuiltinNames.T_SHA3;
Expand All @@ -55,11 +50,8 @@
import static com.oracle.graal.python.nodes.StringLiterals.J_EXT_DYLIB;
import static com.oracle.graal.python.nodes.StringLiterals.J_EXT_SO;
import static com.oracle.graal.python.nodes.StringLiterals.J_LIB_PREFIX;
import static com.oracle.graal.python.nodes.StringLiterals.T_DASH;
import static com.oracle.graal.python.nodes.StringLiterals.T_DOT;
import static com.oracle.graal.python.nodes.StringLiterals.T_EMPTY_STRING;
import static com.oracle.graal.python.nodes.StringLiterals.T_EXT_PYD;
import static com.oracle.graal.python.nodes.StringLiterals.T_EXT_SO;
import static com.oracle.graal.python.nodes.StringLiterals.T_JAVA;
import static com.oracle.graal.python.nodes.StringLiterals.T_NATIVE;
import static com.oracle.graal.python.nodes.StringLiterals.T_PATH;
Expand Down Expand Up @@ -151,7 +143,6 @@
import com.oracle.graal.python.nodes.SpecialAttributeNames;
import com.oracle.graal.python.nodes.SpecialMethodNames;
import com.oracle.graal.python.nodes.WriteUnraisableNode;
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromModuleNode;
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode;
import com.oracle.graal.python.nodes.call.CallNode;
Expand Down Expand Up @@ -807,7 +798,7 @@ public enum CApiState {
@CompilationFinal private boolean nativeAccessAllowed;
@CompilationFinal private NativeContext nativeContext;

private TruffleString soABI;
private TruffleString extensionSuffix;

private static final class GlobalInterpreterLock extends ReentrantLock {
private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -2932,31 +2923,11 @@ public boolean isFinalizing() {
}

@TruffleBoundary
public TruffleString getSoAbi() {
if (soABI == null) {
PythonModule sysModule = this.lookupBuiltinModule(T_SYS);
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);

// only use '.pyd' if we are on 'Win32-native'
TruffleString soExt;
if (getPythonOS() == PLATFORM_DARWIN) {
// not ".dylib", similar to CPython:
// https://github.com/python/cpython/issues/37510
soExt = T_EXT_SO;
} else if (getPythonOS() == PLATFORM_WIN32) {
soExt = T_EXT_PYD;
} else {
soExt = T_EXT_SO;
}

soABI = cat(T_DOT, cacheTag, abiFlags, T_DASH, T_NATIVE, T_DASH, multiArch, soExt);
public TruffleString getExtensionSuffix() {
if (extensionSuffix == null) {
extensionSuffix = toTruffleStringUncached(PythonLanguage.GRAALPY_EXT_SUFFIX);
}
return soABI;
return extensionSuffix;
}

public Thread getMainThread() {
Expand Down
11 changes: 10 additions & 1 deletion graalpython/graalpy-versions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,17 @@ endif()
if (NOT DEFINED GRAALPY_ABIFLAGS)
set(GRAALPY_ABIFLAGS "")
endif()
if (NOT DEFINED GRAALPY_EXT_SUFFIX)
message(FATAL_ERROR "GRAALPY_EXT_SUFFIX needs to be set")
endif()
if (NOT DEFINED GRAALPY_MULTIARCH)
message(FATAL_ERROR "GRAALPY_MULTIARCH needs to be set")
endif()
if (NOT DEFINED GRAALPY_SOABI)
message(FATAL_ERROR "GRAALPY_SOABI needs to be set")
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}\n${GRAALPY_ABIFLAGS}")
file(GENERATE OUTPUT "graalpy_versions" CONTENT "${GRAALPY_VER}\n${GRAALPY_ABIFLAGS}\n${GRAALPY_SOABI}\n${GRAALPY_EXT_SUFFIX}\n${GRAALPY_MULTIARCH}\n")
Loading
Loading