Skip to content

Commit 4395574

Browse files
committed
Building xz from source
config.h and Makefile added
1 parent a7cc903 commit 4395574

File tree

4 files changed

+322
-1
lines changed

4 files changed

+322
-1
lines changed
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
# Copyright (c) 2021, Oracle and/or its affiliates.
2+
#
3+
# The Universal Permissive License (UPL), Version 1.0
4+
#
5+
# Subject to the condition set forth below, permission is hereby granted to any
6+
# person obtaining a copy of this software, associated documentation and/or data
7+
# (collectively the "Software"), free of charge and under any and all copyright
8+
# rights in the Software, and any and all patent rights owned or freely
9+
# licensable by each licensor hereunder covering either (i) the unmodified
10+
# Software as contributed to or provided by such licensor, or (ii) the Larger
11+
# Works (as defined below), to deal in both
12+
#
13+
# (a) the Software, and
14+
# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
15+
# one is included with the Software (each a "Larger Work" to which the
16+
# Software is contributed by such licensors),
17+
#
18+
# without restriction, including without limitation the rights to copy, create
19+
# derivative works of, display, perform, and distribute the Software and make,
20+
# use, sell, offer for sale, import, export, have made, and have sold the
21+
# Software and the Larger Work(s), and to sublicense the foregoing rights on
22+
# either these or other terms.
23+
#
24+
# This license is subject to the following condition:
25+
#
26+
# The above copyright notice and either this complete permission notice or at a
27+
# minimum a reference to the UPL must be included in all copies or substantial
28+
# portions of the Software.
29+
#
30+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36+
# SOFTWARE.
37+
38+
SHELL=/bin/sh
39+
QUIETLY$(MX_VERBOSE) = @
40+
41+
XZ_ROOT=.
42+
CONFIG_H_DIR=$(XZ_ROOT)
43+
OBJ_DIR=$(XZ_ROOT)/build
44+
45+
LIB_DIR=$(XZ_ROOT)/dist/lib
46+
INC_DIR=$(XZ_ROOT)/dist/include
47+
48+
INCLUDES=-I$(CONFIG_H_DIR) \
49+
-I$(XZ_ROOT)/src/liblzma \
50+
-I$(XZ_ROOT)/src/liblzma/api \
51+
-I$(XZ_ROOT)/src/liblzma/common \
52+
-I$(XZ_ROOT)/src/liblzma/check \
53+
-I$(XZ_ROOT)/src/liblzma/lz \
54+
-I$(XZ_ROOT)/src/liblzma/rangecoder \
55+
-I$(XZ_ROOT)/src/liblzma/lzma \
56+
-I$(XZ_ROOT)/src/liblzma/delta \
57+
-I$(XZ_ROOT)/src/liblzma/simple \
58+
-I$(XZ_ROOT)/src/common
59+
60+
CFLAGS=-fPIC -DPIC -g -O2
61+
62+
ifeq ($(shell uname -s), Darwin)
63+
LIB_NAME=liblzma.5.dylib
64+
LIB_LINK=-Wl,-install_name -Wl,@rpath/$(LIB_NAME)
65+
SYM_LIB1=liblzma.dylib
66+
SYM_LIB2=liblzma.5.2.5.dylib
67+
else
68+
LIB_NAME=liblzma.so.5
69+
LIB_LINK=-Wl,-soname -Wl,$(LIB_NAME)
70+
SYM_LIB1=liblzma.so
71+
SYM_LIB2=liblzma.so.5.2.5
72+
endif
73+
74+
CC=clang
75+
SRC = $(XZ_ROOT)/src
76+
77+
# public domain licensed sources
78+
SRC_FILES= $(SRC)/common/tuklib_physmem.c \
79+
$(SRC)/liblzma/common/vli_size.c \
80+
$(SRC)/liblzma/common/hardware_physmem.c \
81+
$(SRC)/liblzma/common/filter_encoder.c \
82+
$(SRC)/liblzma/common/block_buffer_decoder.c \
83+
$(SRC)/liblzma/common/index.c \
84+
$(SRC)/liblzma/common/stream_encoder.c \
85+
$(SRC)/liblzma/common/block_encoder.c \
86+
$(SRC)/liblzma/common/easy_encoder.c \
87+
$(SRC)/liblzma/common/easy_buffer_encoder.c \
88+
$(SRC)/liblzma/common/block_util.c \
89+
$(SRC)/liblzma/common/filter_buffer_decoder.c \
90+
$(SRC)/liblzma/common/stream_flags_encoder.c \
91+
$(SRC)/liblzma/common/easy_preset.c \
92+
$(SRC)/liblzma/common/index_encoder.c \
93+
$(SRC)/liblzma/common/common.c \
94+
$(SRC)/liblzma/common/block_header_encoder.c \
95+
$(SRC)/liblzma/common/vli_encoder.c \
96+
$(SRC)/liblzma/common/block_header_decoder.c \
97+
$(SRC)/liblzma/common/stream_buffer_encoder.c \
98+
$(SRC)/liblzma/common/block_buffer_encoder.c \
99+
$(SRC)/liblzma/common/alone_decoder.c \
100+
$(SRC)/liblzma/common/auto_decoder.c \
101+
$(SRC)/liblzma/common/stream_flags_common.c \
102+
$(SRC)/liblzma/common/easy_decoder_memusage.c \
103+
$(SRC)/liblzma/common/easy_encoder_memusage.c \
104+
$(SRC)/liblzma/common/filter_buffer_encoder.c \
105+
$(SRC)/liblzma/common/filter_decoder.c \
106+
$(SRC)/liblzma/common/filter_flags_encoder.c \
107+
$(SRC)/liblzma/common/filter_common.c \
108+
$(SRC)/liblzma/common/alone_encoder.c \
109+
$(SRC)/liblzma/common/block_decoder.c \
110+
$(SRC)/liblzma/common/filter_flags_decoder.c \
111+
$(SRC)/liblzma/common/index_decoder.c \
112+
$(SRC)/liblzma/common/stream_buffer_decoder.c \
113+
$(SRC)/liblzma/common/stream_flags_decoder.c \
114+
$(SRC)/liblzma/common/index_hash.c \
115+
$(SRC)/liblzma/common/stream_decoder.c \
116+
$(SRC)/liblzma/common/vli_decoder.c \
117+
$(SRC)/liblzma/check/crc64_table.c \
118+
$(SRC)/liblzma/check/crc32_table.c \
119+
$(SRC)/liblzma/check/crc64_fast.c \
120+
$(SRC)/liblzma/check/crc32_fast.c \
121+
$(SRC)/liblzma/check/check.c \
122+
$(SRC)/liblzma/check/sha256.c \
123+
$(SRC)/liblzma/lz/lz_encoder.c \
124+
$(SRC)/liblzma/lz/lz_encoder_mf.c \
125+
$(SRC)/liblzma/lz/lz_decoder.c \
126+
$(SRC)/liblzma/lzma/lzma_encoder_presets.c \
127+
$(SRC)/liblzma/lzma/lzma_encoder.c \
128+
$(SRC)/liblzma/lzma/lzma_encoder_optimum_fast.c \
129+
$(SRC)/liblzma/lzma/lzma_encoder_optimum_normal.c \
130+
$(SRC)/liblzma/lzma/lzma2_encoder.c \
131+
$(SRC)/liblzma/lzma/lzma2_decoder.c \
132+
$(SRC)/liblzma/lzma/lzma_decoder.c \
133+
$(SRC)/liblzma/lzma/fastpos_table.c \
134+
$(SRC)/liblzma/rangecoder/price_table.c \
135+
$(SRC)/liblzma/delta/delta_common.c \
136+
$(SRC)/liblzma/delta/delta_encoder.c \
137+
$(SRC)/liblzma/delta/delta_decoder.c \
138+
$(SRC)/liblzma/simple/simple_coder.c \
139+
$(SRC)/liblzma/simple/simple_encoder.c \
140+
$(SRC)/liblzma/simple/simple_decoder.c \
141+
$(SRC)/liblzma/simple/powerpc.c \
142+
$(SRC)/liblzma/simple/x86.c \
143+
$(SRC)/liblzma/simple/arm.c \
144+
$(SRC)/liblzma/simple/ia64.c \
145+
$(SRC)/liblzma/simple/sparc.c \
146+
$(SRC)/liblzma/simple/armthumb.c
147+
148+
OBJS_FILES=$(patsubst %.c,%.o,$(SRC_FILES))
149+
OBJS =$(patsubst %.o,$(OBJ_DIR)/%.o,$(notdir $(OBJS_FILES)))
150+
151+
all: build_dir objects
152+
$(QUIETLY) $(CC) -shared $(CFLAGS) $(LIB_LINK) -o $(LIB_DIR)/$(LIB_NAME) $(OBJS)
153+
$(QUIETLY) cd $(LIB_DIR) && ln -s $(LIB_NAME) $(SYM_LIB1)
154+
$(QUIETLY) cd $(LIB_DIR) && ln -s $(LIB_NAME) $(SYM_LIB2)
155+
$(QUIETLY) cp -r $(XZ_ROOT)/src/liblzma/api/lzma $(INC_DIR)/lzma
156+
$(QUIETLY) cp $(XZ_ROOT)/src/liblzma/api/lzma.h $(INC_DIR)/lzma.h
157+
$(QUIETLY) rm -f $(OBJS)
158+
159+
objects: build_dir $(OBJS_FILES)
160+
161+
.c.o:
162+
$(QUIETLY) $(CC) -DHAVE_CONFIG_H $(CFLAGS) $(INCLUDES) -c $< -o $(OBJ_DIR)/$(@F)
163+
164+
build_dir:
165+
$(QUIETLY) mkdir -p $(OBJ_DIR)
166+
$(QUIETLY) mkdir -p $(LIB_DIR)
167+
$(QUIETLY) mkdir -p $(INC_DIR)
168+
169+
clean:
170+
$(QUIETLY) rm -f $(OBJS) $(OBJS_FILES)
171+
$(QUIETLY) cd $(LIB_DIR) && rm -f $(LIB_NAME) $(SYM_LIB1) $(SYM_LIB2)
172+
$(QUIETLY) cd $(INC_DIR) && rm -rf lzma && rm -f lzma.h
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
42+
#define ASSUME_RAM 128
43+
#define ENABLE_NLS 1
44+
#define HAVE_CHECK_CRC32 1
45+
#define HAVE_CHECK_CRC64 1
46+
#define HAVE_CHECK_SHA256 1
47+
#define HAVE_DCGETTEXT 1
48+
#define HAVE_DECL_PROGRAM_INVOCATION_NAME 1
49+
#define HAVE_DECODERS 1
50+
#define HAVE_DECODER_ARM 1
51+
#define HAVE_DECODER_ARMTHUMB 1
52+
#define HAVE_DECODER_DELTA 1
53+
#define HAVE_DECODER_IA64 1
54+
#define HAVE_DECODER_LZMA1 1
55+
#define HAVE_DECODER_LZMA2 1
56+
#define HAVE_DECODER_POWERPC 1
57+
#define HAVE_DECODER_SPARC 1
58+
#define HAVE_DECODER_X86 1
59+
#define HAVE_DLFCN_H 1
60+
#define HAVE_ENCODERS 1
61+
#define HAVE_ENCODER_ARM 1
62+
#define HAVE_ENCODER_ARMTHUMB 1
63+
#define HAVE_ENCODER_DELTA 1
64+
#define HAVE_ENCODER_IA64 1
65+
#define HAVE_ENCODER_LZMA1 1
66+
#define HAVE_ENCODER_LZMA2 1
67+
#define HAVE_ENCODER_POWERPC 1
68+
#define HAVE_ENCODER_SPARC 1
69+
#define HAVE_ENCODER_X86 1
70+
#define HAVE_FCNTL_H 1
71+
#define HAVE_FUTIMENS 1
72+
#define HAVE_GETTEXT 1
73+
#define HAVE_IMMINTRIN_H 1
74+
#define HAVE_INTTYPES_H 1
75+
#define HAVE_LIMITS_H 1
76+
#define HAVE_MBRTOWC 1
77+
#define HAVE_MEMORY_H 1
78+
#define HAVE_MF_BT2 1
79+
#define HAVE_MF_BT3 1
80+
#define HAVE_MF_BT4 1
81+
#define HAVE_MF_HC3 1
82+
#define HAVE_MF_HC4 1
83+
#define HAVE_POSIX_FADVISE 1
84+
#define HAVE_STDBOOL_H 1
85+
#define HAVE_STDINT_H 1
86+
#define HAVE_STDLIB_H 1
87+
#define HAVE_STRINGS_H 1
88+
#define HAVE_STRING_H 1
89+
#define HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC 1
90+
#define HAVE_SYS_PARAM_H 1
91+
#define HAVE_SYS_STAT_H 1
92+
#define HAVE_SYS_TIME_H 1
93+
#define HAVE_SYS_TYPES_H 1
94+
#define HAVE_UINTPTR_T 1
95+
#define HAVE_UNISTD_H 1
96+
#define HAVE_VISIBILITY 1
97+
#define HAVE_WCWIDTH 1
98+
#define HAVE__BOOL 1
99+
#define HAVE__MM_MOVEMASK_EPI8 1
100+
#define HAVE___BUILTIN_ASSUME_ALIGNED 1
101+
#define HAVE___BUILTIN_BSWAPXX 1
102+
#define NDEBUG 1
103+
#define SIZEOF_SIZE_T 8
104+
#define STDC_HEADERS 1
105+
#define TUKLIB_CPUCORES_SCHED_GETAFFINITY 1
106+
#define TUKLIB_FAST_UNALIGNED_ACCESS 1
107+
#define TUKLIB_PHYSMEM_SYSCONF 1
108+
#define VERSION "5.2.5"
109+
#ifndef _DARWIN_USE_64_BIT_INODE
110+
# define _DARWIN_USE_64_BIT_INODE 1
111+
#endif

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
so_ext = get_config_var("EXT_SUFFIX")
6565
SOABI = get_config_var("SOABI")
6666
is_managed = 'managed' in SOABI
67+
lib_ext = 'dylib' if sys.platform == "darwin" else 'so'
6768

6869
# configure logger
6970
logger = logging.getLogger(__name__)
@@ -302,6 +303,33 @@ def install(self, build_dir=None):
302303
return self.lib_install_dir
303304

304305

306+
class LZMADepedency(CAPIDependency):
307+
308+
def build(self, extracted_dir=None):
309+
if not extracted_dir:
310+
extracted_dir = self.download()
311+
312+
xz_src_path = os.path.join(extracted_dir, self.package_name + "-" + self.version)
313+
lzma_support_path = os.path.join(__dir__, 'lzma')
314+
parallel_arg = "-j" + str(os.cpu_count()) if threaded else ""
315+
make_args = ['make', parallel_arg, '-C', lzma_support_path]
316+
make_args += ["CC='%s'" % get_config_var("CC")]
317+
make_args += ["XZ_ROOT='%s'" % xz_src_path]
318+
make_args += ["CONFIG_H_DIR='%s'" % lzma_support_path]
319+
make_args += ["LIB_DIR='%s'" % self.lib_install_dir]
320+
make_args += ["INC_DIR='%s'" % self.include_install_dir]
321+
system(' '.join(make_args), msg="Could not build liblzma")
322+
return self.lib_install_dir
323+
324+
def install(self, build_dir=None):
325+
lib_path = os.path.join(self.lib_install_dir, "lib%s.%s" % (self.lib_name, lib_ext))
326+
if os.path.exists(lib_path):
327+
# library has been built earlier, so just return the install directory.
328+
return self.lib_install_dir
329+
330+
return self.build()
331+
332+
305333
def _build_deps(deps):
306334
libs = []
307335
library_dirs = []
@@ -500,7 +528,8 @@ def build(capi_home):
500528
build_nativelibsupport(capi_home,
501529
subdir="lzma",
502530
libname="liblzmasupport",
503-
libs=['lzma'])
531+
deps=[LZMADepedency("lzma", "xz==5.2.5", "XZ-5.2.5")],
532+
extra_link_args=["-Wl,-rpath,%s/lib/%s/" % (relative_rpath, SOABI)])
504533
build_libpython(capi_home)
505534
build_builtin_exts(capi_home)
506535
finally:

mx.graalpython/suite.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@
107107
"version": "1.8",
108108
},
109109
},
110+
"XZ-5.2.5": {
111+
"urls": [
112+
"https://lafo.ssw.uni-linz.ac.at/pub/graal-external-deps/xz-5.2.5.tar.gz",
113+
],
114+
"packedResource": True,
115+
"sha1": "fa2ae4db119f639a01b02f99f1ba671ece2828eb",
116+
},
110117
"BZIP2": {
111118
"urls": [
112119
"https://lafo.ssw.uni-linz.ac.at/pub/graal-external-deps/graalpython/bzip2-1.0.8.tar.gz",
@@ -336,12 +343,14 @@
336343
"sulong:SULONG_HOME",
337344
"sulong:SULONG_LEGACY",
338345
"sulong:SULONG_BOOTSTRAP_TOOLCHAIN",
346+
"XZ-5.2.5",
339347
"BZIP2",
340348
],
341349
"buildEnv": {
342350
"TRUFFLE_H_INC": "<path:SULONG_LEGACY>/include",
343351
"ARCH": "<arch>",
344352
"OS": "<os>",
353+
"XZ-5.2.5": "<path:XZ-5.2.5>",
345354
"BZIP2": "<path:BZIP2>",
346355
},
347356
},

0 commit comments

Comments
 (0)