From 8fc755372f8184e6a487e4b8200cea5faf6eea12 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Tue, 9 Jun 2026 21:21:17 +0200 Subject: [PATCH] Fix build variant environment variable handling --- scripts/Util.pm | 2 +- scripts/build.pl | 82 +++++++++++++++++++++++++--------------------- scripts/compile.pl | 16 ++++++--- 3 files changed, 56 insertions(+), 44 deletions(-) diff --git a/scripts/Util.pm b/scripts/Util.pm index 5821bbf..9d4f9d8 100644 --- a/scripts/Util.pm +++ b/scripts/Util.pm @@ -51,7 +51,7 @@ sub date_now { sub run { my @cmd = @_; - say " + @cmd"; + say "Running: @cmd"; system(@cmd) == 0 or die "Command failed (exit " . ( $? >> 8 ) . "): @cmd\n"; } diff --git a/scripts/build.pl b/scripts/build.pl index 9b2adb5..c651979 100755 --- a/scripts/build.pl +++ b/scripts/build.pl @@ -24,9 +24,12 @@ sub compile { " WAMR_USE_MMAP_IN_TEXT=$ENV{WAMR_USE_MMAP_IN_TEXT}", " WAMR_USE_XIP=$ENV{WAMR_USE_XIP}", " WAMR_USE_ALLOCATOR=$ENV{WAMR_USE_ALLOCATOR}", + " WAMR_USE_GLOBAL_HEAP_IN_TEXT=$ENV{WAMR_USE_GLOBAL_HEAP_IN_TEXT}", + " WAMR_USE_RUNTIME_POOL_IN_TEXT=$ENV{WAMR_USE_RUNTIME_POOL_IN_TEXT}", + " WAMR_USE_LINEAR_POOL_IN_TEXT=$ENV{WAMR_USE_LINEAR_POOL_IN_TEXT}", " compile.pl $module $target $mode"; - system( 'perl', $compile_pl, $module, $target, $mode ) == 0 + system( "perl $compile_pl $module $target $mode > $local_root/build.log 2>&1" ) == 0 or die "Build failed\n"; sleep(1); } @@ -57,33 +60,33 @@ my @allocator_variants = ( "Pool allocator (Alloc_With_Pool)", "Allocator with usage (Alloc_With_Allocator)", ); -my $selected_allocator_variant; +my $selected_allocator_variant = $allocator_variants[1]; if ( grep { $_ eq "aot" or $_ eq "interp" } @selected_modes ) { ($selected_allocator_variant) = TUI::select_from_list( "Select WAMR Allocator Variant", 0, @allocator_variants ); die "No allocator variant selected" unless $selected_allocator_variant; - local $ENV{WAMR_USE_ALLOCATOR} = - ( $selected_allocator_variant eq $allocator_variants[0] ) - ? "false" - : "true"; } +local $ENV{WAMR_USE_ALLOCATOR} = + ( $selected_allocator_variant eq $allocator_variants[1] ) + ? "true" + : "false"; # ========================================================================================= # # Select XIP variant # ========================================================================================= # my @xip_variants = ( "Compile AOT with --xip", "Compile AOT without --xip" ); -my $selected_xip_variant; +my $selected_xip_variant = $xip_variants[0]; if ( grep { $_ eq "aot" } @selected_modes ) { ($selected_xip_variant) = TUI::select_from_list( "Select WAMRC XIP Variant", 0, @xip_variants ); die "No XIP variant selected" unless $selected_xip_variant; - local $ENV{WAMR_USE_XIP} = - ( $selected_xip_variant eq $xip_variants[0] ) - ? "true" - : "false"; } +local $ENV{WAMR_USE_XIP} = + ( $selected_xip_variant eq $xip_variants[0] ) + ? "true" + : "false"; # ========================================================================================= # # Select .text.wamr_mmap variant @@ -93,17 +96,17 @@ my @mmap_variants = ( "Place mmap_space in .text.wamr_mmap", "Let the linker decide where mmap_space is located" ); -my $selected_mmap_variant; +my $selected_mmap_variant = $mmap_variants[1]; if ( grep { $_ eq "aot" or $_ eq "interp" } @selected_modes ) { ($selected_mmap_variant) = TUI::select_from_list( "Select WAMR Mmap.Text Variant", 0, @mmap_variants ); die "No variant selected" unless $selected_mmap_variant; - local $ENV{WAMR_USE_MMAP_IN_TEXT} = - ( $selected_mmap_variant eq $mmap_variants[0] ) - ? "true" - : "false"; } +local $ENV{WAMR_USE_MMAP_IN_TEXT} = + ( $selected_mmap_variant eq $mmap_variants[0] ) + ? "true" + : "false"; # ========================================================================================= # # Select .text.wamr_aot variant @@ -113,17 +116,17 @@ my @aot_section_variants = ( "Place AOT array in .text.wamr_aot", "Let the linker decide where the AOT array is located", ); -my $selected_aot_variant; +my $selected_aot_variant = $aot_section_variants[1]; if ( grep { $_ eq "aot" } @selected_modes ) { ($selected_aot_variant) = TUI::select_from_list( "Select WAMR Array.Text Variant", 0, @aot_section_variants ); die "No AOT section variant selected" unless $selected_aot_variant; - local $ENV{WAMR_USE_AOT_IN_TEXT} = - ( $selected_aot_variant eq $aot_section_variants[0] ) - ? "true" - : "false"; } +local $ENV{WAMR_USE_AOT_IN_TEXT} = + ( $selected_aot_variant eq $aot_section_variants[0] ) + ? "true" + : "false"; # ========================================================================================= # # Select .text.wamr_global_heap variant @@ -133,17 +136,17 @@ my @global_heap_variants = ( "Place pool allocator's global_heap in .text.wamr_global_heap", "Let the linker decide where global_heap is located" ); -my $selected_global_heap_variant; +my $selected_global_heap_variant = $global_heap_variants[1]; if ( $selected_allocator_variant eq $allocator_variants[0] ) { ($selected_global_heap_variant) = TUI::select_from_list( "Select WAMR Global Heap Variant", 0, @global_heap_variants ); die "No global heap variant selected" unless $selected_global_heap_variant; - local $ENV{WAMR_USE_GLOBAL_HEAP_IN_TEXT} = - ( $selected_global_heap_variant eq $global_heap_variants[0] ) - ? "true" - : "false"; } +local $ENV{WAMR_USE_GLOBAL_HEAP_IN_TEXT} = + ( $selected_global_heap_variant eq $global_heap_variants[0] ) + ? "true" + : "false"; # ========================================================================================= # # Select .text.wamr_runtime_pool variant @@ -153,18 +156,18 @@ my @runtime_pool_variants = ( "Place usage allocator's runtime_pool in .text.wamr_runtime_pool", "Let the linker decide where runtime_pool is located" ); -my $selected_runtime_pool_variant; +my $selected_runtime_pool_variant = $runtime_pool_variants[1]; if ( $selected_allocator_variant eq $allocator_variants[1] ) { ($selected_runtime_pool_variant) = TUI::select_from_list( "Select WAMR Runtime Pool Variant", 0, @runtime_pool_variants ); die "No runtime pool variant selected" unless $selected_runtime_pool_variant; - local $ENV{WAMR_USE_RUNTIME_POOL_IN_TEXT} = - ( $selected_runtime_pool_variant eq $runtime_pool_variants[0] ) - ? "true" - : "false"; } +local $ENV{WAMR_USE_RUNTIME_POOL_IN_TEXT} = + ( $selected_runtime_pool_variant eq $runtime_pool_variants[0] ) + ? "true" + : "false"; # ========================================================================================= # # Select .text.wamr_linear_pool variant @@ -174,25 +177,25 @@ my @linear_pool_variants = ( "Place usage allocator's linear_pool in .text.wamr_linear_pool", "Let the linker decide where linear_pool is located" ); -my $selected_linear_pool_variant; +my $selected_linear_pool_variant = $linear_pool_variants[1]; if ( $selected_allocator_variant eq $allocator_variants[1] ) { ($selected_linear_pool_variant) = TUI::select_from_list( "Select WAMR Linear Pool Variant", 0, @linear_pool_variants ); die "No linear pool variant selected" unless $selected_linear_pool_variant; - local $ENV{WAMR_USE_LINEAR_POOL_IN_TEXT} = - ( $selected_linear_pool_variant eq $linear_pool_variants[0] ) - ? "true" - : "false"; } +local $ENV{WAMR_USE_LINEAR_POOL_IN_TEXT} = + ( $selected_linear_pool_variant eq $linear_pool_variants[0] ) + ? "true" + : "false"; # ========================================================================================= # # Select FAIL catch flags (written to runner_flags in each build dir) # ========================================================================================= # my %catch_flag_map = ( - "--catch-outer" => "--catch-outerspace", - "--catch-text" => "--catch-write-textsegment", + "--catch-outer" => "--catch-outerspace", + "--catch-text" => "--catch-write-textsegment", "--wamr-exceptions" => "-Wf,--group1-marker=fail_marker_group1", ); my @selected_catch_flags; @@ -279,6 +282,9 @@ foreach my $experiment (@selected_experiments) { print $fhandle "$catch_flag_map{$_}\n" for @selected_catch_flags; close($fhandle); + system( "mv", "$local_root/build.log", + "$local_root/build-$experiment/build.log" ); + system( join " ", ( diff --git a/scripts/compile.pl b/scripts/compile.pl index 4ff6a87..a6acb98 100644 --- a/scripts/compile.pl +++ b/scripts/compile.pl @@ -32,10 +32,13 @@ my $wamr_root = require_env('WAMR_ROOT'); my $cross_cc = require_env('CROSS_CC'); my $linux_cc = require_env('LINUX_CC'); -my $use_aot_in_text = ( $ENV{WAMR_USE_AOT_IN_TEXT} // 'false' ) eq 'true'; -my $use_mmap_in_text = ( $ENV{WAMR_USE_MMAP_IN_TEXT} // 'false' ) eq 'true'; -my $use_xip = ( $ENV{WAMR_USE_XIP} // 'false' ) eq 'true'; -my $use_allocator = ( $ENV{WAMR_USE_ALLOCATOR} // 'false' ) eq 'true'; +my $use_aot_in_text = ( $ENV{WAMR_USE_AOT_IN_TEXT} // 'false' ) eq 'true'; +my $use_mmap_in_text = ( $ENV{WAMR_USE_MMAP_IN_TEXT} // 'false' ) eq 'true'; +my $use_xip = ( $ENV{WAMR_USE_XIP} // 'false' ) eq 'true'; +my $use_allocator = ( $ENV{WAMR_USE_ALLOCATOR} // 'false' ) eq 'true'; +my $use_global_heap_in_text = ( $ENV{WAMR_USE_GLOBAL_HEAP_IN_TEXT} // 'false' ) eq 'true'; +my $use_runtime_pool_in_text = ( $ENV{WAMR_USE_RUNTIME_POOL_IN_TEXT} // 'false' ) eq 'true'; +my $use_linear_pool_in_text = ( $ENV{WAMR_USE_LINEAR_POOL_IN_TEXT} // 'false' ) eq 'true'; # ========================================================================================= # # WAMR cmake configuration @@ -63,7 +66,7 @@ my @wamr_cmake_linux = ( '-DWAMR_BUILD_PLATFORM=linux', ); # Variant defines passed as CMAKE_C_FLAGS my @variant_cflags = ( '-Wno-error=implicit-function-declaration', '-O0', '-ggdb3' ); -push @variant_cflags, '-DWAMR_MMAP_IN_TEXT=0' unless $use_mmap_in_text; +push @variant_cflags, $use_mmap_in_text ? '-DWAMR_MMAP_IN_TEXT=1' : '-DWAMR_MMAP_IN_TEXT=0'; push @variant_cflags, '-DWASM_MEM_ALLOC_WITH_USAGE=1' if $use_allocator; my $cmake_c_flags = join( ' ', @variant_cflags ); @@ -75,6 +78,9 @@ push @variant_cmake_flags, '-DWAMR_BUILD_ALLOC_WITH_USAGE=1' if $use_allocator; # WASM_MEM_ALLOC_WITH_USAGE value as libiwasm.a was built with. my @host_variant_cflags; push @host_variant_cflags, '-DWASM_MEM_ALLOC_WITH_USAGE=1' if $use_allocator; +push @host_variant_cflags, $use_global_heap_in_text ? '-DWAMR_GLOBAL_HEAP_IN_TEXT=1' : '-DWAMR_GLOBAL_HEAP_IN_TEXT=0'; +push @host_variant_cflags, $use_runtime_pool_in_text ? '-DWAMR_RUNTIME_POOL_IN_TEXT=1' : '-DWAMR_RUNTIME_POOL_IN_TEXT=0'; +push @host_variant_cflags, $use_linear_pool_in_text ? '-DWAMR_LINEAR_POOL_IN_TEXT=1' : '-DWAMR_LINEAR_POOL_IN_TEXT=0'; # ========================================================================================= # # Compiler / linker flags