Skip to content
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

nu: fix build on Linux #104928

Closed
wants to merge 1 commit into from
Closed

nu: fix build on Linux #104928

wants to merge 1 commit into from

Conversation

danielnachun
Copy link
Member

  • Have you followed the guidelines for contributing?
  • Have you ensured that your commits follow the commit style guide?
  • Have you checked that there aren't other open pull requests for the same formula update/change?
  • Have you built your formula locally with brew install --build-from-source <formula>, where <formula> is the name of the formula you're submitting?
  • Is your test running fine brew test <formula>, where <formula> is the name of the formula you're submitting?
  • Does your build pass brew audit --strict <formula> (after doing brew install --build-from-source <formula>)? If this is a new formula, does it pass brew audit --new <formula>?

@danielnachun danielnachun added the CI-no-bottles Merge without publishing bottles label Jul 2, 2022
@BrewTestBot BrewTestBot added no ARM bottle Formula has no ARM bottle no Linux bottle Formula has no Linux bottle labels Jul 2, 2022
@danielnachun danielnachun added the ready to merge PR can be merged once CI is green label Jul 4, 2022
@danielnachun danielnachun requested a review from a team July 5, 2022 16:55
Formula/nu.rb Outdated
def install
ENV.delete("SDKROOT") if MacOS.version < :sierra
ENV["PREFIX"] = prefix
# Some gnustep-make scripts located in libexecA.
ENV.append_path "PATH", Formula["gnustep-make"].libexec unless OS.mac?
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this into the unless block below?

Formula/nu.rb Outdated
"-L#{Formula["swift"].libexec}/lib/swift/linux"
"-Wl,-rpath,#{Formula["swift"].libexec}/lib/swift/linux"
]
inreplace "Makefile", "LDFLAGS = ", "LDFLAGS = #{ldflags.join(" ")}"
Copy link
Member

Choose a reason for hiding this comment

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

We can't pass these LDFLAGS to make? Or use #change_make_var!?

Copy link
Member Author

Choose a reason for hiding this comment

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

I missed this comment earlier. Unfortunately the line I was replacing is the one which seems to reset the LDFLAGS so passing it in doesn't work. Further complicating matters, the way the LDFLAGS are constructed in the Makefile seems incompatible with change_make_var:

LDFLAGS =
LDFLAGS += $(FRAMEWORKS)
LDFLAGS += $(LIBS)
LDFLAGS += $(LIBDIRS)
LDFLAGS += $(FFI_LIB)
ifeq ($(SYSTEM), Darwin)
else
        #LDFLAGS += $(shell gnustep-config --base-libs)
ifneq ($(SYSTEM), SunOS)
        LDFLAGS += -Wl,--rpath -Wl,/usr/local/lib

#LDFLAGS += `gnustep-config --debug-flags`
LDFLAGS += -L/usr/local/lib
LDFLAGS += -ldispatch
LDFLAGS += -lgnustep-base
# LDFLAGS += -lgnustep-gui
LDFLAGS += -L/usr/lib/GNUstep

So as far as I can tell inreplace seems to be the only way for this to work.

Copy link
Member Author

Choose a reason for hiding this comment

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

And as soon as I pasted that, I realized I had missed that LIBDIRS is not overridden in the Makefile. I was able to pass in the flags just by setting it in env, which is much cleaner than the inreplace. I'll push this change now.

Copy link
Member

Choose a reason for hiding this comment

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

If you want to use LDFLAGS just add the flags you want to ENV.ldflags then pass "LDFLAGS=#{ENV.ldflags}" to make.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried that and it doesn't seem to work because the first line in that part of the Makefile is LDFLAGS = , which I believe has the effect of resetting the LDFLAGS even if I pass them in as an argument. I think if they were just using += for all the assignments it would work as you described and that's indeed what is done with LIBDIRS, hence why it works.

Formula/nu.rb Outdated
]
inreplace "Makefile", "LDFLAGS = ", "LDFLAGS = #{ldflags.join(" ")}"
# Don't hard code path to clang.
inreplace "tools/nuke", "/usr/bin/clang", ENV.cc
Copy link
Member

Choose a reason for hiding this comment

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

We might want to do this on macOS too.

Formula/nu.rb Outdated
Comment on lines 49 to 51
inreplace "objc/NuBridge.h", "x86_64-linux-gnu/", ""
inreplace "objc/NuBridge.m", "x86_64-linux-gnu/", ""
inreplace "objc/Nu.m", "x86_64-linux-gnu/", ""
Copy link
Member

Choose a reason for hiding this comment

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

Pass an Array to inreplace since these are all the same.

Formula/nu.rb Outdated

# Nu does not (yet) support the GNUstep 2.0 Objective C runtime so it must use 1.9.
# If this flag is not changed from its default, the linker fails to find some symbols.
inreplace "Nukefile", "-fgnu-runtime", "-fobjc-runtime=gnustep-1.9"
Copy link
Member

Choose a reason for hiding this comment

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

Hard-coding the 1.9 here seems really prone to bitrot.

Copy link
Member Author

Choose a reason for hiding this comment

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

As documented here: https://github.com/gnustep/libobjc2, this is a defined standard whose version won't change over time. We should check with new releases if the 2.0 run time is supported. Maybe I should add this to comment?

Copy link
Member

Choose a reason for hiding this comment

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

Yes. Along with links to documentation, and how to tell when nu supports the newer runtime.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have an interesting update to this. The problem was the the Nukefile was also setting -DGNU_RUNTIME=1, which will result in the compiler trying to find symbols for the GNU runtime. However if I remove -DGNU_RUNTIME=1 and -fgnu-runtime from the CFLAGS, it automatically picks the the 1.9 run time without having to explicitly specify it.

I believe this is essentially aligning it with what happens on macOS and should avoid bitrot as we're just removing some irrelevant flags. If they decide to move to the Objective-C 2.0 runtime, upstream will have to remove these flags on Linux and the workaround will not be needed anymore. I will update the comment to explain this.

@BrewTestBot
Copy link
Member

🤖 A scheduled task has triggered a merge.

@carlocab
Copy link
Member

ARM build failure is an upstream issue -- they're still looking for a /usr/lib/libffi.dylib.

Filed programming-nu/nu#100.

@danielnachun danielnachun deleted the nu branch July 13, 2022 15:39
@github-actions github-actions bot added the outdated PR was locked due to age label Aug 13, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CI-no-bottles Merge without publishing bottles no ARM bottle Formula has no ARM bottle no Linux bottle Formula has no Linux bottle outdated PR was locked due to age ready to merge PR can be merged once CI is green
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants