-
Notifications
You must be signed in to change notification settings - Fork 597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft: Build OR shared libraries for PIP distribution #2311
Conversation
Signed-off-by: Ethan Mahintorabi <[email protected]>
84ea93c
to
cc726e4
Compare
set_property(SOURCE ${ARG_I_FILE} | ||
PROPERTY USE_SWIG_DEPENDENCIES TRUE) | ||
set_property(SOURCE ${ARG_I_FILE} | ||
PROPERTY USE_TARGET_INCLUDE_DIRECTORIES true) | ||
|
||
|
||
if (ARG_SHARED_LIBRARY) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://cmake.org/cmake/help/latest/module/UseSWIG.html seems to have a USE_BUILD_SHARED_LIBS
option to achieve something similar.
@@ -62,16 +62,29 @@ function(swig_lib) | |||
-Werror | |||
-w317,325,378,401,402,467,472,503,509) | |||
|
|||
set_property(SOURCE ${ARG_I_FILE} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should swig be able to infer this from the %module
decl
from setuptools.command.build_ext import build_ext as build_ext_orig | ||
|
||
|
||
class CMakeExtension(Extension): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about reusing something like https://github.com/diegoferigo/cmake-build-extension?
${OPENROAD_TOOL_LIBS} | ||
) | ||
|
||
target_link_libraries(openroad |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be libopenroad
? (or removed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah my bad, that's for the executable.
@@ -293,6 +297,24 @@ target_link_libraries(openroad | |||
${CMAKE_THREAD_LIBS_INIT} | |||
) | |||
|
|||
add_library(libopenroad |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this also be linked against the optional import below (zlib
, cudd
, etc)
@@ -293,6 +297,24 @@ target_link_libraries(openroad | |||
${CMAKE_THREAD_LIBS_INIT} | |||
) | |||
|
|||
add_library(libopenroad | |||
${OPENROAD_LIB_SRCS} | |||
OpenRoad-py.cc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious if that could be a regular c++ library (i.e: drop the OpenRoad-py.cc
dummy file) and have the main binary link against it rather than using OPENROAD_LIB_SRCS
?
Thanks for working on this @QuantamHD! Made a few comments, let me know if you'd prefer me to do propose the change directly against your branch. |
authors = [ | ||
{ name = "Matt Liberty", email = "[email protected]"} | ||
] | ||
description = "A production ready opensource physical design EDA toolkit" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"production-ready open-source"
Also maybe drop "production-ready" to not convey a bug-free experience :)
|
||
[project] | ||
name = "openroad" | ||
version = "0.0.1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What parses the version number and is this going to break things when it doesn't match the source code version? Can this be generated by cmake?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using a pyproject.toml.in
with some @CMAKE_VARIABLES@
or generator expression should be easy
e.g.
A "template" file (here setup.py.in but could be a toml.in file ;))
https://github.com/Mizux/python-native/blob/14648387a267b8ce65db0c0cdd47c1200c8cd7fb/python/setup.py.in#L16-L18
And the CMake stuff to auto-replace...
https://github.com/Mizux/python-native/blob/14648387a267b8ce65db0c0cdd47c1200c8cd7fb/cmake/python.cmake#L173-L181
Last step a custom_command to generate the python package (1 create a the package layout layout with all files in the build dir, 2) ask python to package wheel our stuff, 3) profit !)
https://github.com/Mizux/python-native/blob/14648387a267b8ce65db0c0cdd47c1200c8cd7fb/cmake/python.cmake#L197-L237
What needs to happen next here? This seems stalled |
We need to complete the librarification of the rest of the openroad modules. |
It seems this could proceed in parallel. |
@QuantamHD @proppy any further plans or close? |
@maliberty I do have interest into landing something like this in the conda package for OpenROAD: https://github.com/hdl/conda-eda/tree/master/pnr/openroad to ease the usage from colab notebooks. |
@proppy is there a timeline? As I said earlier "It seems this could proceed in parallel." so I think you are unblocked from progress. |
Another pattern/reference here that we could reuse/take inspiration from is https://github.com/Mizux/cmake-swig (which I believe is what @Mizux uses for packaging https://github.com/google/or-tools). |
@proppy we already have swig setup with cmake. The main point here is about pip packaging |
For python only I would look at:
|
@maliberty but my understanding is that what this PR (despite its title) is trying to address is more building the swig binding as a shared library importable from python #2308 rather than addressing the distribution on pypi #1424 (ultimately we need both, but one need to happen before the other) |
@Mizux thanks for sharing, that's an awesome reference! |
There is no question about how to build the python bindings and we've already done a lot of work in that direction and don't plan to change course. The only question is about building shared libraries. This PR contains python/pyproject.toml which seems related to pip distribution. If the title is wrong, please fix it. |
Yeah let me signal boost @maliberty. The bindings part is already solved we have a defined C++ public API that's SWIG'd. The only question is building the shared libraries such that they don't require the giant OpenROAD object that forces you to link the entire app for the library. @cdleary and I did a bunch of work to separate libraries (gpl, grt, etc.) into library components which should make this easier. There's probably still challenges around logging, and cmake config to be solved. |
Thanks @QuantamHD |
There's actually a problem building it with the whole app. It won't link because it's pulling in main symbols which python will reject. The project is currently achieving python by linking a runtime in, and that's incompatible with pip who wants you to link into the user's arbitrary runtime. |
I didn't mean that quite so literally. I just meant making a single .so for everything but Main.cc is tolerable. |
A single .so is still the goal, it's just a question of actually getting one of those that actually works with pip that's the hard part. I was just pointing out one problem I ran into that stopped progress on this PR. Pulling out Main.cc wasn't as trivial as I expected it to be. |
@QuantamHD I'm missing something here. The work you and Chris did was so you could use a single library in near isolation for unit testing. How does that relate to building a single .so? What are the issues with pulling out Main? |
It's all related @maliberty. I don't recall the exact details, but there's something in Main that the OpenROAD object depends on, and without it none of the logging builds. |
Sorry for the miss-understanding: I do agree all step to get there are inter-related, I just thought it would be beneficial to talk about them in isolation. |
It would be helpful if this PR were brought up to date. Please give a clear statement of the specific issue to be solved is given. All I know is that "something in Main that the OpenROAD object depends on..." but that isn't enough to take any action. |
Its also confusing that the title says Draft but this isn't actually a draft PR. Is this seeking help or just in progress? |
It was draft because it was broken. I don't really have time to work on it at the moment. So this is basically scaffolding that some can pick up, or if no one is interested then it can be closed, and I'll pick it up again when I have more time to focus on this. |
No description provided.