Closed Bug 1312916 Opened 8 years ago Closed 7 years ago

Allow building host Rust crates in the build system

Categories

(Firefox Build System :: General, defect)

defect
Not set
normal

Tracking

(firefox54 fixed)

RESOLVED FIXED
mozilla54
Tracking Status
firefox54 --- fixed

People

(Reporter: ted, Assigned: chmanchester)

References

Details

Attachments

(1 file)

I'd like to use some Rust code in dump_syms, which is a host binary. We don't currently support building host Rust crates. Talking with froydnj about it on IRC we determined it shouldn't be terribly hard, we just need to pass the right --target to cargo and do the moz.build plumbing.
Blocks: 1314352
Assignee: nobody → cmanchester
Comment on attachment 8819448 [details]
Bug 1312916 - Add support for host rust libraries in moz.build.

https://reviewboard.mozilla.org/r/99210/#review100278

This patch is basically what I expected, so that's good!  Just a few small things to fix, I think, but otherwise pretty solid.  Interested to hear feedback on the `BaseX` comments for `HostRustLibrary` and the suggested test.

::: config/rules.mk:967
(Diff revision 1)
>  endif # RUST_LIBRARY_FILE
>  
> +ifdef HOST_RUST_LIBRARY_FILE
> +force-cargo-host-library-build:
> +	$(REPORT_BUILD)
> +	$(CARGO_BUILD) --lib $(cargo_host_flag) $(rust_features_flag)

Wouldn't we want separate feature lists for target Rust libraries vs. host ones?

::: python/mozbuild/mozbuild/frontend/data.py:638
(Diff revision 1)
>  class HostLibrary(HostMixin, BaseLibrary):
>      """Context derived container object for a host library"""
>      KIND = 'host'
>  
>  
> +class HostRustLibrary(HostMixin, RustLibrary):

I think our usual pattern for this is a `BaseX`, from which we have host and target versions, rather than having the host version inherit directly from the target version.

::: python/mozbuild/mozbuild/test/backend/test_recursivemake.py:752
(Diff revision 1)
>              'CARGO_FILE := $(srcdir)/Cargo.toml',
>          ]
>  
>          self.assertEqual(lines, expected)
>  
> +    def test_rust_host_library(self):

May want a host-with-features test here.
Attachment #8819448 - Flags: review?(nfroyd) → review-
Comment on attachment 8819448 [details]
Bug 1312916 - Add support for host rust libraries in moz.build.

https://reviewboard.mozilla.org/r/99210/#review100278

> Wouldn't we want separate feature lists for target Rust libraries vs. host ones?

I guess it's not crazy to have a host and target rust library in the same directory, sure.

> May want a host-with-features test here.

Sure.
Comment on attachment 8819448 [details]
Bug 1312916 - Add support for host rust libraries in moz.build.

https://reviewboard.mozilla.org/r/99210/#review100278

> I think our usual pattern for this is a `BaseX`, from which we have host and target versions, rather than having the host version inherit directly from the target version.

So I agree it doesn't make a lot of sense to have a Host thing inherit from a Target thing, but the alternative gets into a bit of a multiple inheritance mess. Anyway, I'll upload it and we can decide which is worse.
Comment on attachment 8819448 [details]
Bug 1312916 - Add support for host rust libraries in moz.build.

https://reviewboard.mozilla.org/r/99210/#review106366

Thanks for revising this.

::: build/templates.mozbuild:140
(Diff revision 2)
> +    HostLibrary(name)
> +
> +    IS_RUST_LIBRARY = True
> +
> +    if features:
> +        RUST_LIBRARY_FEATURES = features

My initial impulse was to say that this should be `HOST_RUST_LIBRARY_FEATURES`.  But I guess it'd be difficult to have a `HostRustLibrary` and a `RustLibrary` defined in the same moz.build file with our current setup, wouldn't it?  Or, at least, nobody's particularly concerned with such a thing at the moment.  (Maybe I was silly for asking for things to be duplicated in my previous review.)

Please do modify the documentation for `RUST_LIBRARY_FEATURES` to note that `RUST_LIBRARY_FEATURES` can be used for host or target features.

::: python/mozbuild/mozbuild/backend/recursivemake.py:1209
(Diff revision 2)
> -        backend_file.write_once('RUST_LIBRARY_FILE := %s\n' % libdef.import_name)
> +        lib_var = 'RUST_LIBRARY_FILE'
> +        feature_var = 'RUST_LIBRARY_FEATURES'
> +        if isinstance(libdef, HostRustLibrary):
> +            lib_var = 'HOST_RUST_LIBRARY_FILE'
> +            feature_var = 'HOST_RUST_LIBRARY_FEATURES'

Perhaps we should just move these to be static members on the `RustLibrary` and `HostRustLibrary` classes?
Attachment #8819448 - Flags: review?(nfroyd) → review+
Comment on attachment 8819448 [details]
Bug 1312916 - Add support for host rust libraries in moz.build.

https://reviewboard.mozilla.org/r/99210/#review106366

> My initial impulse was to say that this should be `HOST_RUST_LIBRARY_FEATURES`.  But I guess it'd be difficult to have a `HostRustLibrary` and a `RustLibrary` defined in the same moz.build file with our current setup, wouldn't it?  Or, at least, nobody's particularly concerned with such a thing at the moment.  (Maybe I was silly for asking for things to be duplicated in my previous review.)
> 
> Please do modify the documentation for `RUST_LIBRARY_FEATURES` to note that `RUST_LIBRARY_FEATURES` can be used for host or target features.

I thought about this, and the separate variable for host features seems fine. I'm inclined to just fix the typo at this point, thank you for noticing it!
Pushed by cmanchester@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/e0fb919e31cf
Add support for host rust libraries in moz.build. r=froydnj
https://hg.mozilla.org/mozilla-central/rev/e0fb919e31cf
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla54
Product: Core → Firefox Build System
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: