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

chore: Fixed incorrect use of cfg! macro and update build.rs to support arm target #1458

Merged
merged 9 commits into from May 12, 2024

Conversation

Chiichen
Copy link
Contributor

What I've done

  1. Fixed incorrect use of cfg! macro use the CARGO_CFG_TARGET_<OS/ARCH> macro instead of the original cfg! (target_<os/arch>) This is because The build script is compiled for the host architecture as a separate build phase, as that's where it runs. Since the cfg macro runs at compile time it'll always report the host configuration there.When cargo runs the build script it passes the configuration through environment variables, one of which is CARGO_CFG_TARGET_ARCH. Some dicussions can be found here

  2. update build.rs to support arm target support arm target. Like the Aarch64 target, we need to additionally install the cross-compilation toolchain and specify the linker in Cargo/config.toml. I can add this part of the work in next pull request if necessary.

@CLAassistant
Copy link

CLAassistant commented Apr 15, 2024

CLA assistant check
All committers have signed the CLA.

@@ -137,20 +137,19 @@ fn build_v8(is_asan: bool) {
if need_gn_ninja_download() {
download_ninja_gn_binaries();
}

let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a few lines here with a note explaining why cfg! isn't appropriate for future contributors to this file? The commentary from the PR description will work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you add a few lines here with a note explaining why cfg! isn't appropriate for future contributors to this file? The commentary from the PR description will work.

Of course! Actually #[cfg(...)] attributes don't work as expected from build.rs -- they refer to the configuration of the host system which the build.rs script will be running on. In short, cfg!(target_<os/arch>) is actually the host os/arch instead of target os/arch while cross compiling. Instead, Environment viariables is the officially approach to get the target os/arch in build.rs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe some parts of the original code that use the cfg!(target_<os/arch>) macro are used to obtain the host <os/arch>, but I think using this ambiguous syntax is not conducive to long-term maintenance. It's highly recommended to use the HOST environment variable to get the host triplet or use cfg!(target_<os/arch>) with explicit annotation

@mmastrac
Copy link
Member

Is there a reason for the clang submodule update?

@Chiichen
Copy link
Contributor Author

Is there a reason for the clang submodule update?

It may be related to the fact that I modified the bin path of gn/ninja. I rolled back this modification.

@Chiichen
Copy link
Contributor Author

Is there a reason for the clang submodule update?

reverted

@Chiichen Chiichen requested a review from mmastrac April 23, 2024 01:59
build.rs Show resolved Hide resolved
Copy link
Member

@mmastrac mmastrac left a comment

Choose a reason for hiding this comment

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

LGTM, waiting on a build pass.

@Chiichen It appears that 4e30365 seems to have caused the apple builds to fail.

@Chiichen
Copy link
Contributor Author

Chiichen commented Apr 23, 2024

LGTM, waiting on a build pass.

@Chiichen It appears that 4e30365 seems to have caused the apple builds to fail.

Thanks for your reply. It reports in workflow's log at line 135

135 error[E0463]: can't find crate for `core`

This looks like a classic error that can occur when we cross-compile without the corresponding tool chain installed. and I found it at line 7

6 Runner Image
7   Image: macos-14-arm64
8   Version: 20240415.6
9   Included Software: https://github.com/actions/runner-images/blob/macos-14-arm64/20240415.6/images/macos/macos-14-arm64-Readme.md
10  Image Release: https://github.com/actions/runner-images/releases/tag/macos-14-arm64%2F20240415.6

It seems that we are trying to build a x86_64 target on aarch64 platform. I think this may be caused by us not properly installing the Rust toolchain for x86_64-macos on the aarch64-macos device

Actually, I found that the existing workflow does not handle cross-compilation on macos devices. One method is to force it to use x86_64 machines by specifying an older macos version(macos11 or macos12), and the other method is to amend the workflow to support cross-compilation on the macos platform.

@Chiichen
Copy link
Contributor Author

Details at #1472 .

For now, specifying the runner as macos12 is a workaround for specifying the macos architecture as x86_64. However, macos14 does not guarantee that the running architecture is arm64, so I think the ci workflow on macos needs some improvement.

@Chiichen
Copy link
Contributor Author

@mmastrac I think the Test error has nothing to do with my modifications. The same error appears at #1473

@mmastrac
Copy link
Member

I agree -- we're seeing that error frequently on other PRs. It doesn't make a lot of sense

@Chiichen
Copy link
Contributor Author

@mmastrac If there is any expected changes that is blocking this PR from being merged into master, I 'm glad to know

@mmastrac
Copy link
Member

We should be good to go. Just trying to get that flaky test to pass 😞

@Chiichen
Copy link
Contributor Author

We should be good to go. Just trying to get that flaky test to pass 😞

Got it. It looks like the test passed ^_^

@mmastrac mmastrac merged commit 4dd87b2 into denoland:main May 12, 2024
15 checks passed
@Chiichen Chiichen deleted the fix-build-script branch May 13, 2024 01:34
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.

None yet

3 participants