-
Notifications
You must be signed in to change notification settings - Fork 41
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
Build reapi_cli as a shared library #1120
Conversation
@milroy this is fantastic! 🙌 For a quick example of what this enables, I was (very easily) able to build a go module out of tree: https://github.com/converged-computing/flex-ice-cream And specifically, the compile command from the root: GOOS=linux CGO_CFLAGS="-I/opt/flux-sched/resource/reapi/bindings/c" \
CGO_LDFLAGS="-L/usr/lib -L/opt/flux-sched/resource -lfluxion-resource \
-L/opt/flux-sched/resource/libjobspec -ljobspec_conv -L//opt/flux-sched/resource/reapi/bindings \
-lreapi_cli -lflux-idset -lstdc++ -lczmq -ljansson -lhwloc -lboost_system -lflux-hostlist \
-lboost_graph -lyaml-cpp" go build -ldflags '-w' -o bin/server src/fluence/cmd/main.go For go libraries, it is much nicer (and expected by developers) to have go.mod and go.sum in the root of the repository. I tested the above and found I could use the (new?) This dummy example builds fluence, and I'll quickly be changing that to something that is not fluence (and likely deleting the git history in case there is issue having it in two spots). I used fluence because it was the quickest way to prototype/test the bindings and give feedback here, and could be compared against the "fudged version" from flux-framework/flux-k8s#47. When work is merged here, we will want to use these bindings there (and good to sanity check it will build). For now I'm using a fork of the work here, and only because I need to change the module name to match the repository in go.mod (go does not allow you to use, for example, a go.mod with @trws and @grondo I hope you are excited about this, because it means we (and other developers) can easily build cool stuff with fluxion! I am going to make an attempt soon to prototype what I wanted to do with ice cream, and from that we will likely identify some of the missing pieces (go or c bindings here) that are needed. We've already anticipated some of these needs (and I opened issues earlier this week). Thank you in advance for the reviews! |
Update: library is now officially ice-cream-ized: https://github.com/converged-computing/flex-ice-cream It's not perfect, but it's a start! I made sure to nuke the fluence history so there wouldn't be worry about having it there. Going back to sleep, thanks again for the work here and TBA review! |
Glad it works, it feels a little odd to need to make the cli a shared library? Is there something in there we should move to something meant to be an external interface? |
Here is what we needed in fluence: https://github.com/flux-framework/flux-k8s/blob/105562e4662e86a1b8ce1e19762678a6c0dd6309/src/fluence/fluxion/fluxion.go Primarily to make a reapi client and then interact with it! f.cli = fluxcli.NewReapiClient() |
6cdc599
to
ec09cdf
Compare
Dropping WIP. I drastically simplified this PR and reduced the API surface by linking the static Fluxion |
The build works - this is a development container that installs flux-sched from your branch (with the go path tweaked) and then just runs make: The compile command: GOOS=linux CGO_CFLAGS="-I/opt/flux-sched/resource/reapi/bindings/c" CGO_LDFLAGS="-L/usr/lib -L/opt/flux-sched/resource/libjobspec -ljobspec_conv -lflux-idset -lstdc++ -lczmq -ljansson -lhwloc -lboost_system -lflux-hostlist -lboost_graph -lyaml-cpp -L//opt/flux-sched/resource/reapi/bindings -lreapi_cli" go build -ldflags '-w' -o bin/icecream src/cmd/main.go And can confirm the .so is installed. find /usr -name libreapi_cli.so
/usr/lib/flux/libreapi_cli.so The flux .so is installed to a non-traditional place, so not an issue to add that to ./bin/icecream
./bin/icecream: error while loading shared libraries: libreapi_cli.so: cannot open shared object file: No such file or directory
export LD_LIBRARY_PATH=/usr/lib/flux But I think we are still missing one library: ./bin/icecream
./bin/icecream: error while loading shared libraries: libjobspec_conv.so: cannot open shared object file: No such file or directory Which seems to still be in the install root: find /opt/flux-sched/ -name libjobspec_conv.so
/opt/flux-sched/resource/libjobspec/libjobspec_conv.so
find /usr -name libjobspec_conv.so
# no output |
Ok, I updated the PR to install |
@vsoch I did some additional simplification and cleanup that further reduces the complexity of linking Fluxion. Can you test again and make sure this works before I squash the fixup commits? You shouldn't need to link |
Pending the style question and the commit validation getting fixed up I'm good here, and will approve. |
Just an opinion, but yes, installing Flux libraries with generic names like |
Oh just to be clear, I'm okay with it being under flux, and think that's the better design. |
Agreed. |
@vsoch do you mean that you're okay with installation of @grondo regardless of the installation path do you recommend that I add a prefix ( |
Yes. |
Problem: clients may use different licenses than Fluxion. Build `reapi_cli` as a shared library to enforce license boundaries. Link against the Fluxion resource library to include necessary symbols and install `reapi_cli` to FLUX_LIB_DIR.
Problem: the Go test links against unnecessary libraries such as Fluxion resource, reapi_module, and flux::core. Furthermore, the options are a long, unwrapped string which is hard to read. Remove the unnecessary entries in the CGO_LIBRARY_FLAGS and make the presentation more readable. Update GolangSimple.cmake to remove string replacement of " " with ";" which causes the list expansion to fail.
Problem: the Go test links against shared libraries such as libreapi_cli but the LD_LIBRARY_PATH isn't set in the Go test. Set LD_LIBRARY_PATH appropriately.
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.
Looks great to me, good stuff. 👍
Thanks for the reviews! Setting MWP. |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #1120 +/- ##
======================================
Coverage 70.6% 70.6%
======================================
Files 94 94
Lines 12723 12723
======================================
Hits 8984 8984
Misses 3739 3739 |
PR #1094 Updated Fluxion to be build as a static library. Some projects like Fluence are clients of Fluxion and its REAPI and need to link Fluxion libraries as shared libraries to preserve license boundaries. This PR adds the capability to build the necessary shared libraries.