Skip to content
This repository has been archived by the owner on Aug 2, 2020. It is now read-only.

Build dynamic libs #325

Merged
merged 1 commit into from
Jun 26, 2017
Merged

Build dynamic libs #325

merged 1 commit into from
Jun 26, 2017

Conversation

izgzhen
Copy link
Collaborator

@izgzhen izgzhen commented Jun 14, 2017

Solve #4

@izgzhen
Copy link
Collaborator Author

izgzhen commented Jun 14, 2017

It can successful compile a hello-world dynamically now:

inplace/bin/ghc-stage2 -dynamic --make ~/Desktop/Playground/Main.hs

@snowleopard
Copy link
Owner

snowleopard commented Jun 14, 2017

@izgzhen Whoa, hang on, you're moving too fast! You were supposed to start the Summer of Haskell yesterday, but you already resolved the two main issues :D

I'll do my best to review both PRs tomorrow -- today's is a bit busy.

@izgzhen
Copy link
Collaborator Author

izgzhen commented Jun 14, 2017

I'll do my best to review both PRs tomorrow -- today's is a bit busy.

:-) Take your time, thanks

, libraryWays = append [vanilla]
, libraryWays = mconcat
[ append [vanilla]
, notStage0 ? platformSupportsSharedLibs ? append [dynamic] ]
Copy link
Owner

Choose a reason for hiding this comment

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

The quickest flavour is supposed to be the quickest one that produces a working GHC, to be used by CI bots and avoid time limits, so I suggest we stick to pure vanilla.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But this is not consistent with the behavior of quickest flavor specified in mk/build.mk. I remember that dynamic libs will be produced in that one. Will it be a surprise if we redefine this?

Copy link
Owner

Choose a reason for hiding this comment

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

The difference between quick and quickest in the Make build system seemed too marginal to me, so I thought it would be better to deviate from the existing definition. The quickest flavour should be the one that can't be beaten in terms of speed or else why name it this way :)

At the moment, quickest in Hadrian is already different, so I suggest not to try to change this in this PR. This discussion deserves a separate issue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That makes sense.

src/Rules.hs Outdated
@@ -61,6 +61,10 @@ packageRules = do
[ Rules.Compile.compilePackage readPackageDb
, Rules.Library.buildPackageLibrary ]

let dynContexts = liftM3 Context [Stage1 ..] knownPackages [dynamic]
Copy link
Owner

Choose a reason for hiding this comment

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

I am not a fan of using contractions. Can we use dynamic throughout the code instead of dyn? This will be more consistent with the rest of Hadrian.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good

mconcat [ arg "-no-auto-link-packages"
mconcat [ (Dynamic `wayUnit` way) ?
append [ "-shared", "-dynamic", "-dynload", "deploy" ]
, arg "-no-auto-link-packages"
Copy link
Owner

Choose a reason for hiding this comment

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

I'm confused why -no-auto-link-packages is not included in the above append.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Isn't it still on the line after the append? Both static and dynamic needs that flag I think.

Copy link
Owner

Choose a reason for hiding this comment

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

Ah, my bad! Please disregard this comment.

@snowleopard
Copy link
Owner

Nice, looks a lot simpler than I imagined :-)

I've added a few minor comments.

Does this fully solve #4? I remember varous mysterious settings like DynamicGhcPrograms, DYNAMIC_TOO, etc. Also, what about Windows? Wasn't there a recent GHC patch that implemented dynamic way on Windows?

@snowleopard
Copy link
Owner

By the way, Linux CI fails.

@izgzhen
Copy link
Collaborator Author

izgzhen commented Jun 17, 2017

By the way, Linux CI fails.

Ah, my bad, dylib is a mac OS thing, the Linux uses so

@izgzhen
Copy link
Collaborator Author

izgzhen commented Jun 17, 2017

Also, what about Windows? Wasn't there a recent GHC patch that implemented dynamic way on Windows?

Including Windows, I will work on the platform thing soon

@izgzhen
Copy link
Collaborator Author

izgzhen commented Jun 21, 2017

Including Windows, I will work on the platform thing soon

Well, I found that it is hard to test Windows-version on my machine for now. Can I leave it for future?

@snowleopard
Copy link
Owner

Well, I found that it is hard to test Windows-version on my machine for now. Can I leave it for future?

Yes, sure.

@izgzhen
Copy link
Collaborator Author

izgzhen commented Jun 23, 2017

I remember varous mysterious settings like DynamicGhcPrograms, DYNAMIC_TOO

Relevant wiki:

Looks like this issue is around GHCi, a more specialized problem. I believe it is one of the dynamic way milestone tasks, but I prefer to submit a separate issue and PR for it.

Then how should I define this PR? "Build dynamic libs for GHC executable compilation"?

@izgzhen
Copy link
Collaborator Author

izgzhen commented Jun 23, 2017

BTW, I should have fixed the Linux dynamic lib. The weird bit is, for object like rts/Adjust.dyn_o, the old system use ghc-stage2 to build it (the source is C and it works!), while our system will use Cc builder. So the ultimate .dyn_o is built by different commands, comparing my patch and the reference.

@snowleopard
Copy link
Owner

Looks like this issue is around GHCi, a more specialized problem. I believe it is one of the dynamic way milestone tasks, but I prefer to submit a separate issue and PR for it.

Yes, sounds good.

Then how should I define this PR? "Build dynamic libs for GHC executable compilation"?

Works for me!

@snowleopard
Copy link
Owner

The weird bit is, for object like rts/Adjust.dyn_o, the old system use ghc-stage2 to build it (the source is C and it works!), while our system will use Cc builder

Yes, I never found out what was the reason to use GHC for compiling C files, so I decided to use Cc instead. I hope it won't bite us. I suggest to stick to using Cc unless you see a potential problem.

@izgzhen
Copy link
Collaborator Author

izgzhen commented Jun 24, 2017

I pushed the patch to follow the upstream change of dropping hoopl dependency in this PR as well. Should I open another PR for it?

Also, it should really work now, but both Linux and OS X CI timeout due to the lengthy process of building dynamic libs.

@izgzhen izgzhen mentioned this pull request Jun 24, 2017
@snowleopard
Copy link
Owner

@izgzhen I'd prefer a separate PR for dropping hoopl.

but both Linux and OS X CI timeout due to the lengthy process of building dynamic libs

So, let's remove dynamic from quickest. We have a separate issue where we'll keep discussing this.

@izgzhen
Copy link
Collaborator Author

izgzhen commented Jun 25, 2017

So, let's remove dynamic from quickest. We have a separate issue where we'll keep discussing this.

Done (quick still keeps it).

@snowleopard
Copy link
Owner

@izgzhen Thanks! Shall I merge this one too?

[ append =<< getPkgDataList CcArgs
, argSettingList . ConfCcArgs =<< getStage
, cIncludeArgs

, builder (Cc CompileC) ? mconcat [ arg "-Werror"
, (Dynamic `wayUnit` way) ?
mconcat [ arg "-fPIC"
Copy link
Owner

Choose a reason for hiding this comment

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

Should this be append ["-fPIC", "-DDYNAMIC"]?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed


-- This will create split objects if required (we don't track them
-- explicitly as this would needlessly bloat the Shake database).
need $ noHsObjs ++ hsObjs
Copy link
Owner

Choose a reason for hiding this comment

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

Can we get rid of this code duplication?

Copy link
Owner

Choose a reason for hiding this comment

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

See buildPackageLibrary below, which seems to have a lot of overlap with this build rule.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes there is code duplication since buildDynamicLib is adapted from buildPackageLibrary. Before that I am not sure if I should refactor or not, but let's refactor it.

@snowleopard
Copy link
Owner

I've added a couple of more comments after looking through the code again.

@izgzhen
Copy link
Collaborator Author

izgzhen commented Jun 26, 2017

Shall I merge this one too?

I am ready now, you may merge if as you see fit.

@snowleopard snowleopard merged commit 49b13b8 into snowleopard:master Jun 26, 2017
@snowleopard
Copy link
Owner

Thanks! Merged.

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants