Skip to content

Commit 649c9db

Browse files
committed
Build libbz2support with Ninja
1 parent 6e09b75 commit 649c9db

File tree

5 files changed

+127
-22
lines changed

5 files changed

+127
-22
lines changed

graalpython/com.oracle.graal.python.cext/setup.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -585,11 +585,6 @@ def stripped_object_filenames(*args, **kwargs):
585585
build_builtin_exts(capi_home)
586586
if WIN32:
587587
return # TODO: ...
588-
build_nativelibsupport(capi_home,
589-
subdir="bz2",
590-
libname="libbz2support",
591-
deps=[Bzip2Depedency("bz2", "bzip2==1.0.8", "BZIP2")],
592-
extra_link_args=["-Wl,-rpath,%s/lib/%s/" % (relative_rpath, SOABI)])
593588
build_nativelibsupport(capi_home,
594589
subdir="lzma",
595590
libname="liblzmasupport",

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/NFIBz2Support.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public String signature() {
155155
private NFIBz2Support(PythonContext context, NativeLibrary.NFIBackend backend, String noNativeAccessHelp) {
156156
if (context.isNativeAccessAllowed()) {
157157
this.pythonContext = context;
158-
this.typedNativeLib = NativeLibrary.create(SUPPORTING_NATIVE_LIB_NAME + context.getSoAbi().toJavaStringUncached(), Bz2NativeFunctions.values(),
158+
this.typedNativeLib = NativeLibrary.create(SUPPORTING_NATIVE_LIB_NAME + PythonContext.getSupportExt(), Bz2NativeFunctions.values(),
159159
backend, noNativeAccessHelp, false);
160160
this.available = true;
161161
} else {
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#
2+
# Copyright (c) 2023, Oracle and/or its affiliates.
3+
#
4+
# All rights reserved.
5+
#
6+
# Redistribution and use in source and binary forms, with or without modification, are
7+
# permitted provided that the following conditions are met:
8+
#
9+
# 1. Redistributions of source code must retain the above copyright notice, this list of
10+
# conditions and the following disclaimer.
11+
#
12+
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of
13+
# conditions and the following disclaimer in the documentation and/or other materials provided
14+
# with the distribution.
15+
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to
16+
# endorse or promote products derived from this software without specific prior written
17+
# permission.
18+
#
19+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
20+
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21+
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22+
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24+
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25+
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27+
# OF THE POSSIBILITY OF SUCH DAMAGE.
28+
#
29+
cmake_minimum_required(VERSION 3.22)
30+
project(python-libbz2)
31+
32+
function(require_var var)
33+
if (NOT ${var})
34+
message(FATAL_ERROR "${var} needs to be set")
35+
endif()
36+
endfunction()
37+
38+
require_var(BZIP2_SRC)
39+
40+
set(BZIP2_VERSION "${BZIP2_VERSION_MAJOR}.${BZIP2_VERSION_MINOR}.${BZIP2_VERSION_PATCH}")
41+
42+
message(VERBOSE "Building libbz2 version: ${BZIP2_VERSION}")
43+
44+
set(PACKAGE_NAME "bzip2")
45+
set(TARGET_BZIP2 "bz2")
46+
set(TARGET_BZIP2SUPPORT "bz2support")
47+
set(SRC_DIR "${BZIP2_SRC}/${PACKAGE_NAME}-${BZIP2_VERSION}")
48+
49+
add_library(${TARGET_BZIP2} STATIC)
50+
add_library(${TARGET_BZIP2SUPPORT} SHARED)
51+
52+
# we want '-fPIC' even for the static lib
53+
set_target_properties(${TARGET_BZIP2} PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
54+
55+
# preprocessor defines for all platforms
56+
target_compile_definitions(${TARGET_BZIP2} PRIVATE _FILE_OFFSET_BITS=64)
57+
target_compile_definitions(${TARGET_BZIP2SUPPORT} PRIVATE NDEBUG)
58+
59+
if(WIN32)
60+
target_compile_options(${TARGET_BZIP2} PRIVATE /Z7 /O2 /Wall)
61+
target_compile_options(${TARGET_BZIP2SUPPORT} PRIVATE /Z7 /O2 /WX)
62+
else()
63+
target_compile_options(${TARGET_BZIP2} PRIVATE -Wall -Winline -O2 -g)
64+
target_compile_options(${TARGET_BZIP2SUPPORT} PRIVATE -Wall -Werror -O3 -g)
65+
endif()
66+
67+
# don't install into the system but into the MX project's output dir
68+
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR})
69+
70+
# using glob patterns is not recommended: https://cmake.org/cmake/help/latest/command/file.html#glob
71+
target_sources(${TARGET_BZIP2} PRIVATE
72+
"${SRC_DIR}/bzlib.h"
73+
"${SRC_DIR}/blocksort.c"
74+
"${SRC_DIR}/huffman.c"
75+
"${SRC_DIR}/crctable.c"
76+
"${SRC_DIR}/randtable.c"
77+
"${SRC_DIR}/compress.c"
78+
"${SRC_DIR}/decompress.c"
79+
"${SRC_DIR}/bzlib.c"
80+
)
81+
target_sources(${TARGET_BZIP2SUPPORT} PRIVATE "src/bz2.c")
82+
target_include_directories(${TARGET_BZIP2SUPPORT} PRIVATE ${SRC_DIR})
83+
target_link_libraries(${TARGET_BZIP2SUPPORT} PRIVATE ${TARGET_BZIP2})
84+
85+
install(TARGETS ${TARGET_BZIP2SUPPORT} DESTINATION bin)

graalpython/com.oracle.graal.python.cext/bz2/bz2.c renamed to graalpython/python-libbz2/src/bz2.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,6 @@ static off_heap_buffer* bz_allocate_buffer(size_t items)
192192
return o;
193193
}
194194

195-
static off_heap_buffer* bz_create_copy_buffer(Byte *src, ssize_t len) {
196-
off_heap_buffer *dest = bz_allocate_buffer(len);
197-
if (dest && len > 0) {
198-
memcpy(dest->buf, src, len);
199-
}
200-
return dest;
201-
}
202-
203195
static void bz_release_buffer(off_heap_buffer *o) {
204196
if (!o) {
205197
return;
@@ -223,14 +215,6 @@ static void bz_release_buffer(off_heap_buffer *o) {
223215
free(o);
224216
}
225217

226-
static off_heap_buffer* bz_get_ref(off_heap_buffer* o) {
227-
if (o) {
228-
LOG_FINEST("off_heap_buffer(ref_count: %zu + 1)\n", o->ref_count);
229-
o->ref_count++;
230-
}
231-
return o;
232-
}
233-
234218
// nfi_function: name('createStream') map('bzst_stream*', 'POINTER')
235219
bzst_stream *bz_create_bzst_stream() {
236220
bzst_stream *bzst = (bzst_stream *) malloc(sizeof(bzst_stream));

mx.graalpython/suite.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,45 @@
493493
},
494494
},
495495

496+
"python-libbz2": {
497+
"subDir": "graalpython",
498+
"class" : "CMakeNinjaProject",
499+
"max_jobs" : "4",
500+
"vpath" : True,
501+
"ninja_targets" : ["<lib:bz2support>"],
502+
"ninja_install_targets" : ["install"],
503+
"results" : [
504+
"bin/<lib:bz2support>",
505+
],
506+
"cmakeConfig" : {
507+
"BZIP2_SRC": "<path:BZIP2>",
508+
"BZIP2_VERSION_MAJOR": "1",
509+
"BZIP2_VERSION_MINOR": "0",
510+
"BZIP2_VERSION_PATCH": "8",
511+
},
512+
"os_arch": {
513+
"windows": {
514+
"<others>": {
515+
"defaultBuild": False,
516+
},
517+
},
518+
"<others>": {
519+
"<others>": {
520+
"defaultBuild" : True,
521+
},
522+
},
523+
},
524+
"buildDependencies": [
525+
"sulong:SULONG_HOME",
526+
"sulong:SULONG_BOOTSTRAP_TOOLCHAIN",
527+
"BZIP2",
528+
],
529+
"buildEnv": {
530+
"ARCH": "<arch>",
531+
"OS": "<os>",
532+
},
533+
},
534+
496535
"com.oracle.graal.python.hpy.llvm": {
497536
"subDir": "graalpython",
498537
"class" : "CMakeNinjaProject",
@@ -820,6 +859,7 @@
820859
"com.oracle.graal.python.cext",
821860
"python-libzsupport",
822861
"python-libposix",
862+
"python-libbz2",
823863
"com.oracle.graal.python.hpy.llvm"
824864
],
825865
"os_arch": {
@@ -891,6 +931,7 @@
891931
"path": "*",
892932
},
893933
"dependency:com.oracle.graal.python.hpy.llvm/bin/*",
934+
"dependency:python-libbz2/bin/*",
894935
],
895936
"./lib/graalpy<graal_ver:major_minor>/modules/graalpy_virtualenv": [
896937
"file:graalpy_virtualenv/graalpy_virtualenv",

0 commit comments

Comments
 (0)