-
Notifications
You must be signed in to change notification settings - Fork 121
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
Conversation
Maybe we need to automatically enable |
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? |
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). |
Behaviors of |
mozjs-sys/build.rs
Outdated
let build_from_source = if env::var_os("MOZJS_FROM_SOURCE").is_some() || create_archive { | ||
true |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
I will do it later today (and if I forgot do not hesitate to ping me tomorrow). |
There was a problem hiding this 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.
There was a problem hiding this 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.
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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
||
/// 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") { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)?;
There was a problem hiding this comment.
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.
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") |
There was a problem hiding this comment.
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") { |
There was a problem hiding this comment.
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)?;
curl is preinstalled on windows 10/11. |
@sagudev Is it okay to merge this PR? |
- If MOZJS_CREATE_ARCHIVE is enabled, it will also build from source. - If MOZJS_ARCHIVE is enabled, it will panic on extraction fail directly.
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.