Skip to content

Commit 985b453

Browse files
authored
Switch to rust edition 2021 (#385)
* edition 2018 * idioms * edition 2021 * fmt * Workflow dispatch * necessary extern crates * rebase cleanup (fmt & regen wrappers) * fix build errors
1 parent 673b992 commit 985b453

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+414
-454
lines changed

.github/workflows/rust.yml

Lines changed: 71 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches: [master]
66
pull_request:
7+
workflow_dispatch:
78
merge_group:
89
types: [checks_requested]
910

@@ -25,17 +26,17 @@ jobs:
2526
SCCACHE_GHA_ENABLED: "true"
2627
SCCACHE_VERSION: "v0.4.0"
2728
steps:
28-
- uses: actions/checkout@v3
29-
- name: Install deps
30-
run: brew install python [email protected] llvm yasm
31-
- name: Run sccache-cache
32-
uses: mozilla-actions/[email protected]
33-
with:
34-
version: ${{ env.SCCACHE_VERSION }}
35-
- name: Build
36-
run: |
37-
cargo build --verbose ${{ matrix.features }}
38-
cargo test --verbose ${{ matrix.features }}
29+
- uses: actions/checkout@v3
30+
- name: Install deps
31+
run: brew install python [email protected] llvm yasm
32+
- name: Run sccache-cache
33+
uses: mozilla-actions/[email protected]
34+
with:
35+
version: ${{ env.SCCACHE_VERSION }}
36+
- name: Build
37+
run: |
38+
cargo build --verbose ${{ matrix.features }}
39+
cargo test --verbose ${{ matrix.features }}
3940
linux:
4041
env:
4142
RUSTC_WRAPPER: "sccache"
@@ -48,19 +49,19 @@ jobs:
4849
matrix:
4950
features: ["--features debugmozjs", ""]
5051
steps:
51-
- uses: actions/checkout@v3
52-
- uses: dtolnay/rust-toolchain@stable
53-
- name: Install deps
54-
run: |
55-
sudo apt install autoconf2.13 llvm -y
56-
- name: Run sccache-cache
57-
uses: mozilla-actions/[email protected]
58-
with:
59-
version: ${{ env.SCCACHE_VERSION }}
60-
- name: Build
61-
run: |
62-
cargo build --verbose ${{ matrix.features }}
63-
cargo test --verbose ${{ matrix.features }}
52+
- uses: actions/checkout@v3
53+
- uses: dtolnay/rust-toolchain@stable
54+
- name: Install deps
55+
run: |
56+
sudo apt install autoconf2.13 llvm -y
57+
- name: Run sccache-cache
58+
uses: mozilla-actions/[email protected]
59+
with:
60+
version: ${{ env.SCCACHE_VERSION }}
61+
- name: Build
62+
run: |
63+
cargo build --verbose ${{ matrix.features }}
64+
cargo test --verbose ${{ matrix.features }}
6465
windows:
6566
runs-on: windows-2019
6667
strategy:
@@ -70,57 +71,57 @@ jobs:
7071
#target: [""]
7172
target: ["", "aarch64-uwp-windows-msvc", "x86_64-uwp-windows-msvc"]
7273
env:
73-
LINKER: "lld-link.exe"
74-
CC: "clang-cl"
75-
CXX: "clang-cl"
76-
MOZTOOLS_PATH: "${{ github.workspace }}\\target\\dependencies\\moztools-3.2"
74+
LINKER: "lld-link.exe"
75+
CC: "clang-cl"
76+
CXX: "clang-cl"
77+
MOZTOOLS_PATH: "${{ github.workspace }}\\target\\dependencies\\moztools-3.2"
7778
steps:
78-
- uses: actions/checkout@v3
79-
- uses: dtolnay/rust-toolchain@stable
80-
if: (!contains(matrix.target, 'uwp'))
81-
- uses: dtolnay/rust-toolchain@master
82-
if: contains(matrix.target, 'uwp')
83-
with:
84-
toolchain: "nightly-2023-02-02"
85-
components: rust-src
86-
- name: Install deps
87-
run: |
88-
curl -SL "https://github.com/servo/servo-build-deps/releases/download/msvc-deps/moztools-3.2.zip" --create-dirs -o target/dependencies/moztools.zip
89-
cd target/dependencies && unzip -qo moztools.zip -d .
90-
- name: Run sccache-cache
91-
uses: mozilla-actions/[email protected]
92-
with:
93-
version: ${{ env.SCCACHE_VERSION }}
94-
- name: Build uwp
95-
if: contains(matrix.target, 'uwp')
96-
shell: cmd
97-
run: |
98-
rustc --version --verbose
99-
cargo build --verbose ${{ matrix.features }} -Z build-std=std,panic_abort --target ${{ matrix.target }}
100-
- name: Build Windows
101-
if: contains(matrix.target, 'uwp') != true
102-
shell: cmd
103-
run: |
104-
cargo test --verbose ${{ matrix.features }}
79+
- uses: actions/checkout@v3
80+
- uses: dtolnay/rust-toolchain@stable
81+
if: (!contains(matrix.target, 'uwp'))
82+
- uses: dtolnay/rust-toolchain@master
83+
if: contains(matrix.target, 'uwp')
84+
with:
85+
toolchain: "nightly-2023-02-02"
86+
components: rust-src
87+
- name: Install deps
88+
run: |
89+
curl -SL "https://github.com/servo/servo-build-deps/releases/download/msvc-deps/moztools-3.2.zip" --create-dirs -o target/dependencies/moztools.zip
90+
cd target/dependencies && unzip -qo moztools.zip -d .
91+
- name: Run sccache-cache
92+
uses: mozilla-actions/[email protected]
93+
with:
94+
version: ${{ env.SCCACHE_VERSION }}
95+
- name: Build uwp
96+
if: contains(matrix.target, 'uwp')
97+
shell: cmd
98+
run: |
99+
rustc --version --verbose
100+
cargo build --verbose ${{ matrix.features }} -Z build-std=std,panic_abort --target ${{ matrix.target }}
101+
- name: Build Windows
102+
if: contains(matrix.target, 'uwp') != true
103+
shell: cmd
104+
run: |
105+
cargo test --verbose ${{ matrix.features }}
105106
106107
android:
107108
runs-on: ubuntu-latest
108109
steps:
109-
- uses: actions/checkout@v3
110-
- name: Install NDK
111-
uses: nttld/setup-ndk@v1
112-
id: setup-ndk
113-
with:
114-
ndk-version: r21d
115-
- name: Install Rust
116-
uses: dtolnay/rust-toolchain@stable
117-
with:
118-
targets: armv7-linux-androideabi
119-
- name: Build
120-
env:
121-
ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
122-
run: |
123-
./android-build cargo build --target="armv7-linux-androideabi"
110+
- uses: actions/checkout@v3
111+
- name: Install NDK
112+
uses: nttld/setup-ndk@v1
113+
id: setup-ndk
114+
with:
115+
ndk-version: r21d
116+
- name: Install Rust
117+
uses: dtolnay/rust-toolchain@stable
118+
with:
119+
targets: armv7-linux-androideabi
120+
- name: Build
121+
env:
122+
ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
123+
run: |
124+
./android-build cargo build --target="armv7-linux-androideabi"
124125
125126
# The integrity check is currently broken. See issue #345.
126127
#

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
[workspace]
22
members = ["mozjs", "rust-mozjs"]
3+
resolver = "2"
34

45
[workspace.package]
56
repository = "https://github.com/servo/mozjs/"
67
license = "MPL-2.0"
7-
edition = "2015"
8+
edition = "2021"
89

910
[workspace.dependencies]
1011
cc = "1"

mozjs/build.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
extern crate bindgen;
6-
extern crate cc;
7-
extern crate walkdir;
8-
95
use bindgen::Formatter;
106
use std::env;
117
use std::ffi::{OsStr, OsString};
@@ -506,8 +502,8 @@ const BLACKLIST_TYPES: &'static [&'static str] = &[
506502
/// Definitions for types that were blacklisted
507503
const MODULE_RAW_LINES: &'static [(&'static str, &'static str)] = &[
508504
("root", "pub type FILE = ::libc::FILE;"),
509-
("root::JS", "pub type Heap<T> = ::jsgc::Heap<T>;"),
510-
("root::JS", "pub type Rooted<T> = ::jsgc::Rooted<T>;"),
505+
("root::JS", "pub type Heap<T> = crate::jsgc::Heap<T>;"),
506+
("root::JS", "pub type Rooted<T> = crate::jsgc::Rooted<T>;"),
511507
];
512508

513509
/// Rerun this build script if files under mozjs/ changed, unless this returns true.

mozjs/src/jsgc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
use jsapi::JS;
6-
use jsapi::{jsid, JSFunction, JSObject, JSScript, JSString, JSTracer};
5+
use crate::jsapi::JS;
6+
use crate::jsapi::{jsid, JSFunction, JSObject, JSScript, JSString, JSTracer};
77

8-
use jsid::VoidId;
8+
use crate::jsid::VoidId;
99
use std::cell::UnsafeCell;
1010
use std::ffi::c_void;
1111
use std::mem;

mozjs/src/jsid.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
#![allow(non_snake_case)]
66

7-
use jsapi::JS::Symbol;
8-
use jsapi::{jsid, JSString};
7+
use crate::jsapi::JS::Symbol;
8+
use crate::jsapi::{jsid, JSString};
99
use libc::c_void;
1010

1111
#[deprecated]

mozjs/src/jsimpls.rs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
use jsapi::glue::JS_ForOfIteratorInit;
6-
use jsapi::glue::JS_ForOfIteratorNext;
7-
use jsapi::jsid;
8-
use jsapi::JSAutoRealm;
9-
use jsapi::JSContext;
10-
use jsapi::JSErrNum;
11-
use jsapi::JSFunctionSpec;
12-
use jsapi::JSJitGetterCallArgs;
13-
use jsapi::JSJitMethodCallArgs;
14-
use jsapi::JSJitSetterCallArgs;
15-
use jsapi::JSNativeWrapper;
16-
use jsapi::JSObject;
17-
use jsapi::JSPropertySpec;
18-
use jsapi::JSPropertySpec_Kind;
19-
use jsapi::JSPropertySpec_Name;
20-
use jsapi::JS;
21-
use jsgc::RootKind;
22-
use jsid::VoidId;
23-
use jsval::UndefinedValue;
24-
25-
use jsapi::JS::{ObjectOpResult, ObjectOpResult_SpecialCodes};
5+
use crate::jsapi::glue::JS_ForOfIteratorInit;
6+
use crate::jsapi::glue::JS_ForOfIteratorNext;
7+
use crate::jsapi::jsid;
8+
use crate::jsapi::JSAutoRealm;
9+
use crate::jsapi::JSContext;
10+
use crate::jsapi::JSErrNum;
11+
use crate::jsapi::JSFunctionSpec;
12+
use crate::jsapi::JSJitGetterCallArgs;
13+
use crate::jsapi::JSJitMethodCallArgs;
14+
use crate::jsapi::JSJitSetterCallArgs;
15+
use crate::jsapi::JSNativeWrapper;
16+
use crate::jsapi::JSObject;
17+
use crate::jsapi::JSPropertySpec;
18+
use crate::jsapi::JSPropertySpec_Kind;
19+
use crate::jsapi::JSPropertySpec_Name;
20+
use crate::jsapi::JS;
21+
use crate::jsgc::RootKind;
22+
use crate::jsid::VoidId;
23+
use crate::jsval::UndefinedValue;
24+
25+
use crate::jsapi::JS::{ObjectOpResult, ObjectOpResult_SpecialCodes};
2626
use std::ops::Deref;
2727
use std::ops::DerefMut;
2828
use std::os::raw::c_void;
@@ -344,12 +344,12 @@ impl JSPropertySpec {
344344
},
345345
attributes_: 0,
346346
kind_: JSPropertySpec_Kind::NativeAccessor,
347-
u: ::jsapi::JSPropertySpec_AccessorsOrValue {
348-
accessors: ::jsapi::JSPropertySpec_AccessorsOrValue_Accessors {
349-
getter: ::jsapi::JSPropertySpec_Accessor {
347+
u: crate::jsapi::JSPropertySpec_AccessorsOrValue {
348+
accessors: crate::jsapi::JSPropertySpec_AccessorsOrValue_Accessors {
349+
getter: crate::jsapi::JSPropertySpec_Accessor {
350350
native: JSNativeWrapper::ZERO,
351351
},
352-
setter: ::jsapi::JSPropertySpec_Accessor {
352+
setter: crate::jsapi::JSPropertySpec_Accessor {
353353
native: JSNativeWrapper::ZERO,
354354
},
355355
},
@@ -531,7 +531,9 @@ impl JS::ObjectOpResult {
531531

532532
impl Default for ObjectOpResult {
533533
fn default() -> ObjectOpResult {
534-
ObjectOpResult { code_: ObjectOpResult_SpecialCodes::Uninitialized as usize }
534+
ObjectOpResult {
535+
code_: ObjectOpResult_SpecialCodes::Uninitialized as usize,
536+
}
535537
}
536538
}
537539

mozjs/src/jsval.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
#![allow(non_camel_case_types)]
66
#![allow(non_snake_case)]
77

8-
use jsapi::JSContext;
9-
use jsapi::JSObject;
10-
use jsapi::JSString;
11-
use jsapi::JSValueType;
12-
use jsapi::JS::BigInt;
13-
use jsapi::JS::Symbol;
14-
use jsapi::JS::TraceKind;
15-
use jsapi::JS::Value;
8+
use crate::jsapi::JSContext;
9+
use crate::jsapi::JSObject;
10+
use crate::jsapi::JSString;
11+
use crate::jsapi::JSValueType;
12+
use crate::jsapi::JS::BigInt;
13+
use crate::jsapi::JS::Symbol;
14+
use crate::jsapi::JS::TraceKind;
15+
use crate::jsapi::JS::Value;
1616

1717
use libc::c_void;
1818
use std::default::Default;
@@ -565,7 +565,7 @@ fn test_representation_agreement() {
565565
// Annoyingly, we can't check JSObject, JSString, etc. without creating a runtime,
566566
// since the constructor has checks that fail if we try mocking. There are no-check
567567
// versions of the setters, but they're private.
568-
use jsapi::glue::*;
568+
use crate::jsapi::glue::*;
569569
let mut val1 = UndefinedValue();
570570
let mut val2;
571571

@@ -596,7 +596,7 @@ fn test_representation_agreement() {
596596

597597
#[cfg(test)]
598598
fn assert_agreement(val1: JSVal, val2: JSVal) {
599-
use jsapi::glue::*;
599+
use crate::jsapi::glue::*;
600600

601601
assert_eq!(val1.asBits(), val2.asBits());
602602

mozjs/src/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
#[allow(unused_extern_crates)]
5+
#![allow(unused_extern_crates)]
6+
7+
// This extern crates are needed for linking
68
extern crate encoding_c;
7-
#[allow(unused_extern_crates)]
89
extern crate encoding_c_mem;
9-
extern crate libc;
10-
#[allow(unused_extern_crates)]
1110
extern crate libz_sys;
1211

1312
// The jsimpls module just implements traits so can be private
@@ -19,7 +18,7 @@ pub mod jsid;
1918
pub mod jsval;
2019

2120
// Reexport the bindings in the jsapi module
22-
pub use generated::root as jsapi;
21+
pub use crate::generated::root as jsapi;
2322

2423
// The bindings generated by bindgen
2524
#[doc(hidden)]

mozjs/tests/evaluate.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
extern crate mozjs_sys;
6-
75
use mozjs_sys::jsapi::glue::DeleteOwningCompileOptions;
86
use mozjs_sys::jsapi::glue::JS_Init;
97
use mozjs_sys::jsapi::glue::JS_NewOwningCompileOptions;

rust-mozjs/build.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
extern crate cc;
6-
75
use std::env;
86
use std::path::PathBuf;
97

0 commit comments

Comments
 (0)