Skip to content

juliac.jl --trim build fails with Sockets module #59397

@arch-dev

Description

@arch-dev

Environment

  • Julia version: 1.12.0-rc1
  • OS: Windows 11 (x64)

Description

Attempting to compile a Julia script which implements Sockets module into a standalone executable with juliac.jl --experimental --trim in Julia 1.12.0-rc1 fails with Verifier error #...: unresolved call from statement ....

Compiling without --trim succeeds.

Steps to reproduce

Paste the following minimal working example into SocketTest.jl:

module SocketTest

using Sockets

export main

function @main(args::Vector{String})::Cint
    sock = connect("localhost", parse(Int, args[1]))

    if isopen(sock)
        write(sock, "Hello")
        flush(sock)
        close(sock)
    end

    return 0
end

end

using .SocketTest

Compiling with --trim:

julia --project=. ...\contrib\juliac\juliac.jl --experimental --output-exe sockettest --trim SocketTest.jl

fails with the following messages:

SocketTest_Logs.txt

Compiling without --trim succeeds.

Additional notes

I don't know if this is the correct way to do it (I'm not an expert), but inserting the snippet below into juliac-trim-stdlib.jl:

--- juliac-trim-stdlib_orig.jl	2025-07-13 01:17:33.000000000 +0200
+++ juliac-trim-stdlib.jl	2025-08-26 11:41:23.714173100 +0200
@@ -22,6 +22,19 @@
         end
     end
 
+    Sockets = find_loaded_root_module(Base.PkgId(
+        Base.UUID("6462fe0b-24de-5631-8697-dd941f90decc"), "Sockets"))
+    if Sockets !== nothing
+        @eval Sockets begin
+            function show(io::IO, stream::Base.LibuvStream)
+                print(io, typeof(stream), "(",
+                    Sys.iswindows() ? Base.Libc._get_osfhandle(stream) : Base._fd(stream), " ",
+                    Base.uv_status_string(stream), ", ",
+                    bytesavailable(stream.buffer), " bytes waiting)")
+            end
+        end
+    end
+
     Artifacts = find_loaded_root_module(Base.PkgId(
         Base.UUID("56f22d72-fd6d-98f1-02f0-08ddc0907c33"), "Artifacts"))
     if Artifacts !== nothing

seems to fix the errors related to show():

SocketTest_Logs_ShowFix.txt

Metadata

Metadata

Assignees

Labels

trimmingIssues with trimming functionality or PR's relevant to its performance/functionality

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions