-
Notifications
You must be signed in to change notification settings - Fork 23
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
various issues with linking modes #70
Comments
I have been bitten by this too. I guess? Cause my expertise in this area could be much higher. Thanks for your patience. There is only one maintainer on this level. |
I've got some experience developing distributions, which does lead to somewhat better familiarity with the whole process.
No worries! I'm quite aware of what it's like to have limited output (on top of the usual internet-related ADD and similar, I am also chronically ill) and have no complaints on the overall, so long as things do get dealt with eventually. If there's anything else I can do to help (albeit in my limited capacity as it is, and given the skills I have (and more importantly those I don't)), please do tell me. |
It's been a while since I have looked at this, and also a while since this was filed, but better late than never - thanks for looking at this. For legacy reason we have both |
ldflags and lflags are basically the same now, just lflags is what gets injected by jpm where as ldflags is more user controlled. There is a possibility this affects existing code and breaks builds.
Would a good way to improve the situation definitively be to write a jpm alternative for POSIX-compatible platforms (I can't reliably test or predict windows behavior, I don't really work with it), aiming for proper handling of everything? |
Jpm really does need a bit of a rewrite, especially for posix compatible stuff. Ideally, it would be part of spork as well for easier setup. I had somewhat planned this for a while, as there are other issues with JPM's interface that are confusing and hard to reuse. JPM began as an opinionated build tool more than a full on package manager, so it doesn't deal with dependencies ideally - issues with pkg-config and such aren't as much of an issue if you are building everything in one project.janet. A number of issues that would be good to change:
Another idea is that project.janet should be executable as normal scripts - no implicit imports. Hypothetical # JPM analog in spork with aforementioned changes.
(import spork/project :as pj)
(pj/defproject
:name "..."
...)
(pj/declare-executable
...)
# Generate a main function that has subcommands for build, test, deps, etc.
# Also validate the built up project state.
(pj/generate-main) I think once posix works, it would be doable to make MSVC work as well as most of the general procedures are fairly similar, although Windows dynamic linking works differently than linux/posix. However, there are a number of functionalities in popular package managers that I don't think are very good, including support for multiple versions of the same packages, and semantic versioning. |
@bakpakin Would you mind elaborating on this point:
Is this about the theoretical possibiliity of multiple versions of the same packages or specifically the way it has been done elsewhere? In general, I'm not a fan of regularly using multiple versions of the same package and realize there can be issues if different versions of a particular package are not written to coexist with each other, but I have found that being able to do so in certain situations has been helpful in getting things to work out. |
My point is that practically, it doesn't work very well because of native dependencies. Of course it is possible to implement, but you add complexity for questionable value. This "feature" from the npm world seems great if you never lift the curtain and see the waste, complexity, and fragility, but there are plenty of mainstream package managers that take a different approach - separate versions live in separate trees. |
Thanks for the point about the native dependencies. (I don't really have experience with using multiple versions from npm (I'm not at all a fan having suffered from the related churn multiple times). I had issues with not being able to use multple versions of things elsewhere and having to resort to unfortunate renaming hacks.) The type of situation I have concerns with was described by @ianthehenry in the "Modules and Packages" chapter of "Janet for Mortals":
I think what's meant here is using the current jpm dependencies mechanism. What I've started to do recently is to use Perhaps this kind of situation could be handled using this idea you mentioned elsewhere?
[1] I think it can make a lot of sense for developer tools though. |
When linking a native module that includes external linkage (such as
jurl
), theldflags
(i.e libs) must be specified after the-shared
flag, else the shared object will not hold the library references in its dynamic section.For example, when building jurl on my server.
With jpm as it is, the command line is:
cc -std=c99 -I/usr/local/include/janet -I/usr/local/lib/janet -O2 -lcurl -o build/jurl/native.so build/src...o -shared -lpthread
The correct command line is:
cc -std=c99 -I/usr/local/include/janet -I/usr/local/lib/janet -O2 -o build/jurl/native.so build/src...o -shared -lpthread -lcurl
Testing is trivial using
readelf -d build/jurl/native.so
.When building with jpm as it is, output starts as such:
When built with the correct command line, output starts as such:
The consequence of this is that when later linking against
jurl/native.so
, the former will not imply-lcurl
, and thus it will have to be inserted manually - something jpm does not do.When linking dynamically, it's generally ok for the symbols to only become available later, so dynamic-linking-related invocations in
link-cc
should likely specify;ldflags
at the end of the command line rather than near the start.Furthermore, this is also related to a separate issue making static linking difficult even when it is available.
When both a dynamic and a static version of a given library is accessible, most (so including gcc and clang) C compilers will default to preferring the dynamic version of the library (which is likely why jpm currently specifies static libraries for janet and static native modules using their paths rather than
-l
flags).The correct way of resolving this is passing a
-static
flag in front of any-l
s that are available statically, and then a-dynamic
flag in front of any-l
s that are not.Alternatively, jpm could take a
:static
argument (on quickbin and on declare-executable) and prefix;ldflags
with-static
when it is enabled (hard fail if any library is unavailable).While I could try patching jpm and opening a PR at this stage (I have some rough patches around), it's probably important to see what the actual maintainers think (especially given the relatively low level of activity around the tooling and janet itself, e.g I've had #janet/1097 open for about a week; which is not an issue but pushes me in the direction of discussing first, patching later).
The text was updated successfully, but these errors were encountered: