Skip to content

Conversation

@terasakisatoshi
Copy link
Member

Summary

This PR fixes a critical issue where Pkg.build() fails with a Permission denied error when the package is installed via Pkg.add() from a Git repository. The error occurs because the build script tries to write C_API.jl directly to the src/ directory, which is read-only in installed packages.

Problem

When installing the package from GitHub using:

Pkg.add(url="...", subdir="CalcPi.jl")
Pkg.build("CalcPi")

The build process fails with:

ERROR: LoadError: SystemError: opening file "./../src/C_API.jl": Permission denied

This happens because generate_C_API.jl tries to write directly to src/C_API.jl, which is read-only in the installed package directory.

Solution

  1. Added --output-dir option to generate_C_API.jl

    • Allows specifying a custom output directory for the generated file
    • Improves argument parsing to handle multiple options correctly
  2. Modified build.jl to use temporary directory

    • Generates C_API.jl in a temporary directory first
    • Attempts to copy to src/ if writable (development environment)
    • Gracefully handles read-only src/ for installed packages
    • Shows appropriate warnings when src/ is not writable
  3. Added test script

    • run.sh script to test package installation from GitHub
    • Useful for verifying that Pkg.add() and Pkg.test() work correctly

Changes

  • CalcPi.jl/utils/generate_C_API.jl: Added --output-dir option
  • CalcPi.jl/deps/build.jl: Use temporary directory and handle read-only src/
  • run.sh: Test script for package installation

Benefits

  • Fixes build failures for installed packages
  • Maintains compatibility with development workflow
  • Provides better error handling and user feedback
  • Allows testing package installation process

Testing

  • Tested in development environment (writable src/)
  • Tested with installed package (read-only src/)
  • Verified that existing C_API.jl is used when src/ is read-only

- Add --output-dir command-line option to specify output directory
- Improve argument parsing to handle multiple options correctly
- Allow generating C_API.jl to a custom location (useful for build scripts)
- Generate C_API.jl in temporary directory first
- Copy to src/ only if writable (development environment)
- Handle read-only src/ gracefully for installed packages
- Prevents build failures when package is installed via Pkg.add()
- Add run.sh script to test package installation from GitHub
- Useful for verifying that Pkg.add() and Pkg.test() work correctly
@terasakisatoshi terasakisatoshi merged commit 4696d9b into main Jan 8, 2026
15 of 23 checks passed
@terasakisatoshi terasakisatoshi deleted the fix-build-permission-error branch January 8, 2026 07:35
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