Skip to content

Commit 23fd3a1

Browse files
committed
Fix parallel build failures
This was because the static and shared libraries were both producing .mod files at the same location and a parallel build was confusing the compiler with the timestamps
1 parent 8ead1f2 commit 23fd3a1

File tree

2 files changed

+76
-26
lines changed

2 files changed

+76
-26
lines changed

CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ SET(CMAKE_Fortran_ABI_COMPILED 0)
2525
SET(CMAKE_Fortran_COMPILER_SUPPORTS_F90 1)
2626
SET(CMAKE_Fortran_PREPROCESS_SOURCE
2727
"<CMAKE_Fortran_COMPILER> -cpp <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> -o <PREPROCESSED_SOURCE>")
28-
set(CMAKE_Fortran_MODDIR_FLAG "-module ")
28+
SET(CMAKE_Fortran_MODDIR_FLAG "-module ")
2929

3030
# If we are not building as a part of LLVM, build Flang as an
3131
# standalone project, using LLVM as an external library:
@@ -361,7 +361,10 @@ include_directories(BEFORE
361361
)
362362

363363
# Direct module files to build include directory
364-
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include)
364+
set(FLANG_MODULE_DIRECTORY_SHARED ${CMAKE_CURRENT_BINARY_DIR}/include)
365+
# mod files in the following differs only by the timestamp. This is needed to
366+
# ensure that flang can be built parallelly. It is discarded after flang is built
367+
set(FLANG_MODULE_DIRECTORY_STATIC ${CMAKE_CURRENT_BINARY_DIR}/include-static)
365368

366369
# Install Fortran module files
367370
install(DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY}/

runtime/flang/CMakeLists.txt

Lines changed: 71 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ SET(FTN_INTRINSICS
206206
mod.c
207207
mvbits3f.c
208208
nargs3f.c
209-
omp_lib.F95
210209
outstr3f.c
211210
packtimeqq3f.c
212211
perror3f.c
@@ -273,7 +272,7 @@ SET(FTN_INTRINSICS
273272
wait3f.c
274273
)
275274

276-
SET(FTN_SUPPORT
275+
SET(FTN_SUPPORT_COMMON
277276
bcopy.c
278277
bcopys.c
279278
buffer.c
@@ -338,13 +337,8 @@ SET(FTN_SUPPORT
338337
descIntrins.c
339338
descFioUtil.c
340339
descRW.c
341-
ieee_arithmetic.F95
342-
ieee_exceptions.F95
343-
ieee_features.F95
344340
initpar.c
345341
inquire.c
346-
iso_c_bind.F95
347-
iso_fortran_env.f90
348342
ldread.c
349343
ldwrite.c
350344
linux_dummy.c
@@ -480,18 +474,46 @@ SET(FTN_SUPPORT
480474
xfer_rpm1.c
481475
)
482476

483-
add_library(iso_c_bind OBJECT
484-
iso_c_bind.F95
485-
)
477+
foreach(FTN_FILE ieee_arithmetic ieee_exceptions ieee_features iso_c_bind omp_lib)
478+
configure_file(${FTN_FILE}.F95 ${FTN_FILE}_static.F95 COPYONLY)
479+
endforeach()
480+
configure_file(iso_fortran_env.f90 iso_fortran_env_static.f90 COPYONLY)
486481

487-
add_library(ieee_arithmetic OBJECT
482+
SET(FTN_SUPPORT_SHARED
488483
ieee_arithmetic.F95
489484
ieee_exceptions.F95
485+
iso_c_bind.F95
486+
ieee_features.F95
487+
iso_fortran_env.f90
488+
)
489+
490+
SET(FTN_SUPPORT_STATIC
491+
ieee_arithmetic_static.F95
492+
ieee_exceptions_static.F95
493+
iso_c_bind_static.F95
494+
ieee_features_static.F95
495+
iso_fortran_env_static.f90
496+
)
497+
498+
SET(FTN_SUPPORT
499+
${FTN_SUPPORT_STATIC}
500+
${FTN_SUPPORT_SHARED}
501+
${FTN_SUPPORT_COMMON}
502+
)
503+
504+
SET(FTN_INTRINSICS_STATIC
505+
omp_lib_static.F95
506+
)
507+
508+
SET(FTN_INTRINSICS_SHARED
509+
omp_lib_static.F95
490510
)
491511

492512
add_flang_library(flang_static
493513
${FTN_INTRINSICS}
494-
${FTN_SUPPORT}
514+
${FTN_INTRINSICS_STATIC}
515+
${FTN_SUPPORT_COMMON}
516+
${FTN_SUPPORT_STATIC}
495517
${SHARED_SOURCES}
496518
)
497519

@@ -501,10 +523,30 @@ else()
501523
set_property(TARGET flang_static PROPERTY OUTPUT_NAME flang)
502524
endif()
503525

526+
set_target_properties(flang_static PROPERTIES Fortran_MODULE_DIRECTORY ${FLANG_MODULE_DIRECTORY_STATIC})
527+
528+
# State the module that the source is producing
529+
set_source_files_properties(
530+
iso_c_bind_static.F95
531+
PROPERTIES
532+
OBJECT_OUTPUTS ${FLANG_MODULE_DIRECTORY_STATIC}/iso_c_binding.mod
533+
)
534+
535+
# State a dependency on the module
536+
set_source_files_properties(
537+
ieee_arithmetic_static.F95
538+
ieee_exceptions_static.F95
539+
PROPERTIES
540+
OBJECT_DEPENDS ${FLANG_MODULE_DIRECTORY_STATIC}/iso_c_binding.mod
541+
)
542+
504543
set(SHARED_LIBRARY TRUE)
544+
505545
add_flang_library(flang_shared
506546
${FTN_INTRINSICS}
507-
${FTN_SUPPORT}
547+
${FTN_INTRINSICS_SHARED}
548+
${FTN_SUPPORT_COMMON}
549+
${FTN_SUPPORT_SHARED}
508550
${SHARED_SOURCES}
509551
)
510552
set_property(TARGET flang_shared PROPERTY OUTPUT_NAME flang)
@@ -515,6 +557,22 @@ if (NOT MSVC)
515557
else()
516558
set_target_properties(flang_shared PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
517559
endif()
560+
set_target_properties(flang_shared PROPERTIES Fortran_MODULE_DIRECTORY ${FLANG_MODULE_DIRECTORY_SHARED})
561+
562+
# State the module that the source is producing
563+
set_source_files_properties(
564+
iso_c_bind.F95
565+
PROPERTIES
566+
OBJECT_OUTPUTS ${FLANG_MODULE_DIRECTORY_SHARED}/iso_c_binding.mod
567+
)
568+
569+
# State a dependency on the module
570+
set_source_files_properties(
571+
ieee_arithmetic.F95
572+
ieee_exceptions.F95
573+
PROPERTIES
574+
OBJECT_DEPENDS ${FLANG_MODULE_DIRECTORY_SHARED}/iso_c_binding.mod
575+
)
518576

519577
set(SHARED_LIBRARY FALSE)
520578

@@ -579,25 +637,14 @@ target_include_directories(flang_shared
579637
add_dependencies(flang_static
580638
flang1
581639
flang2
582-
ieee_arithmetic
583640
)
584641

585642
# Make sure the compiler is built before we bootstrap
586643
add_dependencies(flang_shared
587644
flang1
588645
flang2
589-
ieee_arithmetic
590646
)
591647

592-
add_dependencies(iso_c_bind
593-
flang1
594-
flang2
595-
)
596-
597-
add_dependencies(ieee_arithmetic
598-
iso_c_bind
599-
)
600-
601648
if (NOT MSVC)
602649
target_compile_options(flang_static PRIVATE -fPIC)
603650
target_compile_options(flang_shared PRIVATE -fPIC)

0 commit comments

Comments
 (0)