Skip to content

Commit 15c069a

Browse files
committed
Handle structmemberalign for non-visual studio actions
1 parent 903b3aa commit 15c069a

File tree

12 files changed

+146
-22
lines changed

12 files changed

+146
-22
lines changed

modules/vstudio/_preload.lua

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -422,19 +422,6 @@
422422
kind = "boolean"
423423
}
424424

425-
p.api.register {
426-
name = "structmemberalign",
427-
scope = "config",
428-
kind = "integer",
429-
allowed = {
430-
"1",
431-
"2",
432-
"4",
433-
"8",
434-
"16",
435-
}
436-
}
437-
438425
p.api.register {
439426
name = "symbolspath",
440427
scope = "config",

modules/vstudio/tests/vc2019/test_compile_settings.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,24 @@
9393
]]
9494
end
9595

96+
--
97+
-- Check StructMemberAlignment
98+
--
99+
100+
function suite.structMemberAlignmentWithClang()
101+
toolset "clang"
102+
structmemberalign(2)
103+
prepare()
104+
test.capture [[
105+
<ClCompile>
106+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
107+
<WarningLevel>Level3</WarningLevel>
108+
<Optimization>Disabled</Optimization>
109+
<AdditionalOptions>/Zp2 %(AdditionalOptions)</AdditionalOptions>
110+
<StructMemberAlignment>2Bytes</StructMemberAlignment>
111+
]]
112+
end
113+
96114
--
97115
-- Check ClCompile for ScanForModuleDependencies
98116
--

modules/vstudio/vs2010_vcxproj.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,6 +2157,10 @@
21572157
if cfg.openmp == "On" then
21582158
table.insert(opts, 1, '/openmp')
21592159
end
2160+
-- <StructMemberAlignment>N</StructMemberAlignment> is unfortunately partially ignored with clang toolset
2161+
if cfg.structmemberalign then
2162+
table.insert(opts, 1, '/Zp' .. tostring(cfg.structmemberalign))
2163+
end
21602164
end
21612165

21622166
if #opts > 0 then

modules/xcode/tests/test_xcode_project.lua

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3214,6 +3214,32 @@
32143214
]]
32153215
end
32163216

3217+
function suite.XCBuildConfigurationProject_OnStructmemberalign()
3218+
structmemberalign(2)
3219+
prepare()
3220+
xcode.XCBuildConfiguration_Project(tr, tr.configs[1])
3221+
test.capture [[
3222+
A14350AC4595EE5E57CE36EC /* Debug */ = {
3223+
isa = XCBuildConfiguration;
3224+
buildSettings = {
3225+
ARCHS = "$(NATIVE_ARCH_ACTUAL)";
3226+
CONFIGURATION_BUILD_DIR = "$(SYMROOT)";
3227+
CONFIGURATION_TEMP_DIR = "$(OBJROOT)";
3228+
GCC_OPTIMIZATION_LEVEL = 0;
3229+
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
3230+
GCC_WARN_ABOUT_RETURN_TYPE = YES;
3231+
GCC_WARN_UNUSED_VARIABLE = YES;
3232+
OBJROOT = obj/Debug;
3233+
ONLY_ACTIVE_ARCH = NO;
3234+
OTHER_CFLAGS = (
3235+
"-fpack-struct=2",
3236+
);
3237+
SYMROOT = bin/Debug;
3238+
};
3239+
name = Debug;
3240+
};
3241+
]]
3242+
end
32173243

32183244
function suite.XCBuildConfigurationProject_OnNoPCH()
32193245
pchheader "MyProject_Prefix.pch"

modules/xcode/xcode_common.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,10 @@
15881588

15891589
settings['OTHER_CFLAGS'] = table.join(flags, cfg.buildoptions)
15901590

1591+
if cfg.structmemberalign then
1592+
table.insert(settings['OTHER_CFLAGS'], "-fpack-struct=" .. tostring(cfg.structmemberalign))
1593+
end
1594+
15911595
-- build list of "other" linked flags.
15921596
flags = { }
15931597
for _, lib in ipairs(config.getlinks(cfg, "system")) do

src/_premake_init.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,19 @@
822822
}
823823
}
824824

825+
api.register {
826+
name = "structmemberalign",
827+
scope = "config",
828+
kind = "integer",
829+
allowed = {
830+
"1",
831+
"2",
832+
"4",
833+
"8",
834+
"16",
835+
}
836+
}
837+
825838
api.register {
826839
name = "symbols",
827840
scope = "config",

src/base/config.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@
575575
-- result if the corresponding value is not present
576576

577577
for key, replacement in pairs(map) do
578-
if #key > 1 and key:startswith("_") then
578+
if type(key) == "string" and #key > 1 and key:startswith("_") then
579579
key = key:sub(2)
580580
if values[key] == nil then
581581
add(replacement)

src/tools/gcc.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@
154154
Thread = "-fsanitize=thread",
155155
UndefinedBehavior = "-fsanitize=undefined",
156156
},
157+
structmemberalign = {
158+
[1] = "-fpack-struct=1",
159+
[2] = "-fpack-struct=2",
160+
[4] = "-fpack-struct=4",
161+
[8] = "-fpack-struct=8",
162+
[16] = "-fpack-struct=16",
163+
},
157164
visibility = {
158165
Default = "-fvisibility=default",
159166
Hidden = "-fvisibility=hidden",

src/tools/msc.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@
139139
On = "/GF",
140140
Off = "/GF-",
141141
},
142+
structmemberalign = {
143+
[1] = "/Zp1",
144+
[2] = "/Zp2",
145+
[4] = "/Zp4",
146+
[8] = "/Zp8",
147+
[16] = "/Zp16",
148+
},
142149
symbols = {
143150
On = "/Z7"
144151
},

tests/tools/test_gcc.lua

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,32 @@
183183
test.contains({ "-ffloat-store" }, gcc.getcflags(cfg))
184184
end
185185

186+
function suite.cflags_onStructmemberalign1()
187+
structmemberalign(1)
188+
prepare()
189+
test.contains({ "-fpack-struct=1" }, gcc.getcflags(cfg))
190+
end
191+
function suite.cflags_onStructmemberalign2()
192+
structmemberalign(2)
193+
prepare()
194+
test.contains({ "-fpack-struct=2" }, gcc.getcflags(cfg))
195+
end
196+
function suite.cflags_onStructmemberalign4()
197+
structmemberalign(4)
198+
prepare()
199+
test.contains({ "-fpack-struct=4" }, gcc.getcflags(cfg))
200+
end
201+
function suite.cflags_onStructmemberalign8()
202+
structmemberalign(8)
203+
prepare()
204+
test.contains({ "-fpack-struct=8" }, gcc.getcflags(cfg))
205+
end
206+
function suite.cflags_onStructmemberalign16()
207+
structmemberalign(16)
208+
prepare()
209+
test.contains({ "-fpack-struct=16" }, gcc.getcflags(cfg))
210+
end
211+
186212
function suite.cflags_onSSE()
187213
vectorextensions "SSE"
188214
prepare()

0 commit comments

Comments
 (0)