Skip to content

Commit ecb8918

Browse files
committed
Fix windows debug builds.
* Better venv support * Fix PDB generation collision for debug builds * Make automatically generated object files from spork/cc indicate where they come from via file extensions to prevent collisions.
1 parent fd550e1 commit ecb8918

File tree

4 files changed

+26
-23
lines changed

4 files changed

+26
-23
lines changed

spork/cc.janet

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@
292292
# Compound commands
293293

294294
(defn out-path
295-
"Take a source file path and convert it to an output path."
295+
"Take a source file path and convert it to an output path with no intermediate directories."
296296
[path to-ext &opt sep]
297297
(default sep "/")
298298
(def flatpath
@@ -305,11 +305,11 @@
305305
"Compile a number of source files, and return the
306306
generated objects files, as well as a boolean if any cpp
307307
source files were found."
308-
[sources cmds-into]
308+
[sources cmds-into ext]
309309
(def objects @[])
310310
(var has-cpp false)
311311
(each source sources
312-
(def o (out-path source ".o"))
312+
(def o (out-path source ext))
313313
(def source-type (classify-source source))
314314
(case source-type
315315
:o
@@ -331,7 +331,7 @@
331331
"Compile and link a shared C/C++ library. Return an array of commands."
332332
[to & sources]
333333
(def res @[])
334-
(def [has-cpp objects] (compile-many sources res))
334+
(def [has-cpp objects] (compile-many sources res ".shared.o"))
335335
(array/push
336336
res
337337
(if has-cpp
@@ -342,7 +342,7 @@
342342
"Compile and link an executable C/C++ program. Return an array of commands."
343343
[to & sources]
344344
(def res @[])
345-
(def [has-cpp objects] (compile-many sources res))
345+
(def [has-cpp objects] (compile-many sources res ".executable.o"))
346346
(array/push
347347
res
348348
(if has-cpp
@@ -353,7 +353,7 @@
353353
"Compile and create a static archive. Return an array of commands."
354354
[to & sources]
355355
(def res @[])
356-
(def [_ objects] (compile-many sources res))
356+
(def [_ objects] (compile-many sources res ".static.o"))
357357
(array/push res (make-archive objects to)))
358358

359359
###
@@ -436,9 +436,10 @@
436436
nil)
437437

438438
(defn- msvc-opt
439-
[]
439+
[to]
440+
(def pdb-name (string to ".pdb"))
440441
(case (build-type)
441-
:debug ["/Od" "/Zi" "/MDd"]
442+
:debug ["/Od" "/Zi" "/MDd" (string "/Fd" pdb-name)]
442443
["/O2" "/MD"]))
443444
(defn- msvc-defines []
444445
(def res @[])
@@ -485,14 +486,14 @@
485486
(defn msvc-compile-c
486487
"Compile a C source file with MSVC to an object file. Return the command arguments."
487488
[from to]
488-
(exec [(cl.exe) "/c" (msvc-cstd) "/utf-8" "/nologo" ;(cflags) ;(msvc-compile-paths) ;(msvc-opt) ;(msvc-defines)
489+
(exec [(cl.exe) "/c" (msvc-cstd) "/utf-8" "/nologo" ;(cflags) ;(msvc-compile-paths) ;(msvc-opt to) ;(msvc-defines)
489490
from (string "/Fo" to)]
490491
[from] [to] (string "compiling " from "...")))
491492

492493
(defn msvc-compile-c++
493494
"Compile a C++ source file with MSVC to an object file. Return the command arguments."
494495
[from to]
495-
(exec [(cl.exe) "/c" (msvc-c++std) "/utf-8" "/nologo" "/EHsc" ;(c++flags) ;(msvc-compile-paths) ;(msvc-opt) ;(msvc-defines)
496+
(exec [(cl.exe) "/c" (msvc-c++std) "/utf-8" "/nologo" "/EHsc" ;(c++flags) ;(msvc-compile-paths) ;(msvc-opt to) ;(msvc-defines)
496497
from (string "/Fo" to)]
497498
[from] [to] (string "compiling " from "...")))
498499

@@ -520,10 +521,10 @@
520521
"Compile a number of source files, and return the
521522
generated objects files, as well as a boolean if any cpp
522523
source files were found."
523-
[sources cmds-into]
524+
[sources cmds-into ext]
524525
(def objects @[])
525526
(each source sources
526-
(def o (out-path source ".o" "\\"))
527+
(def o (out-path source ext "\\"))
527528
(def source-type (classify-source source))
528529
(case source-type
529530
:o
@@ -544,7 +545,7 @@
544545
"Compile and link a shared C/C++ library. Return an array of commands."
545546
[to & sources]
546547
(def res @[])
547-
(def objects (msvc-compile-many sources res))
548+
(def objects (msvc-compile-many sources res ".shared.o"))
548549
(array/push
549550
res
550551
(msvc-link-shared objects to)))
@@ -553,7 +554,7 @@
553554
"Compile and link an executable C/C++ program. Return an array of commands."
554555
[to & sources]
555556
(def res @[])
556-
(def objects (msvc-compile-many sources res))
557+
(def objects (msvc-compile-many sources res ".executable.o"))
557558
(array/push
558559
res
559560
(msvc-link-executable objects to)))
@@ -562,7 +563,7 @@
562563
"Compile and create a static archive. Return an array of commands."
563564
[to & sources]
564565
(def res @[])
565-
(def objects (msvc-compile-many sources res))
566+
(def objects (msvc-compile-many sources res ".static.o"))
566567
(array/push res (msvc-make-archive objects to)))
567568

568569
###

spork/declare-cc.janet

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,8 @@
493493
(install-rule to (string name suffix))
494494
(def objects @[])
495495
(loop [src :in embedded]
496-
(def c-src (cc/out-path src ".c"))
497-
(def o-src (cc/out-path src ".o"))
496+
(def c-src (cc/out-path src ".dynamic.c"))
497+
(def o-src (cc/out-path src ".dynamic.o"))
498498
(array/push objects o-src)
499499
(build-rules/build-rule rules c-src [src]
500500
(create-buffer-c (slurp src) c-src (embed-name src)))
@@ -512,8 +512,8 @@
512512
cc/*defines* (merge-into @{"JANET_ENTRY_NAME" ename} defines)]
513513
(def sobjects @[])
514514
(loop [src :in embedded]
515-
(def c-src (cc/out-path src ".c"))
516-
(def o-src (cc/out-path src ".o"))
515+
(def c-src (cc/out-path src ".static.c"))
516+
(def o-src (cc/out-path src ".static.o"))
517517
(array/push sobjects o-src)
518518
(build-rules/build-rule rules c-src [src]
519519
(create-buffer-c (slurp src) c-src (embed-name src)))

spork/pm-config.janet

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757
(assertf (in enum-set y) "unknown option %v for %s. Expected one of %s." x name (string/join options ", "))
5858
y))
5959

60-
(def- build-type-xform (make-enum "build type" "debug" "develop" "release"))
61-
(def- toochain-xform (make-enum "toolchain" "gcc" "clang" "msvc" "cc")) # TODO mingw, zig
60+
(def- build-type-xform (make-enum "build type" :debug :develop :release))
61+
(def- toochain-xform (make-enum "toolchain" :gcc :clang :msvc :cc)) # TODO mingw, zig
6262

6363
(defn read-env-variables
6464
"Read and validate environment variables for configuration. These environment variables are

spork/pm.janet

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@
672672
@set _OLD_PATH=%PATH%
673673
@set _OLD_PROMPT=%PROMPT%
674674
@set JANET_PATH=$abspath
675-
@set PATH=%JANET_PATH%\bin:%PATH%
675+
@set PATH=%JANET_PATH%\bin;%PATH%
676676
@set PROMPT=($path) %PROMPT%
677677
````)
678678

@@ -698,4 +698,6 @@
698698
(spit (path/join path "bin" "activate.bat") (enter-cmd-template opts))
699699
(spit (path/join path "bin" "deactivate.bat") (exit-cmd-template opts))
700700
(print "created project shell environment at " path)
701-
(print "run `. " path "/bin/activate` to enter the new environment, then `deactivate` to exit."))
701+
(if (or (= :windows (os/which)) (= :mingw (os/which)))
702+
(print "run `" path "\\bin\\activate` to enter the new environment, then `deactivate` to exit.")
703+
(print "run `. " path "/bin/activate` to enter the new environment, then `deactivate` to exit.")))

0 commit comments

Comments
 (0)