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

feat(xsnap): Build sensitivity to presence of build toolchain #9160

Merged
merged 5 commits into from
Apr 4, 2024

Conversation

kriskowal
Copy link
Member

@kriskowal kriskowal commented Mar 28, 2024

closes: #8536

Description

For those just tuning in, @warner took a run at making yarn build xsnap just once when it’s initially installed. I then took a run at landing the described fix and discovered a problem with building in Docker and reverted.

The changes you see before you unrevert the revert and go on to address the issue with Docker. Except, we do not update .dockerignore. We do not do anything special for the Docker environment because the new Dockerfile.sdk doesn’t require accommodation. We might in some future change make the postinstall script gracefully handle a Docker environment that has a binary but no sources, and we’ve laid some groundwork, but that case is still not supported.

Elaborating on the original plan, it also turns out to be insufficient to assume the presence of a moddable directory implies the existence of checked-out files under some circumstances (Documentation CI). So, we must be more specific about a file that would have been checked out. I chose the xs.h header arbitrarily.

This attempt otherwise resembles #9113 and ensures the C sources get published to npm so the recipient doesn’t have to git update submodules and this presumably is why make remembers where it left off when you yarn again later.

Documentation integration PR (this regressed last time) Agoric/documentation#1050

Security Considerations

Scaling Considerations

Documentation Considerations

Testing Considerations

Upgrade Considerations

@kriskowal kriskowal force-pushed the kriskowal-this-time-with-feeling-8536 branch 2 times, most recently from 4a2c75c to 73a1ebe Compare March 29, 2024 00:22
@kriskowal kriskowal marked this pull request as ready for review March 29, 2024 00:49
@kriskowal kriskowal requested a review from warner March 29, 2024 00:49
Copy link
Member

@michaelfig michaelfig left a comment

Choose a reason for hiding this comment

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

This still needs some work. Coupling with the Docker host's platform is too strong, and produces broken binaries if your host platform's compiler is binary-incompatible with the platform used inside the containers.

.dockerignore Outdated
@@ -26,3 +26,4 @@ endo-sha.txt
# `@@AGORIC_DOCKER_SUBMODULES@@`
packages/xsnap/moddable
packages/xsnap/xsnap-native
!packages/xsnap/xsnap-native/xsnap/build/bin
Copy link
Member

Choose a reason for hiding this comment

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

I'm not convinced this is correct. The only way it would work is if the platform within the Docker container is (coincidentally) binary-compatible with the host platform's (outside of Docker) compiler toolchain, and the host built the binary before attempting to run the Docker build.

That bundling of a host-specific binary violates the idea of Docker builds being reproducible.

In practical terms, this means that I won't be able to run agoric-sdk/a3p-integration on my MacOS box, because the host platform's compiler toolchain is not binary-compatible with the Linux-based system inside the Docker containers.

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’ve removed this line from .dockerignore. It might be appropriate to remove the submodule exceptions as well, though they appear to be doing no harm.

@michaelfig
Copy link
Member

This still needs some work.

Are you running into multiple builds because of bin/agd? That's a more encompassing issue that I'm looking to solve properly once I clear (or reprioritise) more of my queue.

Comment on lines 293 to 292
// For the Docker case, we can expect the binary to have been made and added
// by the host, and for the native module sources to have been ommitted,
// as per .dockerignore in this repository:
//
// packages/xsnap/moddable
// packages/xsnap/xsnap-native
// !packages/xsnap/xsnap-native/xsnap/build/bin
//
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 still need these semantics, I’d suggest doing the xsnap build in a stage of Dockerfile.sdk which has the compiler toolchain (i.e. no host build necessary), and in a later stage:

RUN rm -rf packages/xsnap/moddable packages/xsnap/xsnap-native && mkdir -p packages/xsnap/xsnap-native/xsnap/build/bin
COPY --from=<earlier-stage> /usr/src/agoric-sdk/packages/xsnap/xsnap-native/xsnap/build/bin/* packages/xsnap/xsnap-native/xsnap/build/bin/

That doesn’t need a .dockerignore change.

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 think this requires a base Docker image that includes the build toolchain, including make, git, and the CC, which are evidently absent.

Is it possible to contrive a mechanism that builds xsnap in one container and shares the build product into the next?

Copy link
Member Author

Choose a reason for hiding this comment

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

michaelfig answers out-of-band: Build stages. We can do this.

https://docs.docker.com/build/building/multi-stage/

Copy link
Member Author

Choose a reason for hiding this comment

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

Evidently, you already did this. I pulled out the .dockerignore change since it’s no longer helpful or necessary. I’ve also removed the ruminations on the fictional Docker environment where we want yarn build to work for xsnap when there’s a binary already present but no sources. I left the code mostly the same since there’s no downside.

.dockerignore Outdated
@@ -26,3 +26,4 @@ endo-sha.txt
# `@@AGORIC_DOCKER_SUBMODULES@@`
packages/xsnap/moddable
packages/xsnap/xsnap-native
!packages/xsnap/xsnap-native/xsnap/build/bin
Copy link
Member Author

Choose a reason for hiding this comment

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

@turadg, I got a tip from @michaelfig that you might have pending changes to Docker stuff that might overlap with this effort to speed up xsnap builds. Please take a look and let me know whether the wind is carrying us in the same direction.

Copy link
Member

Choose a reason for hiding this comment

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

My thing landed in a couple days ago: #8850 Sorry I didn't think to tag you. I had picked the reviewers before you took up xsnap.

Your branch is on top of that from master so no potential for conflicts.

That change was to have a Docker layer specifically for xsnap, so that the yarn install didn't try to build it again if it hadn't changed. I think that's good to keep and should reduce the number of cases you have to consider.

Copy link
Member Author

Choose a reason for hiding this comment

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

The Docker build of xsnap in a container with the build toolchain is great and I think does simplify the constraints on build.js. I’ve mostly adjusted the comments to reflect that simplification.

@kriskowal kriskowal force-pushed the kriskowal-this-time-with-feeling-8536 branch 3 times, most recently from 5c5cbbd to 28e2a42 Compare March 30, 2024 01:21
@kriskowal
Copy link
Member Author

Are you running into multiple builds because of bin/agd? That's a more encompassing issue that I'm looking to solve properly once I clear (or reprioritise) more of my queue.

I have not seen this reported. I’ve only heard about lots of rebuilding of xsnap each time a dapp dev runs yarn.

@kriskowal kriskowal force-pushed the kriskowal-this-time-with-feeling-8536 branch 2 times, most recently from 99eee8b to d627413 Compare April 1, 2024 21:25
@@ -13,7 +13,7 @@
"scripts": {
"repl": "node src/xsrepl.js",
"build:bin": "if test -d ./test; then node src/build.js; else yarn build:from-env; fi",
"build:env": "test -d ./test && node src/build.js --show-env > build.env",
"build:env": "node src/build.js --show-env > build.env",
Copy link
Member Author

Choose a reason for hiding this comment

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

In both the old and new build:env script, we fail if git is unavailable, since that is a requirement for --show-env, but now src/build.js says why. In the old code, we would short circuit if test didn’t exist, which is the case for an unpacked npm tarball, an environment where git might not exist and in which git should not be used. In the new code, we use the existence of a specific source file and the platform-specific binary for a more direct signal.

Comment on lines +53 to +60
"moddable/modules/data",
"moddable/xs/includes",
"moddable/xs/makefiles",
"moddable/xs/platforms/*.h",
"moddable/xs/sources",
"src",
"xsnap-native/xsnap/makefiles",
"xsnap-native/xsnap/sources"
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the bit that makes it unnecessary for the postinstall script to clone git submodules.

Comment on lines +17 to +20
time yarn
time yarn
time yarn
time yarn
Copy link
Member Author

Choose a reason for hiding this comment

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

First one is slow, subsequent are fast.

@kriskowal kriskowal force-pushed the kriskowal-this-time-with-feeling-8536 branch from 98f7094 to b4fdfb8 Compare April 2, 2024 18:12
Copy link
Member

@michaelfig michaelfig left a comment

Choose a reason for hiding this comment

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

LGTM!

@kriskowal kriskowal force-pushed the kriskowal-this-time-with-feeling-8536 branch from b4fdfb8 to efbaf26 Compare April 4, 2024 18:20
@kriskowal kriskowal added the automerge:rebase Automatically rebase updates, then merge label Apr 4, 2024
@mergify mergify bot merged commit c060e65 into master Apr 4, 2024
74 checks passed
@mergify mergify bot deleted the kriskowal-this-time-with-feeling-8536 branch April 4, 2024 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge:rebase Automatically rebase updates, then merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

build xsnap from NPM tarball without git
3 participants