Skip to content

Commit 2961e42

Browse files
committed
[GR-47698] Support GraalPy build with GraalOS musl toolchain.
PullRequest: graalpython/3939
2 parents 139e632 + 7f20333 commit 2961e42

File tree

4 files changed

+211
-54
lines changed

4 files changed

+211
-54
lines changed

graalpython/python-liblzma/src/lzma.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
#include <limits.h>
5151
#include <stdlib.h>
5252
#include <string.h>
53-
53+
#include <sys/types.h>
5454

5555
#include <lzma.h>
5656

@@ -196,7 +196,7 @@ enum {
196196
FORMAT_RAW,
197197
};
198198

199-
// The ref_count is important for `copy` as we
199+
// The ref_count is important for `copy` as we
200200
// share off heap storage between native objects.
201201
typedef struct
202202
{
@@ -239,7 +239,7 @@ void get_macros(int* formats, int* checks, uint64_t* filters, int* mfs, int* mod
239239
checks[CHECK_SHA256_INDEX] = LZMA_CHECK_SHA256;
240240
checks[CHECK_ID_MAX_INDEX] = LZMA_CHECK_ID_MAX;
241241
checks[CHECK_UNKNOWN_INDEX] = LZMA_CHECK_UNKNOWN;
242-
242+
243243
filters[FILTER_LZMA1_INDEX] = LZMA_FILTER_LZMA1;
244244
filters[FILTER_LZMA2_INDEX] = LZMA_FILTER_LZMA2;
245245
filters[FILTER_DELTA_INDEX] = LZMA_FILTER_DELTA;
@@ -249,7 +249,7 @@ void get_macros(int* formats, int* checks, uint64_t* filters, int* mfs, int* mod
249249
filters[FILTER_ARM_INDEX] = LZMA_FILTER_ARM;
250250
filters[FILTER_ARMTHUMB_INDEX] = LZMA_FILTER_ARMTHUMB;
251251
filters[FILTER_SPARC_INDEX] = LZMA_FILTER_SPARC;
252-
252+
253253
mfs[MF_HC3_INDEX] = LZMA_MF_HC3;
254254
mfs[MF_HC4_INDEX] = LZMA_MF_HC4;
255255
mfs[MF_BT2_INDEX] = LZMA_MF_BT2;
@@ -258,7 +258,7 @@ void get_macros(int* formats, int* checks, uint64_t* filters, int* mfs, int* mod
258258

259259
modes[MODE_FAST_INDEX] = LZMA_MODE_FAST;
260260
modes[MODE_NORMAL_INDEX] = LZMA_MODE_NORMAL;
261-
261+
262262
preset[PRESET_DEFAULT_INDEX] = LZMA_PRESET_DEFAULT;
263263
preset[PRESET_EXTREME_INDEX] = LZMA_PRESET_EXTREME;
264264
}
@@ -267,7 +267,7 @@ static void* LZMA_Malloc(void* ctx, size_t items, size_t size)
267267
{
268268
void *m = malloc((size_t)items * (size_t)size);
269269
LOG_FINER("malloc(address: %p, items: %u, size: %u)\n", m, items, size);
270-
return m;
270+
return m;
271271
}
272272

273273
static void LZMA_Free(void* ctx, void *ptr)
@@ -524,7 +524,7 @@ int lzma_set_filter_spec_lzma(lzmast_stream *lzmast, int fidx, int64_t* opts) {
524524
initFilters(lzmast);
525525
lzma_options_lzma *options;
526526
lzmast->filters[fidx].id = (uint64_t) opts[ID_INDEX];
527-
527+
528528
options = (lzma_options_lzma *)calloc(1, sizeof *options);
529529
if (options == NULL) {
530530
return LZMA_MEM_ERROR;
@@ -538,31 +538,31 @@ int lzma_set_filter_spec_lzma(lzmast_stream *lzmast, int fidx, int64_t* opts) {
538538
}
539539

540540
if (opts[LC_INDEX] != -1) {
541-
options->lc = (uint32_t) opts[LC_INDEX];
541+
options->lc = (uint32_t) opts[LC_INDEX];
542542
}
543543

544544
if (opts[LP_INDEX] != -1) {
545-
options->lp = (uint32_t) opts[LP_INDEX];
545+
options->lp = (uint32_t) opts[LP_INDEX];
546546
}
547547

548548
if (opts[PB_INDEX] != -1) {
549-
options->pb = (uint32_t) opts[PB_INDEX];
549+
options->pb = (uint32_t) opts[PB_INDEX];
550550
}
551551

552552
if (opts[MODE_INDEX] != -1) {
553-
options->mode = (lzma_mode) opts[MODE_INDEX];
553+
options->mode = (lzma_mode) opts[MODE_INDEX];
554554
}
555555

556556
if (opts[NICE_LEN_INDEX] != -1) {
557-
options->nice_len = (uint32_t) opts[NICE_LEN_INDEX];
557+
options->nice_len = (uint32_t) opts[NICE_LEN_INDEX];
558558
}
559559

560560
if (opts[MF_INDEX] != -1) {
561-
options->mf = (lzma_match_finder) opts[MF_INDEX];
561+
options->mf = (lzma_match_finder) opts[MF_INDEX];
562562
}
563563

564564
if (opts[DEPTH_INDEX] != -1) {
565-
options->depth = (uint32_t) opts[DEPTH_INDEX];
565+
options->depth = (uint32_t) opts[DEPTH_INDEX];
566566
}
567567

568568
lzmast->filters[fidx].options = options;
@@ -662,7 +662,7 @@ int lzma_decode_filter_spec(int64_t filter_id, Byte* encoded_props, int len, int
662662
lzma_filter filter;
663663

664664
filter.id = (lzma_vli) filter_id;
665-
665+
666666
lzret = lzma_properties_decode(&filter, NULL, encoded_props, len);
667667
if (!isOK(lzret)) {
668668
return lzret;
@@ -879,8 +879,8 @@ int lzma_lzma_alone_decoder(lzmast_stream *lzmast, uint64_t memlimit) {
879879
d->lzs.avail_in are updated to reflect the consumed input. */
880880

881881
// nfi_function: name('decompress') map('lzmast_stream*', 'POINTER')
882-
int lzma_decompress(lzmast_stream *lzmast,
883-
Byte *input_buffer, ssize_t offset,
882+
int lzma_decompress(lzmast_stream *lzmast,
883+
Byte *input_buffer, ssize_t offset,
884884
ssize_t max_length,
885885
ssize_t bufsize, size_t lzs_avail_in) {
886886
LOG_INFO("lzma_decompress(%p, %p, %zd, %zd, %zd, %zd)\n", lzmast, input_buffer, offset, bufsize, lzs_avail_in);
@@ -919,11 +919,11 @@ int lzma_decompress(lzmast_stream *lzmast,
919919
if (!isOK(lzret)) {
920920
clear_output(lzmast);
921921
return lzret;
922-
}
922+
}
923923
if (lzret == LZMA_GET_CHECK || lzret == LZMA_NO_CHECK) {
924924
lzmast->check = lzma_get_check(&lzmast->lzs);
925925
lzret = LZMA_OK;
926-
}
926+
}
927927
if (lzret == LZMA_STREAM_END) {
928928
// lzmast->eof = 1;
929929
// we'll return LZMA_STREAM_END to the java side and process EOF.

mx.graalpython/mx_graalpython.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,15 @@ def libpythonvm_build_args():
267267
build_args = []
268268
build_args += bytecode_dsl_build_args()
269269

270+
if graalos := ("musl" in mx_subst.path_substitutions.substitute("<multitarget_libc_selection>")):
271+
build_args += ['-H:+GraalOS']
272+
else:
273+
build_args += ["-Dpolyglot.image-build-time.PreinitializeContexts=python"]
274+
270275
if (
271-
mx_sdk_vm_ng.is_nativeimage_ee()
272-
and mx.is_linux()
276+
mx.is_linux()
277+
and not graalos
278+
and mx_sdk_vm_ng.is_nativeimage_ee()
273279
and not os.environ.get('NATIVE_IMAGE_AUXILIARY_ENGINE_CACHE')
274280
and not _is_overridden_native_image_arg("--gc")
275281
):
@@ -430,8 +436,7 @@ def full_python(args, env=None):
430436
args.insert(0, '--python.WithJavaStacktrace=1')
431437

432438
if "--hosted" in args[:2]:
433-
args.remove("--hosted")
434-
return python(args)
439+
return do_run_python(args)
435440

436441
if '--vm.da' not in args:
437442
args.insert(0, '--vm.ea')
@@ -467,15 +472,13 @@ def handle_debug_arg(args):
467472
f"--vm.agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=127.0.0.1:{mx._opts.java_dbg_port}")
468473

469474

470-
def python(args, **kwargs):
471-
"""run a Python program or shell"""
472-
if not any(arg.startswith('--python.WithJavaStacktrace') for arg in args):
473-
args.insert(0, '--python.WithJavaStacktrace=1')
474-
475-
do_run_python(args, **kwargs)
475+
def do_run_python(args, extra_vm_args=None, env=None, jdk=None, extra_dists=None, cp_prefix=None, cp_suffix=None, main_class=GRAALPYTHON_MAIN_CLASS, minimal=False, **kwargs):
476476

477+
if "--hosted" in args[:2]:
478+
args.remove("--hosted")
479+
if not any(arg.startswith('--python.WithJavaStacktrace') for arg in args):
480+
args.insert(0, '--python.WithJavaStacktrace=1')
477481

478-
def do_run_python(args, extra_vm_args=None, env=None, jdk=None, extra_dists=None, cp_prefix=None, cp_suffix=None, main_class=GRAALPYTHON_MAIN_CLASS, minimal=False, **kwargs):
479482
if not any(arg.startswith("--python.CAPI") for arg in args):
480483
capi_home = _get_capi_home()
481484
args.insert(0, "--python.CAPI=%s" % capi_home)
@@ -495,7 +498,7 @@ def do_run_python(args, extra_vm_args=None, env=None, jdk=None, extra_dists=None
495498

496499
if minimal:
497500
x = [x for x in SUITE.dists if x.name == "GRAALPYTHON"][0]
498-
dists = [dep for dep in x.deps if dep.isJavaProject() or dep.isJARDistribution()]
501+
dists = [dep for dep in x.deps if dep.isJavaProject() or dep.isJARDistribution() and dep.exists()]
499502
# Hack: what we should just do is + ['GRAALPYTHON_VERSIONS_MAIN'] and let MX figure out
500503
# the class-path and other VM arguments necessary for it. However, due to a bug in MX,
501504
# LayoutDirDistribution causes an exception if passed to mx.get_runtime_jvm_args,
@@ -2322,16 +2325,17 @@ def run(self, args, env=None, cwd=None, **kwargs):
23222325
args.insert(0, "-q")
23232326

23242327
args[:0] = [
2325-
f"--python.PyCachePrefix={pycache_dir}",
2326-
"--python.DisableFrozenModules",
2328+
"--PosixModuleBackend=java",
2329+
"--CompressionModulesBackend=java",
2330+
f"--PyCachePrefix={pycache_dir}",
2331+
"--DisableFrozenModules",
23272332
"-B",
23282333
"-S"
23292334
]
23302335
mx_util.ensure_dir_exists(cwd)
23312336

23322337
env = env.copy() if env else os.environ.copy()
23332338
env.update(cast(GraalpythonProject, self.subject).getBuildEnv())
2334-
args.insert(0, '--PosixModuleBackend=java')
23352339
jdk = mx.get_jdk() # Don't get JVMCI, it might not have finished building by this point
23362340
rc = do_run_python(args, jdk=jdk, env=env, cwd=cwd, minimal=True, out=self.PrefixingOutput(self.subject.name, mx.log), err=self.PrefixingOutput(self.subject.name, mx.log_error), **kwargs)
23372341

0 commit comments

Comments
 (0)