@ -10,6 +10,7 @@ find_program(MAKE make REQUIRED)
option ( WASI_SDK_DEBUG_PREFIX_MAP "Pass `-fdebug-prefix-map` for built artifacts" ON )
option ( WASI_SDK_INCLUDE_TESTS "Whether or not to build tests by default" OFF )
option ( WASI_SDK_INSTALL_TO_CLANG_RESOURCE_DIR "Whether or not to modify the compiler's resource directory" OFF )
option ( WASI_SDK_LTO "Whether or not to build LTO assets" ON )
set ( wasi_tmp_install ${ CMAKE_CURRENT_BINARY_DIR } /install )
set ( wasi_sysroot ${ wasi_tmp_install } /share/wasi-sysroot )
@ -97,16 +98,28 @@ add_custom_target(compiler-rt DEPENDS compiler-rt-build compiler-rt-post-build)
# w a s i - l i b c b u i l d l o g i c
# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
function ( define_wasi_libc target )
set ( build_dir ${ CMAKE_CURRENT_BINARY_DIR } /wasi-libc- ${ target } )
function ( define_wasi_libc _sub target target_suffix lto )
set ( build_dir ${ CMAKE_CURRENT_BINARY_DIR } /wasi-libc- ${ target } ${ target_suffix } )
if ( ${ target } MATCHES threads )
if ( lto )
set ( extra_make_flags LTO=full THREAD_MODEL=posix )
else ( )
set ( extra_make_flags THREAD_MODEL=posix )
endif ( )
elseif ( ${ target } MATCHES p2 )
if ( lto )
set ( extra_make_flags LTO=full WASI_SNAPSHOT=p2 default )
else ( )
set ( extra_make_flags WASI_SNAPSHOT=p2 default libc_so )
endif ( )
else ( )
if ( lto )
set ( extra_make_flags LTO=full default )
else ( )
set ( extra_make_flags default libc_so )
endif ( )
endif ( )
string ( TOUPPER ${ CMAKE_BUILD_TYPE } CMAKE_BUILD_TYPE_UPPER )
get_property ( directory_cflags DIRECTORY ${ CMAKE_CURRENT_SOURCE_DIR } PROPERTY COMPILE_OPTIONS )
@ -114,7 +127,7 @@ function(define_wasi_libc target)
" $ { C M A K E _ C _ F L A G S } $ { d i r e c t o r y _ c f l a g s } $ { C M A K E _ C _ F L A G S _ $ { C M A K E _ B U I L D _ T Y P E _ U P P E R } } " )
list ( JOIN extra_cflags_list " " extra_cflags )
ExternalProject_Add ( wasi-libc- ${ target }
ExternalProject_Add ( wasi-libc- ${ target } ${ target_suffix } -build
# C u r r e n t l y w a s i - l i b c d o e s n ' t s u p p o r t o u t - o f - t r e e b u i l d s s o f e i g h a
# " d o w n l o a d c o m m a n d " w h i c h c o p i e s t h e s o u r c e t r e e t o a d i f f e r e n t l o c a t i o n
# s o o u t - o f - t r e e b u i l d s a r e s u p p o r t e d .
@ -140,6 +153,16 @@ function(define_wasi_libc target)
)
endfunction ( )
function ( define_wasi_libc target )
define_wasi_libc_sub ( ${ target } "" OFF )
if ( WASI_SDK_LTO )
define_wasi_libc_sub ( ${ target } "-lto" ON )
endif ( )
add_custom_target ( wasi-libc- ${ target }
D E P E N D S w a s i - l i b c - $ { t a r g e t } - b u i l d $ < $ < B O O L : $ { W A S I _ S D K _ L T O } > : w a s i - l i b c - $ { t a r g e t } - l t o - b u i l d > )
endfunction ( )
foreach ( target IN LISTS WASI_SDK_TARGETS )
define_wasi_libc ( ${ target } )
endforeach ( )
@ -148,7 +171,12 @@ endforeach()
# l i b c x x b u i l d l o g i c
# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
function ( define_libcxx target )
execute_process (
C O M M A N D $ { C M A K E _ C _ C O M P I L E R } - d u m p v e r s i o n
O U T P U T _ V A R I A B L E l l v m _ v e r s i o n
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E )
function ( define_libcxx_sub target target_suffix extra_target_flags extra_libdir_suffix )
if ( ${ target } MATCHES threads )
set ( threads ON )
set ( pic OFF )
@ -158,6 +186,10 @@ function(define_libcxx target)
set ( pic ON )
set ( target_flags "" )
endif ( )
if ( ${ target_suffix } MATCHES lto )
set ( pic OFF )
endif ( )
list ( APPEND target_flags ${ extra_target_flags } )
set ( runtimes "libcxx;libcxxabi" )
@ -176,7 +208,7 @@ function(define_libcxx target)
set ( extra_cxxflags_list ${ CMAKE_CXX_FLAGS } ${ extra_flags } )
list ( JOIN extra_cxxflags_list " " extra_cxxflags )
ExternalProject_Add ( libcxx- ${ target } -build
ExternalProject_Add ( libcxx- ${ target } ${ target_suffix } -build
S O U R C E _ D I R $ { l l v m _ p r o j _ d i r } / r u n t i m e s
C M A K E _ A R G S
$ { d e f a u l t _ c m a k e _ a r g s }
@ -214,8 +246,8 @@ function(define_libcxx target)
- D U N I X : B O O L = O N
- D C M A K E _ C _ F L A G S = $ { e x t r a _ c f l a g s }
- D C M A K E _ C X X _ F L A G S = $ { e x t r a _ c x x f l a g s }
- D L I B C X X _ L I B D I R _ S U F F I X = / $ { t a r g e t }
- D L I B C X X A B I _ L I B D I R _ S U F F I X = / $ { t a r g e t }
- D L I B C X X _ L I B D I R _ S U F F I X = / $ { t a r g e t } $ { e x t r a _ l i b d i r _ s u f f i x }
- D L I B C X X A B I _ L I B D I R _ S U F F I X = / $ { t a r g e t } $ { e x t r a _ l i b d i r _ s u f f i x }
# S e e h t t p s : / / w w w . s c i v i s i o n . d e v / c m a k e - e x t e r n a l p r o j e c t - l i s t - a r g u m e n t s / f o r
# w h y t h i s i s i n ` C M A K E _ C A C H E _ A R G S ` i n s t e a d o f a b o v e
@ -229,6 +261,15 @@ function(define_libcxx target)
U S E S _ T E R M I N A L _ B U I L D O N
U S E S _ T E R M I N A L _ I N S T A L L O N
)
endfunction ( )
function ( define_libcxx target )
define_libcxx_sub ( ${ target } "" "" "" )
if ( WASI_SDK_LTO )
# N o t e : c l a n g k n o w s t h i s / l l v m - l t o / $ { l l v m _ v e r s i o n } c o n v e n t i o n .
# h t t p s : / / g i t h u b . c o m / l l v m / l l v m - p r o j e c t / b l o b / l l v m o r g - 1 8 . 1 . 8 / c l a n g / l i b / D r i v e r / T o o l C h a i n s / W e b A s s e m b l y . c p p # L 2 0 4 - L 2 1 0
define_libcxx_sub ( ${ target } "-lto" "-flto=full" "/llvm-lto/${llvm_version}" )
endif ( )
# A s o f t h i s w r i t i n g , ` c l a n g + + ` w i l l i g n o r e t h e t a r g e t - s p e c i f i c i n c l u d e d i r s
# u n l e s s t h i s o n e a l s o e x i s t s :
@ -236,7 +277,7 @@ function(define_libcxx target)
C O M M A N D $ { C M A K E _ C O M M A N D } - E m a k e _ d i r e c t o r y $ { w a s i _ s y s r o o t } / i n c l u d e / c + + / v 1
C O M M E N T " c r e a t i n g l i b c x x - s p e c i f i c h e a d e r f i l e f o l d e r " )
add_custom_target ( libcxx- ${ target }
D E P E N D S l i b c x x - $ { t a r g e t } - b u i l d li b c x x - $ { t a r g e t } - e x t r a - d i r )
D E P E N D S l i b c x x - $ { t a r g e t } - b u i l d $< $ < B O O L : $ { W A S I _ S D K _ L T O } > : l i b c x x - $ { t a r g e t } - l t o - b u i l d > li b c x x - $ { t a r g e t } - e x t r a - d i r )
endfunction ( )
foreach ( target IN LISTS WASI_SDK_TARGETS )