Skip to content

Commit

Permalink
[OpenMP][Build][Wasm][116552] Fixed build problem when compiling with…
Browse files Browse the repository at this point in the history
… Emscripten on Windows (llvm#116874)
  • Loading branch information
maniatic0 authored Nov 20, 2024
1 parent 08e7609 commit 05bcf83
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
10 changes: 8 additions & 2 deletions openmp/runtime/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,22 @@ if(${LIBOMP_OMPT_SUPPORT})
endif()

# Generate message catalog files: kmp_i18n_id.inc and kmp_i18n_default.inc
set(LIBOMP_MESSAGE_CONVERTER_EXTRA_ARGS "")
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Emscripten")
# Required as Python doesn't inherit CMake's environment setup and uses the host system as the target system by default
set(LIBOMP_MESSAGE_CONVERTER_EXTRA_ARGS ${LIBOMP_MESSAGE_CONVERTER_EXTRA_ARGS} --target-system-override=${CMAKE_SYSTEM_NAME})
endif()

add_custom_command(
OUTPUT kmp_i18n_id.inc
COMMAND ${Python3_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/message-converter.py
--enum=kmp_i18n_id.inc ${LIBOMP_SRC_DIR}/i18n/en_US.txt
--enum=kmp_i18n_id.inc ${LIBOMP_MESSAGE_CONVERTER_EXTRA_ARGS} ${LIBOMP_SRC_DIR}/i18n/en_US.txt
DEPENDS ${LIBOMP_SRC_DIR}/i18n/en_US.txt ${LIBOMP_TOOLS_DIR}/message-converter.py
)
add_custom_command(
OUTPUT kmp_i18n_default.inc
COMMAND ${Python3_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/message-converter.py
--default=kmp_i18n_default.inc ${LIBOMP_SRC_DIR}/i18n/en_US.txt
--default=kmp_i18n_default.inc ${LIBOMP_MESSAGE_CONVERTER_EXTRA_ARGS} ${LIBOMP_SRC_DIR}/i18n/en_US.txt
DEPENDS ${LIBOMP_SRC_DIR}/i18n/en_US.txt ${LIBOMP_TOOLS_DIR}/message-converter.py
)

Expand Down
39 changes: 37 additions & 2 deletions openmp/runtime/tools/message-converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,32 @@
from libomputils import ScriptError, error


class TargetPlatform:
"""Convenience class for handling the target platform for configuration/compilation"""

system_override = None
"""
Target system name override by the user.
It follows the conventions from https://docs.python.org/3/library/platform.html#platform.system
"""

def set_system_override(override_system):
"""
Set a system override for the target.
Please follow the style from https://docs.python.org/3/library/platform.html#platform.system
"""
TargetPlatform.system_override = override_system

def system():
"""
Target System name.
It follows the conventions from https://docs.python.org/3/library/platform.html#platform.system
"""
if TargetPlatform.system_override is None:
return platform.system()
return TargetPlatform.system_override


class ParseMessageDataError(ScriptError):
"""Convenience class for parsing message data file errors"""

Expand Down Expand Up @@ -55,7 +81,7 @@ def __init__(self, lineNumber, name, text):
self.text = text

def toSrc(self):
if platform.system() == "Windows":
if TargetPlatform.system().casefold() == "Windows".casefold():
return re.sub(r"%([0-9])\$(s|l?[du])", r"%\1!\2!", self.text)
return str(self.text)

Expand Down Expand Up @@ -363,6 +389,13 @@ def main():
parser.add_argument(
"--message", metavar="FILE", help="Generate message file named FILE"
)
parser.add_argument(
"--target-system-override",
metavar="TARGET_SYSTEM_NAME",
help="Target System override.\n"
"By default the target system is the host system\n"
"See possible values at https://docs.python.org/3/library/platform.html#platform.system",
)
parser.add_argument("inputfile")
commandArgs = parser.parse_args()

Expand All @@ -371,14 +404,16 @@ def main():
return
data = MessageData.create(commandArgs.inputfile)
prefix = commandArgs.prefix
if commandArgs.target_system_override:
TargetPlatform.set_system_override(commandArgs.target_system_override)
if commandArgs.enum:
generate_enum_file(commandArgs.enum, prefix, data)
if commandArgs.default:
generate_default_messages_file(commandArgs.default, prefix, data)
if commandArgs.signature:
generate_signature_file(commandArgs.signature, data)
if commandArgs.message:
if platform.system() == "Windows":
if TargetPlatform.system().casefold() == "Windows".casefold():
generate_message_file_windows(commandArgs.message, data)
else:
generate_message_file_unix(commandArgs.message, data)
Expand Down

0 comments on commit 05bcf83

Please sign in to comment.