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: add MOZJS_FROM_SOURCE #450

Merged
merged 12 commits into from
Mar 28, 2024
Merged

feat: add MOZJS_FROM_SOURCE #450

merged 12 commits into from
Mar 28, 2024

Conversation

wusyong
Copy link
Contributor

@wusyong wusyong commented Jan 24, 2024

Blocked by #445 and probably need a CI from servo org to publish libmozjs.

This is the last step of #439. Everything should work now but it's based on my fork at the moment.

@sagudev
Copy link
Member

sagudev commented Feb 27, 2024

Maybe we need to automatically enable MOZJS_FROM_SOURCE if features or target are not right but not if MOZJS_ARCHIVE is provided (in this case we trust user that it knows what it is doing).

mozjs-sys/build.rs Outdated Show resolved Hide resolved
@wusyong
Copy link
Contributor Author

wusyong commented Mar 14, 2024

The action seems to work on PR and main branch. But I haven't added the job to test auto-downloaded prebuilt. What's preferred job or step to test this?

@sagudev
Copy link
Member

sagudev commented Mar 14, 2024

But I haven't added the job to test auto-downloaded prebuilt. What's preferred job or step to test this?

I think adjusting release.yml to support auto-downloading (instead of manually specifying release/download) would be the way to go. Actually we could always test with auto-download, except when this would require new release (mozjs-sys version was bumped), so in that case we need to fallback to testing artifacts on PR and MQ (but we can auto-download when pushed on main as the release should be made by the same run).

.github/workflows/rust.yml Outdated Show resolved Hide resolved
@wusyong
Copy link
Contributor Author

wusyong commented Mar 17, 2024

Behaviors of MOZJS_CREATE_ARCHIVE and MOZJS_ARCHIVE have been updated based on review.
And I added another step in release.yml to auto-download archive and build when it's pushed on main branch.

@wusyong wusyong marked this pull request as ready for review March 17, 2024 13:19
@wusyong wusyong requested a review from sagudev March 17, 2024 13:20
Comment on lines 62 to 63
let build_from_source = if env::var_os("MOZJS_FROM_SOURCE").is_some() || create_archive {
true
Copy link
Member

Choose a reason for hiding this comment

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

If I am reading things correctly, if features mismatch with what artifacts provide we run compilation with artifacts anyway and then on failure (if it even fails), we do fallback. I think it would be nicer to fallback to build from source directly. So if streams feature is not selected or debug-mozjs feature is enabled. And when building from source is enabled we should print reason for this using cargo:info for easier debugging.

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 added two conditions to check streams and debug-mozjs features. Do they match what you described?

Copy link
Member

Choose a reason for hiding this comment

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

It's good. Is there any specific reason for mixing env::var vs env::var_os, or can we only use one variant everywhere?

Separating MOZJS_FROM_SOURCE and MOZJS_CREATE_ARCHIVE into separate if's with reasons info would also make sense, right?

Otherwise this looks really good, I will do more test after #459 to make sure everything works as expected and then we can land this.

@wusyong
Copy link
Contributor Author

wusyong commented Mar 22, 2024

@sagudev Sine #459 has been merged, could this PR be reviewed again? Or should it need to wait for any other PR?

@sagudev
Copy link
Member

sagudev commented Mar 22, 2024

I will do it later today (and if I forgot do not hesitate to ping me tomorrow).

mozjs-sys/build.rs Outdated Show resolved Hide resolved
Copy link
Member

@sagudev sagudev left a comment

Choose a reason for hiding this comment

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

LGTM

But given the nature of this change, maybe this needs another pair of eyes.

@sagudev sagudev requested a review from mrobinson March 23, 2024 05:25
Copy link
Member

@mrobinson mrobinson left a comment

Choose a reason for hiding this comment

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

Looks pretty good. I just have a few minor comments.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
mozjs-sys/build.rs Outdated Show resolved Hide resolved
mozjs-sys/build.rs Outdated Show resolved Hide resolved
mozjs-sys/build.rs Outdated Show resolved Hide resolved
let target = env::var("TARGET").unwrap();
let archive_path = PathBuf::from(env::var_os("OUT_DIR").unwrap()).join("libmozjs.tar.gz");
if !archive_path.exists() {
if !Command::new("curl")
Copy link
Member

Choose a reason for hiding this comment

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

We should document somewhere that cURL is now a dependency.

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 added in mozjs's README. I'll also add them to servo's README later.

Copy link
Member

Choose a reason for hiding this comment

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

It would be nice to add this for Windows as well.

Copy link
Contributor Author

@wusyong wusyong Mar 26, 2024

Choose a reason for hiding this comment

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

Windows has built-in curl as @sagudev mentioned.

mozjs-sys/build.rs Outdated Show resolved Hide resolved
mozjs-sys/build.rs Outdated Show resolved Hide resolved

/// Link static library tarball instead of building it from source.
fn link_static_lib_binaries(build_dir: &Path) -> Result<(), std::io::Error> {
if let Ok(archive) = env::var("MOZJS_ARCHIVE") {
Copy link
Member

Choose a reason for hiding this comment

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

Could this be mapped to an Option instead of repeating the download_archive and decompress_static_lib calls below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When it's returned, we will also print the error cause as cargo warning if pre-built archive step fails.
I hope we can keep it as a Result so we can understand why this step failed.

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 something like this:

   let archive = let Ok(archive) = env::var("MOZJS_ARCHIVE") {
        download_archive(Some(&archive)).unwrap_or(PathBuf::from(archive));
    } else {
        download_archive(None)?;
    };
    decompress_static_lib(&archive, build_dir)?;

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 believe @sagudev wants decompress_static_lib in the first branch to have a hard fail because it manually specifies MOZJS_ARCHIVE, and we want it to panic instead of fall back.

@wusyong wusyong requested a review from mrobinson March 26, 2024 12:44
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
mozjs-sys/build.rs Outdated Show resolved Hide resolved
let target = env::var("TARGET").unwrap();
let archive_path = PathBuf::from(env::var_os("OUT_DIR").unwrap()).join("libmozjs.tar.gz");
if !archive_path.exists() {
if !Command::new("curl")
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice to add this for Windows as well.


/// Link static library tarball instead of building it from source.
fn link_static_lib_binaries(build_dir: &Path) -> Result<(), std::io::Error> {
if let Ok(archive) = env::var("MOZJS_ARCHIVE") {
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 something like this:

   let archive = let Ok(archive) = env::var("MOZJS_ARCHIVE") {
        download_archive(Some(&archive)).unwrap_or(PathBuf::from(archive));
    } else {
        download_archive(None)?;
    };
    decompress_static_lib(&archive, build_dir)?;

@sagudev
Copy link
Member

sagudev commented Mar 26, 2024

It would be nice to add this for Windows as well.

curl is preinstalled on windows 10/11.

@wusyong wusyong requested a review from mrobinson March 26, 2024 14:09
@wusyong
Copy link
Contributor Author

wusyong commented Mar 28, 2024

@sagudev Is it okay to merge this PR?

@sagudev sagudev added this pull request to the merge queue Mar 28, 2024
Merged via the queue into servo:main with commit 8603cbf Mar 28, 2024
20 checks passed
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