Skip to content

Refactor iree_bytecode_module and iree_c_module static lib support - #10238

Merged
hcindyl merged 4 commits into
iree-org:mainfrom
hcindyl:cmake-cleanup1
Aug 30, 2022
Merged

hcindyl merged 4 commits into
iree-org:mainfrom
hcindyl:cmake-cleanup1

Conversation

@hcindyl

@hcindyl hcindyl commented Aug 30, 2022

Copy link
Copy Markdown
Contributor

Add STATIC_LIB_PATH option instead of parsing the compiler flags

Add STATIC_LIB_PATH option instead of parsing the compiler flags
endif()
endforeach(_FLAG)
if(_RULE_STATIC_LIB_PATH)
list(APPEND _ARGS "--iree-hal-target-backends=llvm-cpu")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh I missed that we weren't already passing the backend as an explicit cmake arg. That makes this way of doing things a bit more weird (because now if I switch from non-static to static lib I drop the target arg). I still think it's better though

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can leave the target backend flag outside of the iree_*_module macro, although in L53 we still want to check the setting condition as

if(_RULE_STATIC_LIB_PATH AND NOT IREE_TARGET_BACKEND_LLVM_CPU)
    message(SEND_ERROR "Static library only supports llvm-cpu backend")
  endif()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I wasn't saying change it, necessarily. What you have now and what you had before that last commit are both fine :-) I think the ideal given we're doing things based on backend would be to have the backend as an explicit arg also, but I'm not going to punish you with extra work just because you touched this rule :-P

Match the input arguments for CMake `iree_*_modules` functions.
@hcindyl

hcindyl commented Aug 30, 2022

Copy link
Copy Markdown
Contributor Author

As discussed offline, add the corresponding iree_*_module bazel rules to make the interface consistent (although there is currently no e2e static linker target in bazel). @GMNGeoffrey, please take another look, thanks!

@hcindyl
hcindyl requested a review from GMNGeoffrey August 30, 2022 03:46
Comment on lines +47 to +57
out_files = [module_name]
module_flags = ["--output-format=vm-bytecode"]
if static_lib_path:
static_header_path = static_lib_path.replace(".o", ".h")
out_files.extend([static_lib_path, static_header_path])
module_flags.extend([
"--iree-llvm-link-embedded=false",
"--iree-llvm-link-static",
"--iree-llvm-static-library-output-path=$(location %s)" % (static_lib_path),
])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than creating a separate variable and then adding it on, just use the single variable "flags" and extend it with the new stuff? I think Starlark does away with some of Python's foot-gun reference semantics so modifying the list passed in shouldn't be a problem (if it is, you can also use += instead of extend/append). Note that this is slightly different than what you have semantically because it adds the rule's flags at the end instead of the beginning. I'm not sure whether that's practically a difference. If it is, it's probably better to leave as you have it with the user-provided flags at the end

Suggested change
out_files = [module_name]
module_flags = ["--output-format=vm-bytecode"]
if static_lib_path:
static_header_path = static_lib_path.replace(".o", ".h")
out_files.extend([static_lib_path, static_header_path])
module_flags.extend([
"--iree-llvm-link-embedded=false",
"--iree-llvm-link-static",
"--iree-llvm-static-library-output-path=$(location %s)" % (static_lib_path),
])
out_files = [module_name]
flags.append("--output-format=vm-bytecode")
if static_lib_path:
static_header_path = static_lib_path.replace(".o", ".h")
out_files.extend([static_lib_path, static_header_path])
flags.extend([
"--iree-llvm-link-embedded=false",
"--iree-llvm-link-static",
"--iree-llvm-static-library-output-path=$(location %s)" % (static_lib_path),
])

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buildifier accepts += to replace extend, but it still prefers append over +=. Made the change based on the feedback and the buildifier result.

Comment thread build_tools/bazel/iree_c_module.bzl Resolved
@hcindyl
hcindyl merged commit 726c592 into iree-org:main Aug 30, 2022
@hcindyl
hcindyl deleted the cmake-cleanup1 branch October 12, 2022 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants