@ -3,18 +3,24 @@ const fs = std.fs;
const builtin = @import ( " builtin " ) ;
const builtin = @import ( " builtin " ) ;
const common = @import ( " ../build_common.zig " ) ;
const common = @import ( " ../build_common.zig " ) ;
const mkvar_thread_version = " 3.0.1 " ;
const mkvar_thread_zip_file = " libthread " + + mkvar_thread_version + + " .zip " ;
const mkvar_thread_vfs_root = " libthread.vfs " ;
const mkvar_thread_vfs_path = mkvar_thread_vfs_root + + " /thread_library " ;
const mkvar_pkg_lib_file = " tcl9thread301.dll " ;
/ / Although this function looks imperative , note that its job is to
/ / Although this function looks imperative , note that its job is to
/ / declaratively construct a build graph that will be executed by an external
/ / declaratively construct a build graph that will be executed by an external
/ / runner .
/ / runner .
/ / pub fn build ( b : * std . Build ) ! void { }
/ / pub fn build ( b : * std . Build ) ! void { }
pub fn build_tclthread ( comptime tcldir : [ ] const u8 , comptime subdir : [ ] const u8 , b : * std . Build , target : std . Build . ResolvedTarget , optimize : std . builtin . OptimizeMode , stublib : * std . Build . Step . Compile ) ! * std . Build . Step . Compile {
pub fn build_tclthread ( comptime tcldir : [ ] const u8 , comptime subdir : [ ] const u8 , b : * std . Build , target : std . Build . ResolvedTarget , optimize : std . builtin . OptimizeMode , stublib : * std . Build . Step . Compile ) ! * std . Build . Step . Compile {
/ / Version derived from the checkout ' s AC_INIT ( G - 107 ) : the recipe formerly
/ / hardcoded 3.0 . 1 , compiling newer trunk sources with a stale PACKAGE_VERSION -
/ / the dll then self - reported the wrong version and the thread testsuite ' s
/ / ' package require - exact thread < treeversion > ' could never load it . All
/ / version - derived names below ( dll , install dir , pkgIndex , resource fields )
/ / follow the tree .
const thread_version = common . acInitVersion ( b , subdir ) ;
const thread_vernodots = common . stripChars ( b , thread_version , " . " ) ;
const pkg_lib_name = b . fmt ( " tcl9thread{s} " , . { thread_vernodots } ) ;
const pkg_lib_file = b . fmt ( " {s}.dll " , . { pkg_lib_name } ) ;
var thread_verparts = std . mem . splitScalar ( u8 , thread_version , '.' ) ;
const thread_ver_major = thread_verparts . next ( ) orelse " 0 " ;
const thread_ver_minor = thread_verparts . next ( ) orelse " 0 " ;
const wrapfilecmd = b . addExecutable ( . {
const wrapfilecmd = b . addExecutable ( . {
. name = " wrapfiletofile " ,
. name = " wrapfiletofile " ,
. root_module = b . createModule ( . {
. root_module = b . createModule ( . {
@ -65,7 +71,7 @@ pub fn build_tclthread(comptime tcldir: []const u8, comptime subdir: []const u8,
const lib = b . addLibrary ( . {
const lib = b . addLibrary ( . {
. linkage = . dynamic ,
. linkage = . dynamic ,
. name = " tcl9thread301 " ,
. name = pkg_lib_name ,
. root_module = b . createModule ( . {
. root_module = b . createModule ( . {
. target = target ,
. target = target ,
. optimize = optimize ,
. optimize = optimize ,
@ -79,8 +85,8 @@ pub fn build_tclthread(comptime tcldir: []const u8, comptime subdir: []const u8,
try flags . appendSlice ( & . {
try flags . appendSlice ( & . {
" -DPACKAGE_NAME= \" thread \" " ,
" -DPACKAGE_NAME= \" thread \" " ,
" -DPACKAGE_TARNAME= \" thread \" " ,
" -DPACKAGE_TARNAME= \" thread \" " ,
" -DPACKAGE_VERSION= \" 3.0.1 \" " ,
b . fmt ( " -DPACKAGE_VERSION= \" {s} \" " , . { thread_version } ) ,
" -DPACKAGE_STRING= \" thread 3.0.1 \" " ,
b . fmt ( " -DPACKAGE_STRING= \" thread {s} \" " , . { thread_version } ) ,
" -DPACKAGE_BUGREPORT= \" \" " ,
" -DPACKAGE_BUGREPORT= \" \" " ,
" -DPACKAGE_URL= \" \" " ,
" -DPACKAGE_URL= \" \" " ,
" -DTCL_CFG_OPTIMIZED=1 " ,
" -DTCL_CFG_OPTIMIZED=1 " ,
@ -155,9 +161,9 @@ pub fn build_tclthread(comptime tcldir: []const u8, comptime subdir: []const u8,
lib . root_module . addWin32ResourceFile ( . {
lib . root_module . addWin32ResourceFile ( . {
. file = threadrc_overlay ,
. file = threadrc_overlay ,
. flags = & . {
. flags = & . {
" -DPACKAGE_MAJOR=3 " ,
b . fmt ( " -DPACKAGE_MAJOR={s} " , . { thread_ver_major } ) ,
" -DPACKAGE_MINOR=0 " ,
b . fmt ( " -DPACKAGE_MINOR={s} " , . { thread_ver_minor } ) ,
" -DPACKAGE_VERSION=3.0b2 " ,
b . fmt ( " -DPACKAGE_VERSION={s} " , . { thread_version } ) ,
} ,
} ,
. include_paths = & . {
. include_paths = & . {
b . path ( tcldir + + " /generic " ) ,
b . path ( tcldir + + " /generic " ) ,
@ -166,13 +172,18 @@ pub fn build_tclthread(comptime tcldir: []const u8, comptime subdir: []const u8,
} ) ; / / ignored for non - windows targets
} ) ; / / ignored for non - windows targets
b . installArtifact ( lib ) ;
b . installArtifact ( lib ) ;
/ / G - 102 : pkgIndex . tcl so ' package require Thread ' resolves against the prefix
/ / G - 102 : pkgIndex . tcl so package requires resolve against the prefix
/ / ( punkshell runtests - jobs and codethread need it ) - formerly a suite . tcl
/ / ( punkshell runtests - jobs and codethread need it ) - formerly a suite . tcl
/ / post - build block .
/ / post - build block . Both capitalizations are declared ( G - 107 ) : the dll
/ / provides ' Thread ' AND ' thread ' ( threadCmd . c PkgProvideEx x2 ) ; the thread
/ / testsuite requires the lowercase name , existing punkshell consumers the
/ / capitalized one .
const wf_pkgidx = b . addWriteFiles ( ) ;
const wf_pkgidx = b . addWriteFiles ( ) ;
const pkgidx = wf_pkgidx . add ( " pkgIndex.tcl " , " package ifneeded Thread " + + mkvar_thread_version + +
const pkgidx = wf_pkgidx . add ( " pkgIndex.tcl " , b . fmt (
" [list load [file normalize [file join $dir .. .. bin " + + mkvar_pkg_lib_file + + " ]] Thread] \n " ) ;
" package ifneeded Thread {s} [list load [file normalize [file join $dir .. .. bin {s}]] Thread] \n " + +
const pkgidx_install = b . addInstallFileWithDir ( pkgidx , . prefix , " lib/thread " + + mkvar_thread_version + + " /pkgIndex.tcl " ) ;
" package ifneeded thread {s} [list load [file normalize [file join $dir .. .. bin {s}]] Thread] \n " ,
. { thread_version , pkg_lib_file , thread_version , pkg_lib_file } ) ) ;
const pkgidx_install = b . addInstallFileWithDir ( pkgidx , . prefix , b . fmt ( " lib/thread{s}/pkgIndex.tcl " , . { thread_version } ) ) ;
b . getInstallStep ( ) . dependOn ( & pkgidx_install . step ) ;
b . getInstallStep ( ) . dependOn ( & pkgidx_install . step ) ;
return lib ;
return lib ;