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

Generate all .o .deps and binaries to generated/ #6562

Merged
merged 2 commits into from
Feb 27, 2017

Conversation

RazvanN7
Copy link
Contributor

@RazvanN7 RazvanN7 commented Feb 23, 2017

I created a directory src/ddmd where I moved all the files in src/, except makefiles. Other than that I modified optabgen.d to generate sources to src/ddmd/backend and I also moved tk.c to backend since it was the only .c file in src/ddmd.

I also modified the makefile to have all generated files (except .c .d and .h files - source code generated files) in a directory called generated/ which is on the root level (same level as src). After creating dmd, the executable is copied to src/dmd so that other tools aren't affected by this PR.

Now all the other tools can be updated to use the dmd from the generated/ folder whithout causing a major stall. After all the scripts are updated to use generated/dmd/ I will issue a new PR which renames ddmd to dmd and no longer generates dmd in the src folder. This way things will get smoothly in the right direction.

This is a WIP as I only applied the modifications to the posix makefile.

This is a duplicate of #6489 since it was more time consuming to apply these changes on that branch.

@RazvanN7 RazvanN7 force-pushed the ddmd_generated branch 2 times, most recently from 3b9ece9 to 72278c1 Compare February 23, 2017 15:45
src/posix.mak Outdated

GENERATED = ../generated
G = $(GENERATED)/$(OS)$(MODEL)
$(shell mkdir -p $G)
Copy link
Member

Choose a reason for hiding this comment

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

How about following the style used at Phobos and Druntime?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that there is no good reason to have two unused levels in the hierarchy

Copy link
Member

Choose a reason for hiding this comment

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

I think that there is no good reason to have two unused levels in the hierarchy

Well you can do debug and release builds at the same time without any issues ... and there are tons of other different build types available for DMD: https://github.com/dlang/dmd/blob/master/src/posix.mak#L160

Copy link
Member

Choose a reason for hiding this comment

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

This is interesting. A few explanations follow.

  1. Currently the code does not make the situation any worse than before - it just moves all generated files elsewhere, indiscriminately.

  2. The structure generated/$(OS)$(MODEL) (as opposed to Phobos' generated/$(OS)/$(MODEL)) was chosen by @RazvanN7 and I after discussing for a while and figuring there's no real need for two separate levels in the dir hierarchy.

  3. We could actually simply use generated/ without the OS or the model, BUT:

  • It is reasonable to generate 32 and 64 binaries on a given machine
  • Even on a given OS, there may be multiple "OS"s - consider generating Windows and Cygwin binaries on Windows. Are there any others? Not sure how important this is, but putting the OS in the dirname helps such situations.
  1. Now (this is getting to @wilzbach's point), we have the situation in which changing CFLAGS and DFLAGS affects the generated binaries in many ways, per https://github.com/dlang/dmd/blob/master/src/posix.mak#L160. The "total" solution to that is to canonicalize and place the controlling flags in the dir names, i.e. (after removing ENABLE) in alphabetical order: COVERAGE, DEBUG, LTO, PGO_GENERATE, PGO_USE, PROFILE, PROFILING, RELEASE, UNITTEST. Then the dir name of a generated bunch of binaries would be something like generated/posix64/DEBUG_PROFLE_UNITTEST. The "final release" version should sit in generated/$(OS)$(MODEL/ so flags do not affect tool developers. This scheme may be overkill even if technically appropriate. I think @WalterBright and @MartinNowak should chime in here because they'll be the first and most affected.

Copy link
Member

Choose a reason for hiding this comment

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

This is interesting. A few explanations follow.

  1. The structure generated/$(OS)$(MODEL) (as opposed to Phobos' generated/$(OS)/$(MODEL)) was chosen by @RazvanN7 and I after discussing for a while and figuring there's no real need for two separate levels in the dir hierarchy.

I doesn't cost anything either, and consistency across repos seems more important (in particular for scripting, e.g. release scripts). So let's please just stick with generated/$OS/$BUILD/$MODEL as anywhere else.

Even on a given OS, there may be multiple "OS"s - consider generating Windows and Cygwin binaries on Windows. Are there any others? Not sure how important this is, but putting the OS in the dirname helps such situations.

I also allows to more easily rsync code from other machines/VMs.

Now (this is getting to @wilzbach's point), we have the situation in which changing CFLAGS and DFLAGS affects the generated binaries in many ways, per https://github.com/dlang/dmd/blob/master/src/posix.mak#L160. The "total" solution to that is to canonicalize and place the controlling flags in the dir names, i.e. (after removing ENABLE) in alphabetical order: COVERAGE, DEBUG, LTO, PGO_GENERATE, PGO_USE, PROFILE, PROFILING, RELEASE, UNITTEST.

Those are hardly maintained and rarely used, let's not overshoot and leave it to maintainers.
Separating debug and relase builds is quite helpful though.
An alternative would be to dump all flags to some file and error on mismatch (requiring a clean step). This is the usual configure/Make approach to changing flags.

Copy link
Member

Choose a reason for hiding this comment

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

OK with @MartinNowak, @RazvanN7 can you please execute? Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

So, what will be the final path of the created dmd binary when make is invoked with the default settings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the end, the path will be generated/dmd, but until then we will keep a copy of dmd in src/ so that we will have a smooth transition

Copy link
Member

Choose a reason for hiding this comment

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

the path will be generated/dmd

Didn't we agree on generated/linux/debug/64/dmd ?
In the final build step you could create a symlink to the last built binary (e.g generated/dmd -> $(abspath generated/linux/debug/64/dmd)`) if you really want to ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's right. Sorry, I misread the comments

@RazvanN7
Copy link
Contributor Author

I don't have a windows setup, so my strategy is to spam the auto-tester. If someone with a windows machine wishes to co-op this PR, be my guest.

@UplinkCoder
Copy link
Member

@RazvanN7 please give me the rational for using the generated folder.
IMO it's easier to work with dmd when the .o files are in the same dir as the sources.

@wilzbach
Copy link
Member

please give me the rational for using the generated folder.

#6489

@RazvanN7 RazvanN7 force-pushed the ddmd_generated branch 3 times, most recently from 9fac9bb to 87e0612 Compare February 24, 2017 07:59
@andralex
Copy link
Member

One more thing: @RazvanN7 mentioned the file src/checkwhitespace.d is actually a tool that has no place in the dmd project (it uses phobos, it's also used by phobos and dmd). For this diff @RazvanN7 please leave checkwhitespace.d in src/ to avoid breakage, and let's move it in a later step. Thanks!

@skl131313
Copy link
Contributor

With all the changes happening anyways, would there be a possibility of adding druntime/phobos as submodules into dmd? The make files expect a specific file structure for where dmd, druntime, and phobos should be located relative to each other. Having them be submodules in dmd will make building from source easier. It will also know which specific version of druntime/phobos to use, rather than having to checkout the correct version for every repo.

@MartinNowak
Copy link
Member

IMO it's easier to work with dmd when the .o files are in the same dir as the sources.

Building out of tree is a common best practice and immediately useful to separate debug and release objects to avoid errors during development.

With all the changes happening anyways, would there be a possibility of adding druntime/phobos as submodules into dmd?

Let's please not open another can of worms. @CyberShadow has an exterior repo that tracks all repos, https://bitbucket.org/cybershadow/d (used by Digger).

@MartinNowak
Copy link
Member

Let's not move src/checkwhitespace.d → src/ddmd/checkwhitespace.d, right? Will also fix your tests ;).

@skl131313
Copy link
Contributor

skl131313 commented Feb 25, 2017

@MartinNowak

This is probably the only time to do so. A lot of the changes that would have to be made are on the same lines that this change is going to cause. Relying on an external tool and external repo for building kind of proves my point.

@RazvanN7 RazvanN7 force-pushed the ddmd_generated branch 7 times, most recently from df17adb to 060531b Compare February 27, 2017 09:30
@RazvanN7
Copy link
Contributor Author

The last commit was called "Added $(BUILD) to generated path", but it seems that $(BUILD) was evaluated to the empty string.

@CyberShadow
Copy link
Member

CyberShadow commented Feb 27, 2017

The last commit was called "Added $(BUILD) to generated path", but it seems that $(BUILD) was evaluated to the empty string.

I believe the problem occurred at the time the commit is created - your shell evaluated $(BUILD) to the expansion of the output of a non-existent command. To avoid this, you can use single quotes when specifying the commit message on the command line, or don't use -m and type the commit message in the invoked editor instead.

@RazvanN7
Copy link
Contributor Author

@CyberShadow thanks! I should have known that this would happen.

@andralex
Copy link
Member

Looking green! Well. almost. What's the failure with DAutoTest? Thanks! cc @CyberShadow maybe you could help.

@CyberShadow
Copy link
Member

make[2]: *** No rule to make target 'project.ddoc', needed by '/dev/shm/dtest/work/repo/dlang.org/web/dmd-prerelease/.generated'.  Stop.

Is it the DMD source code DDoc stuff? Not really familiar with that.

@CyberShadow
Copy link
Member

However, I think @RazvanN7 has deliberately made two commits to separate the renaming from the Makefile adjustments, so imho there's no need to do squashing here...

No, the first commit moves the file and the second one moves it back. So a squash is fine in this case.

@andralex
Copy link
Member

way we go...

@CyberShadow
Copy link
Member

CyberShadow commented Feb 27, 2017

So, what will be the final path of the created dmd binary when make is invoked with the default settings?

Question still unanswered in light of the latest changes :) Need to know what to update DIgger to use, so that we can delete dmd/src.

@wilzbach
Copy link
Member

Question still unanswered in light of the latest changes :) Need to know what to update DIgger to use, so that we can delete dmd/src..

AFAIK it's supposed to be generated/linux/release/64/dmd (?)

@RazvanN7
Copy link
Contributor Author

@CyberShadow : @wilzbach is right. that will be the path, same as in the phobos makefile

@dlang-bot dlang-bot merged commit 2bf9a9d into dlang:master Feb 27, 2017
@CyberShadow
Copy link
Member

Hmm, dlang.org autodeploy build failed:

digger: Running: 'make' '-f' 'posix.mak' 'MODEL=64' 'HOST_DC='
digger: PATH=/bin:/usr/bin
no cpu specified, assuming X86
posix.mak:81: *** 'dmd' not found, get a D compiler or make AUTO_BOOTSTRAP=1.  Stop.

@CyberShadow
Copy link
Member

Something changed in this PR which for some reason kept working on the documentation tester but didn't work on the dlang.org autodeployer, even though they use nearly the same environment and build commands.

@CyberShadow
Copy link
Member

Found the bug: if (buildPath(sourceDir, "src", "idgen.d").exists)

Odd that it worked on DAutoTest :)

@CyberShadow
Copy link
Member

CyberShadow commented Feb 27, 2017

Fixed. CyberShadow/ae@13bc434

@MartinNowak
Copy link
Member

.gitignore still needs to be updated

@MartinNowak
Copy link
Member

Seems like this broken the build script @RazvanN7, could you please have a look.
http://nightlies.dlang.org/dmd-master-2017-03-01/build.html

Running: make MODEL=32 DMD=..\dmd\src\dmd HOST_DC=C:\Users\vagrant\old-dmd\dmd2\windows\bin\dmd.exe RELEASE=1 LATEST=master -f win32.mak dmd
if not exist "..\generated\Windows_NT32" mkdir ..\generated\Windows_NT32
make -fwin32.mak C=ddmd\backend TK=ddmd\tk ROOT=ddmd\root MAKE="make" HOST_DC="C:\Users\vagrant\old-dmd\dmd2\windows\bin\dmd.exe" DMODEL= CC="dmc" LIB="lib" OBJ_MSVC="" "OPT=-o" "DEBUG=" "DDEBUG=" "DOPT=-O -release -inline" "LFLAGS=-L/delexe/la" ..\generated\Windows_NT32\dmd.exe
Error: don't know how to make '..\generated\Windows_NT32\dmd.exe'

@CyberShadow
Copy link
Member

@MartinNowak Since so many things seem to have broken nightly builds recently, is there a possibility of adding it as a CI? (Bonus: you can download a version of D that includes a certain PR to test it out)

@RazvanN7
Copy link
Contributor Author

RazvanN7 commented Mar 2, 2017

@MartinNowak it seems that the rule to make the target ..\generated\Windows...\dmd.exe doesn't exist in the makefile. That is odd, since the rule definitely exists in the makefile that I commited. The link you provided doesn't output this error. Could you, please, give me some more information?

@MartinNowak
Copy link
Member

The cost for a real run is prohibitive atm. (too many OSes/VMs).

@MartinNowak
Copy link
Member

http://nightlies.dlang.org/dmd-master-2017-03-02/build.html, wrong date, my mistake.

@CyberShadow
Copy link
Member

The cost for a real run is prohibitive atm. (too many OSes/VMs).

How about making it on-demand, or just whenever a makefile changes?

@MartinNowak
Copy link
Member

Yes, we should work on replacing the create_dmd_release script and CI integration (heuristic sounds like a good idea) in the longer run, but I'm busy w/ other things atm.
https://trello.com/c/uDoxVgpc/110-ci-for-nightly-builds

@MartinNowak
Copy link
Member

See #6585.

@wilzbach
Copy link
Member

wilzbach commented Mar 4, 2017

Eww discovered a couple of more issues with the "new" Makefile:

#6586

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants