Skip to content

Commit

Permalink
Merge pull request #1425 from ribbanya/pr/dtk-template
Browse files Browse the repository at this point in the history
Update `dtk-template`
  • Loading branch information
ribbanya authored Aug 12, 2024
2 parents a8e27ea + 2b9aa23 commit 01c4d1c
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 32 deletions.
9 changes: 5 additions & 4 deletions .nix/decomp-toolkit.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

rustPlatform.buildRustPackage rec {
pname = "decomp-toolkit";
version = "0.7.5";
version = "0.9.3";

src = fetchFromGitHub {
owner = "encounter";
repo = "decomp-toolkit";
rev = "v${version}";
hash = "sha256-DvZCJRGn6C2FXVlMQTUdmT5+J8raM+RE2Jhzx08VhT4=";
hash = "sha256-5EWZwAQNso58WIWKtXNiDDBjMUYYArdRREtyD0bXurY=";
};

nativeBuildInputs = [
Expand All @@ -22,8 +22,9 @@ rustPlatform.buildRustPackage rec {

cargoLock.lockFile = "${src}/Cargo.lock";
cargoLock.outputHashes."ar-0.8.0" = "sha256-OLyo+cRRWMsI1i8NsgsBKRJH1XsKW1CculQnJ/wcya0=";
cargoLock.outputHashes."dol-0.1.0" = "sha256-YfMXWNtmZJhK39R3w98DEGm4y9x59osFGliG36BcuLU=";
cargoLock.outputHashes."objdiff-core-1.0.0" = "sha256-KXQ8oTRhe7zsmQH69dz4/qgiwcLfEBjTbSi5IJHlL08=";
cargoLock.outputHashes."nod-1.2.0" = "sha256-M7jSBo1Dqrhy/F0osoUtTMNm2BkFnRy2MOmkTs1pvdM=";
cargoLock.outputHashes."objdiff-core-2.0.0-alpha.3" = "sha256-E597zRlSpxrTGino7jqoQmyxWkLYXT1P6U2PRolm0Ek=";
cargoLock.outputHashes."ppc750cl-0.3.0" = "sha256-nMJk+rgu7Ydi2VZfodJk0kBz9xLLVBVz0vEZPee8Q6M=";

meta = with lib; {
description = "A GameCube & Wii decompilation toolkit";
Expand Down
33 changes: 26 additions & 7 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@
from pathlib import Path
from typing import Iterator, List, Optional

from tools.project import (LibDict, Object, ProjectConfig, calculate_progress,
generate_build, is_windows)
from tools.project import (
LibDict,
Object,
ProjectConfig,
calculate_progress,
generate_build,
is_windows,
)

# Game versions
DEFAULT_VERSION = 0
Expand All @@ -33,6 +39,7 @@
nargs="?",
)
parser.add_argument(
"-v",
"--version",
choices=VERSIONS,
type=str.upper,
Expand Down Expand Up @@ -128,10 +135,16 @@
action="store_true",
help="require function prototypes",
)
parser.add_argument(
"--non-matching",
dest="non_matching",
action="store_true",
help="builds equivalent (but non-matching) or modded objects",
)
args = parser.parse_args()

config = ProjectConfig()
config.version = args.version
config.version = str(args.version)
version_num = VERSIONS.index(config.version)

# Apply arguments
Expand All @@ -141,6 +154,7 @@
config.compilers_path = args.compilers
config.debug = args.debug
config.generate_map = args.map
config.non_matching = args.non_matching
config.sjiswrap_path = args.sjiswrap
if not is_windows():
config.wrapper = args.wrapper
Expand All @@ -150,7 +164,7 @@
# Tool versions
config.binutils_tag = "2.42-1"
config.compilers_tag = "20231018"
config.dtk_tag = "v0.7.5"
config.dtk_tag = "v0.9.3"
config.sjiswrap_tag = "v1.1.1"
config.wibo_tag = "0.6.11"

Expand All @@ -169,6 +183,8 @@
"-nodefaults",
"-warn off",
]
# Use for any additional files that should cause a re-configure when modified
config.reconfig_deps = []

# Progress
config.progress_use_fancy = True
Expand Down Expand Up @@ -360,8 +376,11 @@ def RuntimeLib(lib_name: str, objects: Objects) -> LibDict:
)


Matching = True
NonMatching = False
Matching = True # Object matches and should be linked
NonMatching = False # Object does not match and should not be linked
Equivalent = (
config.non_matching
) # Object should be linked when configured with --non-matching

config.warn_missing_config = True
config.warn_missing_source = True
Expand Down Expand Up @@ -459,7 +478,7 @@ def RuntimeLib(lib_name: str, objects: Objects) -> LibDict:
Object(NonMatching, "melee/ft/ft_0892.c"),
# Common
Object(Matching, "melee/ft/chara/ftCommon/ftCo_Wait.c"),
Object(Matching, "melee/ft/ftwaitanim.c"),
Object(NonMatching, "melee/ft/ftwaitanim.c"),
Object(Matching, "melee/ft/chara/ftCommon/ftCo_Attack1.c"),
Object(Matching, "melee/ft/chara/ftCommon/ftCo_AttackDash.c"),
Object(Matching, "melee/ft/chara/ftCommon/ftCo_AttackS3.c"),
Expand Down
125 changes: 104 additions & 21 deletions tools/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def __init__(self) -> None:
self.sjiswrap_path: Optional[Path] = None # If None, download

# Project config
self.non_matching: bool = False
self.build_rels: bool = True # Build REL files
self.check_sha_path: Optional[Path] = None # Path to version.sha1
self.config_path: Optional[Path] = None # Path to config.yml
Expand All @@ -92,6 +93,15 @@ def __init__(self) -> None:
self.shift_jis = (
True # Convert source files from UTF-8 to Shift JIS automatically
)
self.reconfig_deps: Optional[List[Path]] = (
None # Additional re-configuration dependency files
)
self.custom_build_rules: Optional[List[Dict[str, Any]]] = (
None # Custom ninja build rules
)
self.custom_build_steps: Optional[Dict[str, List[Dict[str, Any]]]] = (
None # Custom build steps, types are ["pre-compile", "post-compile", "post-link", "post-build"]
)

# Progress output and progress.json config
self.progress_all: bool = True # Include combined "all" category
Expand Down Expand Up @@ -441,6 +451,48 @@ def generate_build_ninja(
)
n.newline()

n.comment("Custom project build rules (pre/post-processing)")
for rule in config.custom_build_rules or {}:
n.rule(
name=rule.get("name"),
command=rule.get("command"),
description=rule.get("description", None),
depfile=rule.get("depfile", None),
generator=rule.get("generator", False),
pool=rule.get("pool", None),
restat=rule.get("restat", False),
rspfile=rule.get("rspfile", None),
rspfile_content=rule.get("rspfile_content", None),
deps=rule.get("deps", None),
)
n.newline()

def write_custom_step(step: str) -> List[str]:
implicit = []
if config.custom_build_steps and step in config.custom_build_steps:
n.comment(f"Custom build steps ({step})")
for custom_step in config.custom_build_steps[step]:
outputs = custom_step.get("outputs")

if isinstance(outputs, list):
implicit.extend(outputs)
else:
implicit.append(outputs)

n.build(
outputs=outputs,
rule=custom_step.get("rule"),
inputs=custom_step.get("inputs", None),
implicit=custom_step.get("implicit", None),
order_only=custom_step.get("order_only", None),
variables=custom_step.get("variables", None),
implicit_outputs=custom_step.get("implicit_outputs", None),
pool=custom_step.get("pool", None),
dyndep=custom_step.get("dyndep", None),
)
n.newline()
return implicit

n.comment("Host build")
n.variable("host_cflags", "-I include -Wno-trigraphs")
n.variable(
Expand All @@ -459,6 +511,9 @@ def generate_build_ninja(
)
n.newline()

# Add all build steps needed before we compile (e.g. processing assets)
precompile_implicit = write_custom_step("pre-compile")

###
# Source files
###
Expand Down Expand Up @@ -509,16 +564,15 @@ def write(self, n: ninja_syntax.Writer) -> None:
outputs=elf_path,
rule="link",
inputs=self.inputs,
implicit=[self.ldscript, *mwld_implicit],
implicit=[
*precompile_implicit,
self.ldscript,
*mwld_implicit,
*postcompile_implicit,
],
implicit_outputs=elf_map,
variables={"ldflags": elf_ldflags},
)
n.build(
outputs=dol_path,
rule="elf2dol",
inputs=elf_path,
implicit=dtk,
)
else:
preplf_path = build_path / self.name / f"{self.name}.preplf"
plf_path = build_path / self.name / f"{self.name}.plf"
Expand Down Expand Up @@ -555,6 +609,7 @@ def write(self, n: ninja_syntax.Writer) -> None:
)
n.newline()

link_outputs: List[Path] = []
if build_config:
link_steps: List[LinkStep] = []
used_compiler_versions: Set[str] = set()
Expand Down Expand Up @@ -690,6 +745,7 @@ def add_unit(build_obj, link_step: LinkStep):
).with_suffix(".s")

link_built_obj = obj.completed
built_obj_path: Optional[Path] = None
if unit_src_path.exists():
if unit_src_path.suffix in (".c", ".cp", ".cpp"):
# Add MWCC & host build rules
Expand All @@ -705,7 +761,6 @@ def add_unit(build_obj, link_step: LinkStep):
link_built_obj = False

# Assembly overrides
built_obj_path: Optional[Path] = None
if unit_asm_path is not None and unit_asm_path.exists():
link_built_obj = True
built_obj_path = asm_build(obj, options, lib_name, unit_asm_path)
Expand Down Expand Up @@ -757,13 +812,30 @@ def add_unit(build_obj, link_step: LinkStep):
if config.compilers_path and not os.path.exists(mw_path):
sys.exit(f"Linker {mw_path} does not exist")

# Add all build steps needed before we link and after compiling objects
postcompile_implicit = write_custom_step("post-compile")

###
# Link
###
for step in link_steps:
step.write(n)
link_outputs.append(step.output())
n.newline()

# Add all build steps needed after linking and before GC/Wii native format generation
postlink_implicit = write_custom_step("post-link")

###
# Generate DOL
###
n.build(
outputs=link_steps[0].output(),
rule="elf2dol",
inputs=link_steps[0].partial_output(),
implicit=[*postlink_implicit, dtk],
)

###
# Generate RELs
###
Expand Down Expand Up @@ -826,6 +898,9 @@ def add_unit(build_obj, link_step: LinkStep):
)
n.newline()

# Add all build steps needed post-build (re-building archives and such)
postbuild_implicit = write_custom_step("post-build")

###
# Helper rule for building all source files
###
Expand Down Expand Up @@ -863,7 +938,7 @@ def add_unit(build_obj, link_step: LinkStep):
outputs=ok_path,
rule="check",
inputs=config.check_sha_path,
implicit=[dtk, *map(lambda step: step.output(), link_steps)],
implicit=[dtk, *link_outputs, *postbuild_implicit],
)
n.newline()

Expand Down Expand Up @@ -963,6 +1038,7 @@ def add_unit(build_obj, link_step: LinkStep):
configure_script,
python_lib,
python_lib_dir / "ninja_syntax.py",
*(config.reconfig_deps or []),
],
)
n.newline()
Expand All @@ -972,7 +1048,10 @@ def add_unit(build_obj, link_step: LinkStep):
###
n.comment("Default rule")
if build_config:
n.default(progress_path)
if config.non_matching:
n.default(link_outputs)
else:
n.default(progress_path)
else:
n.default(build_config_path)

Expand Down Expand Up @@ -1022,20 +1101,20 @@ def generate_objdiff_config(
"GC/2.5": "mwcc_247_105",
"GC/2.6": "mwcc_247_107",
"GC/2.7": "mwcc_247_108",
"GC/3.0": "mwcc_41_60831",
# "GC/3.0a3": "mwcc_41_51213",
"GC/3.0a3": "mwcc_41_51213",
"GC/3.0a3.2": "mwcc_41_60126",
# "GC/3.0a3.3": "mwcc_41_60209",
# "GC/3.0a3.4": "mwcc_42_60308",
# "GC/3.0a5": "mwcc_42_60422",
"GC/3.0a3.3": "mwcc_41_60209",
"GC/3.0a3.4": "mwcc_42_60308",
"GC/3.0a5": "mwcc_42_60422",
"GC/3.0a5.2": "mwcc_41_60831",
"GC/3.0": "mwcc_41_60831",
"Wii/1.0RC1": "mwcc_42_140",
"Wii/0x4201_127": "mwcc_42_142",
# "Wii/1.0": "mwcc_43_145",
# "Wii/1.0RC1": "mwcc_42_140",
"Wii/1.0a": "mwcc_42_142",
"Wii/1.0": "mwcc_43_145",
"Wii/1.1": "mwcc_43_151",
"Wii/1.3": "mwcc_43_172",
# "Wii/1.5": "mwcc_43_188",
"Wii/1.5": "mwcc_43_188",
"Wii/1.6": "mwcc_43_202",
"Wii/1.7": "mwcc_43_213",
}
Expand Down Expand Up @@ -1108,10 +1187,14 @@ def keep_flag(flag):
if compiler_version is None:
print(f"Missing scratch compiler mapping for {options['mw_version']}")
else:
cflags_str = make_flags_str(cflags)
if options["extra_cflags"] is not None:
extra_cflags_str = make_flags_str(options["extra_cflags"])
cflags_str += " " + extra_cflags_str
unit_config["scratch"] = {
"platform": "gc_wii",
"compiler": compiler_version,
"c_flags": make_flags_str(cflags),
"c_flags": cflags_str,
"ctx_path": src_ctx_path,
"build_ctx": True,
}
Expand Down Expand Up @@ -1228,8 +1311,8 @@ def print_category(unit: Optional[ProgressUnit]) -> None:
if config.progress_use_fancy:
code_items = math.floor(code_frac * unit.code_fancy_frac)
print(
"\nYou have {} of {} {} and completed {} of {} {}.".format(
code_items,
"\nYou have {} out of {} {} and {} out of {} {}.".format(
math.floor(code_frac * unit.code_fancy_frac),
unit.code_fancy_frac,
unit.code_fancy_item,
math.floor(data_frac * unit.data_fancy_frac),
Expand Down

0 comments on commit 01c4d1c

Please sign in to comment.