Skip to content

Improve the rerun logic for the config target - #348

Merged
jserv merged 4 commits into
sysprog21:masterfrom
DrXiao:enhance-rebuild-logic
Oct 25, 2026
Merged

jserv merged 4 commits into
sysprog21:masterfrom
DrXiao:enhance-rebuild-logic

Conversation

@DrXiao

@DrXiao DrXiao commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Running make previously always triggered the config and the bootstrap targets to execute because the value of TRANSLATION_DEFS differed on every run, causing the auto-generated config file to be updated and the bootstrap target to run through an indirect dependency.

The proposed changes primarily rewrite the Makefile logic to enable the build system to check the configuration switches (ARCH/DYNLINK/BINDING) and to determine whether a reconfiguration or a rebuild should be performed.

Now, the aforementioned variables are stored in the build session file (BINDING is stored only when dynamic linking is enabled) after the config target is triggered. For the next make run, the build system will verify whether any of these variables has changed and whether the rerun requirements are met.


Test cases:

# Case 1: the first build is performed directly.
$ make
Configurations: (arm, static linking)
...
Warning: discarding const qualifier in cast

# Case 2: directly running "make" again -> No action.
$ make
Keep configurations

# Case 3: Switch from static linking to dynamic linking.
$ make DYNLINK=1
Configurations: (arm, dynamic linking, lazy binding)
  CC    out/src/main.o
...

# Case 4: Switch from lazy binding to immediate binding.
$ make BINDING=now
Configurations: (arm, dynamic linking, immediate binding)
...

# Case 5: Switch from arm to x64 (an architecture switch).
#         Note that dynamic linking and immediate binding are kept.
$ make ARCH=x64
Configurations: (x64, dynamic linking, immediate binding)
...

Summary by cubic

Rerunning make no longer always reconfigures and rebuilds the bootstrap target. The build system now records ARCH, DYNLINK, and BINDING in a build session file and only reconfigures when one of these switches, printing Keep configurations otherwise. Passing BINDING with static linking now aborts the build instead of silently ignoring it.

  • Reworks the Makefile conditionals so the config target writes the generated config file and session file only when NEED_RECONFIGURE is set.
  • Defaults BINDING to undefined and sets it to lazy only when DYNLINK=1.
  • Updates the README with the new configuration switch behavior and error cases.

Written for commit ef884db. Summary will update on new commits.

View guided diff

cubic-dev-ai[bot]

This comment was marked as resolved.

Comment thread Makefile
Comment thread Makefile Outdated
Comment thread Makefile
Comment thread Makefile Outdated
@jserv

jserv commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator

Merging this as is turns every static-linking CI job red: the workflow passes BINDING=lazy with DYNLINK=0, and the new check aborts at parse time. See the comment on the $(error) line in Makefile for the options.

@DrXiao
DrXiao force-pushed the enhance-rebuild-logic branch from ef884db to c484ba3 Compare October 25, 2026 11:27
Running "make" previously always ran the config target and indirectly
caused the bootstrap target to run as well. The main reason was that
the config target writes the TRANSLATION_DEFS variable, whose value
always differs on each run, to the generated "config" file. This
triggered the bootstrap target through the indirect dependency.

These changes therefore rewrite the Makefile logic as follows:
- Make the BINDING variable be undefined by default. Conditionally set
  it to lazy when DYNLINK is set to 1.
- The build system reads the configuration from the build session file
  if it exists, and then sets the NEED_RECONFIGURE variable if any of
  the following conditions is met:
  - ARCH is switched to another target architecture.
  - DYNLINK is switched.
  - BINDING is switched in the dynamic linking mode.
- The config target is modified by introducing several 'ifeq'
  conditionals. Once NEED_RECONFIGURE is set to 1, this target directly
  writes the required "config" file and the build session file;
  otherwise, it only prints a hint message and takes no action.

The DYNLINK and BINDING checks have also been enhanced to prevent
invalid configurations.

Eventually, the config target does not modify the "config" file or the
build session file if the ARCH/DYNLINK/BINDING switches do not affect
the build.

The aforementioned issue in the first paragraph can also be resolved.

Close sysprog21#347
If the ARCH_DEFS variable in the selected target architecture's Makefile
fragment is modified after an initial build or configuration, running
"make" again does not cause the config target to run again.

The build system now writes a SHA-256 checksum of the content of
ARCH_DEFS to a file (archdefs.sha256) and uses this file to determine
whether the next run should execute the config target. If the new
SHA-256 checksum does not equal to the previous checksum recorded in the
file, NEED_RECONFIGURE is set to 1, allowing a reconfiguration to be
performed.
Since the previous commit has improved the build logic, this commit
updates the related descriptions in the README, including:
- Rewriting the reference messages for running "make".
- Describing the conditions and behavior for a rebuild or
  a reconfiguration.
The Makefile now retains the ARCH/DYNLINK/BINDING configurations
via the build session file, and static builds reject a non-empty
BINDING. The following changes are introduced:
- The CI matrices are fixed by leaving BINDING empty instead of
  "lazy" when verifying static builds. This avoids passing
  "BINDING=lazy" to those builds and prevents them from failing.
- Because the build system can keep configurations via the stored
  session, not every step that runs "make" needs to explicitly assign
  them. Some CI steps have been improved by removing the redundant
  variable assignments.
- Outdated comments have been removed.
@DrXiao
DrXiao force-pushed the enhance-rebuild-logic branch from c484ba3 to 0c21ef7 Compare October 25, 2026 11:30
@DrXiao

DrXiao commented Oct 25, 2026

Copy link
Copy Markdown
Collaborator Author

2c73c41 handles configuration switches, but it can not deal with the cases where ARCH_DEFS (in mk/*.mk) is modified after an initial configuration/build.

2088fd8 is therefore introduced to handle such cases. The build system now writes a SHA-256 checksum of the content of ARCH_DEFS to a file (archdefs.sha256), and the next make run can use this file and the new checksum to determine whether ARCH_DEFS has changed and whether the config target should be run.

@DrXiao
DrXiao requested a review from jserv October 25, 2026 11:57
@jserv
jserv merged commit 8a59f89 into sysprog21:master Oct 25, 2026
55 checks passed
@jserv

jserv commented Oct 25, 2026

Copy link
Copy Markdown
Collaborator

Thank @DrXiao for contributing!

@DrXiao
DrXiao deleted the enhance-rebuild-logic branch October 25, 2026 12:18
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.

2 participants