Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,24 @@ jobs:
uses: actions/cache@v4
with:
path: rewatch/target
key: rewatch-build-v2-${{ matrix.rust-target }}-${{ hashFiles('rewatch/src/**', 'rewatch/Cargo.lock') }}
key: rewatch-build-v3-${{ matrix.rust-target }}-${{ hashFiles('rewatch/src/**', 'rewatch/Cargo.lock') }}

- name: Determine Rust toolchain version
id: rust-version
shell: bash
run: |
version="$(awk -F '"' '/^rust-version[[:space:]]*=/ { print $2; exit }' rewatch/Cargo.toml)"
if [ -z "$version" ]; then
echo "rust-version missing in rewatch/Cargo.toml" >&2
exit 1
fi
echo "version=${version}" >> "$GITHUB_OUTPUT"

- name: Install rust toolchain
if: steps.rewatch-build-cache.outputs.cache-hit != 'true'
uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.88.0
toolchain: ${{ steps.rust-version.outputs.version }}
targets: ${{ matrix.rust-target }}
components: clippy, rustfmt

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

- Rename Core to Stdlib in tests/tests. https://github.com/rescript-lang/rescript/pull/8005
- CI: Build on `windows-2025` runners. https://github.com/rescript-lang/rescript/pull/8006
- Rewatch: upgrade Rust to 1.91.0. https://github.com/rescript-lang/rescript/pull/8007

# 12.0.0-rc.3

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Happy hacking!
- [Yarn CLI](https://yarnpkg.com/getting-started/install) (can be installed with `corepack`, Homebrew, etc)
- C compiler toolchain (usually installed with `xcode` on Mac)
- Python <= 3.11 (required to build ninja)
- Rust toolchain (required to build rewatch; follow the instructions at https://www.rust-lang.org/tools/install)
- Rust toolchain (required to build rewatch; follow the instructions at https://www.rust-lang.org/tools/install and install the version listed as `rust-version` in `rewatch/Cargo.toml`)
- `opam` (OCaml Package Manager) v2.2.0 or newer
- VSCode (+ [OCaml Platform Extension](https://marketplace.visualstudio.com/items?itemName=ocamllabs.ocaml-platform))

Expand Down
2 changes: 1 addition & 1 deletion rewatch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "rescript"
version = "12.0.0-rc.4"
edition = "2024"
rust-version = "1.88"
rust-version = "1.91"

[dependencies]
ahash = "0.8.3"
Expand Down
19 changes: 10 additions & 9 deletions rewatch/src/build/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,11 @@ pub fn cleanup_previous_build(
// we do this by checking if the cmt file is newer than the AST file. We always compile the
// interface AND implementation. For some reason the CMI file is not always rewritten if it
// doesn't have any changes, that's why we just look at the CMT file.
if let Some(cmt_last_modified) = cmt_last_modified {
if cmt_last_modified > ast_last_modified && !deleted_interfaces.contains(module_name) {
module.compile_dirty = false;
}
if let Some(cmt_last_modified) = cmt_last_modified
&& cmt_last_modified > ast_last_modified
&& !deleted_interfaces.contains(module_name)
{
module.compile_dirty = false;
}

match &mut module.source_type {
Expand Down Expand Up @@ -302,11 +303,11 @@ fn has_compile_warnings(module: &Module) -> bool {
pub fn cleanup_after_build(build_state: &BuildCommandState) {
build_state.modules.par_iter().for_each(|(_module_name, module)| {
let package = build_state.get_package(&module.package_name).unwrap();
if has_parse_warnings(module) {
if let SourceType::SourceFile(source_file) = &module.source_type {
remove_iast(package, &source_file.implementation.path);
remove_ast(package, &source_file.implementation.path);
}
if has_parse_warnings(module)
&& let SourceType::SourceFile(source_file) = &module.source_type
{
remove_iast(package, &source_file.implementation.path);
remove_ast(package, &source_file.implementation.path);
}
if has_compile_warnings(module) {
// only retain AST file if the compilation doesn't have warnings, we remove the AST in favor
Expand Down
45 changes: 21 additions & 24 deletions rewatch/src/build/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,11 @@ pub fn compile(
// so editor tooling can surface it from .compiler.log
let mut touched_packages = AHashSet::<String>::new();
for module_name in cycle.iter() {
if let Some(module) = build_state.get_module(module_name) {
if touched_packages.insert(module.package_name.clone()) {
if let Some(package) = build_state.get_package(&module.package_name) {
logs::append(package, &message);
}
}
if let Some(module) = build_state.get_module(module_name)
&& touched_packages.insert(module.package_name.clone())
&& let Some(package) = build_state.get_package(&module.package_name)
{
logs::append(package, &message);
}
}

Expand Down Expand Up @@ -795,24 +794,23 @@ fn compile_file(

// copy js file
root_config.get_package_specs().iter().for_each(|spec| {
if spec.in_source {
if let SourceType::SourceFile(SourceFile {
if spec.in_source
&& let SourceType::SourceFile(SourceFile {
implementation: Implementation { path, .. },
..
}) = &module.source_type
{
let source = helpers::get_source_file_from_rescript_file(
&Path::new(&package.path).join(path),
&root_config.get_suffix(spec),
);
let destination = helpers::get_source_file_from_rescript_file(
&package.get_build_path().join(path),
&root_config.get_suffix(spec),
);

if source.exists() {
let _ = std::fs::copy(&source, &destination).expect("copying source file failed");
}
{
let source = helpers::get_source_file_from_rescript_file(
&Path::new(&package.path).join(path),
&root_config.get_suffix(spec),
);
let destination = helpers::get_source_file_from_rescript_file(
&package.get_build_path().join(path),
&root_config.get_suffix(spec),
);

if source.exists() {
let _ = std::fs::copy(&source, &destination).expect("copying source file failed");
}
}
});
Expand Down Expand Up @@ -912,10 +910,9 @@ pub fn mark_modules_with_expired_deps_dirty(build_state: &mut BuildCommandState)

if let (Some(last_compiled_dependent), Some(last_compiled)) =
(dependent_module.last_compiled_cmt, module.last_compiled_cmt)
&& last_compiled_dependent < last_compiled
{
if last_compiled_dependent < last_compiled {
modules_with_expired_deps.insert(dependent.to_string());
}
modules_with_expired_deps.insert(dependent.to_string());
}
}
}
Expand Down
14 changes: 9 additions & 5 deletions rewatch/src/build/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ pub fn initialize(packages: &AHashMap<String, Package>) {
packages.par_iter().for_each(|(name, package)| {
File::create(get_log_file_path(package, Location::Bs))
.map(|file| write_to_log_file(file, name, &format!("#Start({})\n", helpers::get_system_time())))
.expect(&("Cannot create compiler log for package ".to_owned() + name));
.unwrap_or_else(|err| {
panic!("Cannot create compiler log for package {name}: {err}");
});
})
}

Expand All @@ -64,10 +66,12 @@ pub fn append(package: &packages::Package, str: &str) {
.append(true)
.open(get_log_file_path(package, Location::Bs))
.map(|file| write_to_log_file(file, &package.name, str))
.expect(
&("Cannot write compilerlog: ".to_owned()
+ &get_log_file_path(package, Location::Bs).to_string_lossy()),
);
.unwrap_or_else(|err| {
panic!(
"Cannot write compilerlog: {} ({err})",
get_log_file_path(package, Location::Bs).to_string_lossy()
);
});
}

pub fn finalize(packages: &AHashMap<String, Package>) {
Expand Down
8 changes: 4 additions & 4 deletions rewatch/src/build/packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -882,10 +882,10 @@ fn get_unallowed_dependents(
for deps_package_name in dependencies {
if let Some(deps_package) = packages.get(deps_package_name) {
let deps_allowed_dependents = deps_package.config.allowed_dependents.to_owned();
if let Some(allowed_dependents) = deps_allowed_dependents {
if !allowed_dependents.contains(package_name) {
return Some(deps_package_name.to_string());
}
if let Some(allowed_dependents) = deps_allowed_dependents
&& !allowed_dependents.contains(package_name)
{
return Some(deps_package_name.to_string());
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions rewatch/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ fn get_files_in_scope() -> Result<Vec<String>> {
&& let Some(source_files) = &package.source_files
{
for (path, _metadata) in source_files {
if let Some(extension) = path.extension() {
if extension == "res" || extension == "resi" {
files.push(package.path.join(path).to_string_lossy().into_owned());
}
if let Some(extension) = path.extension()
&& (extension == "res" || extension == "resi")
{
files.push(package.path.join(path).to_string_lossy().into_owned());
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions rewatch/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ fn main() -> Result<()> {

let mut command = cli.command;

if let cli::Command::Build(build_args) = &command {
if build_args.watch {
log::warn!("`rescript build -w` is deprecated. Please use `rescript watch` instead.");
command = cli::Command::Watch(build_args.clone().into());
}
if let cli::Command::Build(build_args) = &command
&& build_args.watch
{
log::warn!("`rescript build -w` is deprecated. Please use `rescript watch` instead.");
command = cli::Command::Watch(build_args.clone().into());
}

let is_tty: bool = Term::stdout().is_term() && Term::stderr().is_term();
Expand Down
23 changes: 12 additions & 11 deletions rewatch/src/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ fn is_in_build_path(path_buf: &Path) -> bool {
let mut prev_component: Option<&std::ffi::OsStr> = None;
for component in path_buf.components() {
let comp_os = component.as_os_str();
if let Some(prev) = prev_component {
if prev == "lib" && (comp_os == "bs" || comp_os == "ocaml") {
return true;
}
if let Some(prev) = prev_component
&& prev == "lib"
&& (comp_os == "bs" || comp_os == "ocaml")
{
return true;
}
prev_component = Some(comp_os);
}
Expand Down Expand Up @@ -116,14 +117,14 @@ async fn async_watch(

for event in events {
// if there is a file named rescript.lock in the events path, we can quit the watcher
if event.paths.iter().any(|path| path.ends_with(LOCKFILE)) {
if let EventKind::Remove(_) = event.kind {
if show_progress {
println!("\nExiting... (lockfile removed)");
}
clean::cleanup_after_build(&build_state);
return Ok(());
if event.paths.iter().any(|path| path.ends_with(LOCKFILE))
&& let EventKind::Remove(_) = event.kind
{
if show_progress {
println!("\nExiting... (lockfile removed)");
}
clean::cleanup_after_build(&build_state);
return Ok(());
}

let paths = event
Expand Down
Loading