Skip to content

Fix generator polyglot bootstrap script failures on Windows and macOS #216

Description

@solevic

Problem

The current stub.sh generator script fails to run correctly on certain platforms:

  • Windows: Requires CRLF line endings for the Batch portion of the polyglot script
  • macOS: Newer versions require a valid shebang

Context

The original polyglot script was generated via sbt-assembly's defaultUniversalScript, which handled mixed line endings and shebang injection.

Having a stub.sh with mixed line endings is not possible because of Git line endings normalization.

Proposed Solution

The stub should be generated dynamically during the build process using a Bazel genrule. This allows to explicitly write CRLF bytes for the Windows section while keeping LF for the Unix section.

  1. Create a stub genrule: This rule constructs the script line-by-line, enforcing the correct line endings.
genrule(
    name = "stub",
    outs = ["stub.sh"],
    cmd = """
    printf '#!/usr/bin/env sh\n' > $@
    printf '@ 2>/dev/null # 2>nul & echo off & goto BOF\n' >> $@
    printf ':\n' >> $@
    printf 'exec java -jar $${JAVA_OPTS:-} "$$0" "$$@"\n' >> $@
    printf 'exit\n' >> $@
    printf '\n' >> $@
    printf ':BOF\r\n' >> $@
    printf '@echo off\r\n' >> $@
    printf 'java -jar %%JAVA_OPTS%% "%%~dpnx0" %%*\r\n' >> $@
    printf 'exit /B %%errorlevel%%\r\n' >> $@
    """,
)
  1. Update the generator rule: Depend on the generated stub and concatenate it with the deploy jar.
genrule(
    name = "generator",
    srcs = [":stub", "//src:djinni_deploy.jar"],
    outs = ["djinni"],
    cmd = "cat $(location :stub) $(location //src:djinni_deploy.jar) > $@ && chmod +x $@",
    executable = True
)

If this solution is appropriate, I can provide a pull request with the changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions