Skip to content

Commit

Permalink
Packaging: add --no-lzma option for use with short
Browse files Browse the repository at this point in the history
  • Loading branch information
byeongkeunahn committed Dec 26, 2024
1 parent 76375f7 commit cf5135a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 5 additions & 1 deletion scripts/static-pie-gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import utils

try:
solution_src_path, target_name, elf_path, stub_path, lang_name, template_path = sys.argv[1:]
no_lzma = "--no-lzma" in sys.argv
argv = [x for x in sys.argv if x != "--no-lzma"]
solution_src_path, target_name, elf_path, stub_path, lang_name, template_path = argv[1:]
stub_path = locator.template_path(stub_path)
template_path = locator.template_path(template_path)
except ValueError:
Expand Down Expand Up @@ -124,6 +126,8 @@
template_candidates = [template_path]
if lang_name in ["C", "Rust"] and "x86_64" in target_name and "short" in template_path:
template_candidates.append(template_path.replace("short", "shorter"))
if no_lzma:
template_candidates = template_candidates[1:]

# exports
exports_dict = loader_fdict.get("exports", dict())
Expand Down
9 changes: 6 additions & 3 deletions scripts/static-pie.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@ def run_cmds(cmds):
raise Exception("Build command terminated with a non-zero exit code {}.".format(completed_process.returncode))

def main(args):
# TODO: devise way to handle short
cmds = []

target = args.target
lang = args.lang
profile = args.profile
profile_dir = {"Debug": "debug", "Release": "release"}[profile]
cargo_args = args.cargo_args
# We remove "--no-lzma" since it is not actually a cargo arg.
no_lzma, cargo_args = "--no-lzma" in cargo_args, [x for x in cargo_args if x != "--no-lzma"]

cargo_target_dir = os.environ.get("CARGO_TARGET_DIR", "target")
short = any("short" in x for x in cargo_args)
assert not(no_lzma and not short), "--no-lzma is only applicable when not using --features short"
python = "python" if os.name == "nt" else "python3"
solution_src_path = "basm/"

Expand Down Expand Up @@ -75,6 +77,7 @@ def main(args):
print(f"Language ${lang} is not supported for target ${target}", file=sys.stderr)
exit()
elif target == "wasm32-unknown-unknown":
assert not no_lzma, "--no-lzma is only applicable for C and Rust output"
if lang == "JavaScript":
template = "wasm-template.js"
elif lang == "HTML":
Expand Down Expand Up @@ -105,14 +108,14 @@ def main(args):
cmds.append(["cargo", "+nightly", "build"] + extra_config + ["--target", target_cargo, "--bin", "basm-submit", "--features=submit", "--release"] + cargo_args)

if target in ["x86_64-pc-windows-msvc", "x86_64-pc-windows-gnu"]:
cmds.append([python, "scripts/static-pie-gen.py", solution_src_path, target, f"{cargo_target_dir}/{target}/{profile_dir}/basm-submit.exe", stub, lang, template])
cmds.append([python, "scripts/static-pie-gen.py", solution_src_path, target, f"{cargo_target_dir}/{target}/{profile_dir}/basm-submit.exe", stub, lang, template] + (["--no-lzma"] if no_lzma else []))
elif target in "wasm32-unknown-unknown":
cmds.append([python, "scripts/wasm-gen.py", solution_src_path, template, lang])
else:
cmds.append(["cp", f"{cargo_target_dir}/{target}/{profile_dir}/basm-submit", f"{cargo_target_dir}/{target}/{profile_dir}/basm-submit-stripped"])
cmds.append(["objcopy", "--strip-all", f"{cargo_target_dir}/{target}/{profile_dir}/basm-submit-stripped"])
cmds.append(["objcopy", "--remove-section", ".eh_frame", "--remove-section", ".gcc_except_table", "--remove-section", ".gnu.hash", f"{cargo_target_dir}/{target}/{profile_dir}/basm-submit-stripped"])
cmds.append([python, "scripts/static-pie-gen.py", solution_src_path, target, f"{cargo_target_dir}/{target}/{profile_dir}/basm-submit-stripped", stub, lang, template])
cmds.append([python, "scripts/static-pie-gen.py", solution_src_path, target, f"{cargo_target_dir}/{target}/{profile_dir}/basm-submit-stripped", stub, lang, template] + (["--no-lzma"] if no_lzma else []))

run_cmds(cmds)

Expand Down

0 comments on commit cf5135a

Please sign in to comment.