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

build: support lib.cc #1035

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open

build: support lib.cc #1035

wants to merge 27 commits into from

Conversation

Lazauya
Copy link

@Lazauya Lazauya commented Nov 14, 2024

A simple implementation for static library building. It functions nearly identically to executable building, except that we look for files named lib.cc (or the other acceptable C++ extensions) and resolved the dependencies for that file. Instead of linking everything into an executable at the end, we instead use ar to build an object archive called lib<package-name>.a.

@Lazauya Lazauya marked this pull request as ready for review November 14, 2024 04:29
src/BuildConfig.cc Outdated Show resolved Hide resolved
@ken-matsui
Copy link
Member

Please fix CI errors.

@Lazauya
Copy link
Author

Lazauya commented Nov 15, 2024

Please fix CI errors.

Working on it! I think I know what the issue is, luckily.

src/BuildConfig.hpp Outdated Show resolved Hide resolved
@ken-matsui
Copy link
Member

Please fix CI errors.

Working on it! I think I know what the issue is, luckily.

Great, thanks!

@ken-matsui
Copy link
Member

ken-matsui commented Nov 16, 2024

Please fix conflicts. (Note: this was merged)

Copy link
Member

@ken-matsui ken-matsui left a comment

Choose a reason for hiding this comment

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

Almost LG. Let's address some small things. Thanks!

src/BuildConfig.cc Outdated Show resolved Hide resolved
src/Cmd/Build.cc Outdated Show resolved Hide resolved
@ken-matsui ken-matsui changed the title Library building build: support lib.cc Nov 16, 2024
Copy link
Member

@ken-matsui ken-matsui left a comment

Choose a reason for hiding this comment

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

I have more comments but don't have enough time. Let me do that later. Here's what I have so far.

src/Cmd/Build.cc Outdated Show resolved Hide resolved
src/BuildConfig.cc Outdated Show resolved Hide resolved
src/BuildConfig.cc Outdated Show resolved Hide resolved
src/BuildConfig.cc Outdated Show resolved Hide resolved
src/Cmd/Build.cc Outdated Show resolved Hide resolved
src/Cmd/Build.cc Outdated Show resolved Hide resolved
@ken-matsui
Copy link
Member

Please fix conflicts, thank you

Copy link
Member

@ken-matsui ken-matsui left a comment

Choose a reason for hiding this comment

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

Sorry for taking long to review!

src/BuildConfig.cc Outdated Show resolved Hide resolved
src/BuildConfig.cc Outdated Show resolved Hide resolved
Comment on lines 65 to 66
BuildConfig::BuildConfig(const std::string& packageName, const bool isDebug)
: packageName{ packageName }, isDebug{ isDebug } {
Copy link
Member

Choose a reason for hiding this comment

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

Now this line looks awkward. Can you also please move this to the constructor body?

Suggested change
BuildConfig::BuildConfig(const std::string& packageName, const bool isDebug)
: packageName{ packageName }, isDebug{ isDebug } {
BuildConfig::BuildConfig(const std::string& packageName, const bool isDebug) {
packageName = packageName;
isDebug = isDebug;

Copy link
Author

Choose a reason for hiding this comment

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

Clang tidy throws an error if I do that.

src/BuildConfig.cc Outdated Show resolved Hide resolved
Comment on lines 898 to 922
if (executable) {
// Project binary target.
const std::string mainObjTarget = buildOutPath / "main.o";
std::unordered_set<std::string> projTargetDeps = { mainObjTarget };
collectBinDepObjs(
projTargetDeps, "",
targets.at(mainObjTarget).remDeps, // we don't need sourceFile
buildObjTargets
);

defineLinkTarget(outBasePath / packageName, projTargetDeps);
}

defineLinkTarget(outBasePath / packageName, projTargetDeps);
if (library) {
// Project library target.
const std::string libTarget = buildOutPath / "lib.o";
std::unordered_set<std::string> libTargetDeps = { libTarget };
collectBinDepObjs(
libTargetDeps, "",
targets.at(libTarget).remDeps, // we don't need sourceFile
buildObjTargets
);

defineLibTarget(outBasePath / libName, libTargetDeps);
}
Copy link
Member

Choose a reason for hiding this comment

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

These are almost equivalent. Can you make a new method for this?

Copy link
Author

Choose a reason for hiding this comment

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

I made new methods but it leaves a few loose ends lying around now. The commands have to be duplicated since I couldn't think of a convenient way to do that. I want to make the command strings both static variables but the library command can't be static since it uses fmt. It might be able to be made static if we use a make variable instead of fmt but I'm not sure how we'd want to go about that. Thoughts?

src/BuildConfig.hpp Outdated Show resolved Hide resolved
src/BuildConfig.hpp Outdated Show resolved Hide resolved
src/BuildConfig.hpp Outdated Show resolved Hide resolved
src/BuildConfig.hpp Outdated Show resolved Hide resolved
src/Cmd/Build.cc Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants